Introduction: 3D Printed Scrap Pile Arduino Tank Build
Beginning Vision: We started this project with the vision of a budget build tank that could pull a person sitting on a wheeled chair. We had the vision of a sleek design without a bunch of wire exposure. We had the design idea of tank tread from the beginning of our drafting process.
Summary: In the final version of our project the tank still had its treads but didn't have the power to pull a person on a chair. To solve this issue, you would need larger better geared motors.
Step 1: Code
char getstr;
int in1=9; //direction motor 1
int in2=10; //direction motor 1
int in3=11; //direction motor 2
int in4=12; //direction motor 2
int enA=5; //enable motor 1
int enB=6; //enable motor 2
void setup()
{
Serial.begin(9600);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(enA,OUTPUT);
pinMode(enB,OUTPUT);
digitalWrite(in1,HIGH);
digitalWrite(in2,HIGH);
digitalWrite(in3,HIGH);
digitalWrite(in4,HIGH);
digitalWrite(enA,HIGH);
digitalWrite(enB,HIGH);
}
//right turn
void _mTurnRight(int pin1,int pin2)
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
analogWrite(enA,0);
analogWrite(enB,255);
}
//Foward right turn
void _mTurnFowardRight(int pin1,int pin2)
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
analogWrite(enA,255);
analogWrite(enB,155);
}
//Back right turn
void _mTurnBackRight(int pin1,int pin2)
{
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
analogWrite(enA,255);
analogWrite(enB,155);
}
//Back left turn
void _mTurnBackLeft(int pin1,int pin2)
{
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
analogWrite(enA,155);
analogWrite(enB,255);
}
//Foward left turn
void _mTurnFowardLeft(int pin1,int pin2)
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
analogWrite(enA,155);
analogWrite(enB,255);
}
//left turn
void _mTurnLeft(int pin1,int pin2)
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
analogWrite(enA,255);
analogWrite(enB,0);
}
//forward first gear
void _mFirst(int pin1,int pin2)
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
analogWrite(enA,100);
analogWrite(enB,100);
}
//forward 2nd gear
void _mSecond(int pin1,int pin2)
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
analogWrite(enA,200);
analogWrite(enB,200);
}
//forward 3rd gear
void _mThird(int pin1,int pin2)
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
analogWrite(enA,255);
analogWrite(enB,255);
}
//backup
void _mBackup(int pin1,int pin2)//
{
digitalWrite(pin1,LOW);
digitalWrite(pin2,HIGH);
digitalWrite(enA,HIGH);
digitalWrite(enB,HIGH);
}
//stop and declare which pins to stop
void _mStop(int pin1,int pin2)
{
digitalWrite(pin1,LOW);
digitalWrite(pin2,LOW);
digitalWrite(enA,HIGH);
digitalWrite(enB,HIGH);
}
void loop()
{
getstr=Serial.read();
if(getstr=='I')
{
Serial.println("gear 1!");
_mStop(in1,in2);
_mStop(in3,in4);
_mTurnFowardLeft(in1,in2);
_mTurnFowardLeft(in3,in4);
}
if(getstr=='G')
{
Serial.println("gear 2!");
_mStop(in1,in2);
_mStop(in3,in4);
_mTurnFowardRight(in1,in2);
_mTurnFowardRight(in3,in4);
}
if(getstr=='F')
{
Serial.println("gear 3!");
_mStop(in1,in2);
_mStop(in3,in4);
_mThird(in1,in2);
_mThird(in3,in4);
}
else if(getstr=='B')
{
Serial.println("go back!");
_mStop(in1,in2);
_mStop(in3,in4);
_mBackup(in1,in2);
_mBackup(in3,in4);
}
else if(getstr=='J')
{
Serial.println("go back!");
_mStop(in1,in2);
_mStop(in3,in4);
_mTurnBackRight(in1,in2);
_mTurnBackRight(in3,in4);
}
else if(getstr=='H')
{
Serial.println("go back!");
_mStop(in1,in2);
_mStop(in3,in4);
_mTurnBackLeft(in1,in2);
_mTurnBackLeft(in3,in4);
}
if(getstr=='L')
{
Serial.println("turn Left!");
_mStop(in1,in2);
_mStop(in3,in4);
_mTurnLeft(in1,in2);
_mTurnLeft(in3,in4);
}
else if(getstr=='R')
{
Serial.println("go right!");
_mStop(in1,in2);
_mStop(in3,in4);
_mTurnRight(in1,in2);
_mTurnRight(in3,in4);
}
else if(getstr=='S')
{
Serial.println("Stop!");
_mStop(in1,in2);
_mStop(in3,in4);
}
}
Step 2: Code Description
This piece of code tells which pins are connected to what motors and what directions they go.
int in1=9; //direction motor 1
int in2=10; //direction motor 1
int in3=11; //direction motor 2
int in4=12; //direction motor 2
int enA=5; //enable motor 1
int enB=6; //enable motor 2
This piece of code turns on all of the pins and makes sure they are ready to receive our code.
Serial.begin(9600);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(enA,OUTPUT);
pinMode(enB,OUTPUT);
digitalWrite(in1,HIGH);
digitalWrite(in2,HIGH);
digitalWrite(in3,HIGH);
digitalWrite(in4,HIGH);
digitalWrite(enA,HIGH);
digitalWrite(enB,HIGH);
This is our turning code, we have the pin that turns on the right motor on and the other pin (pin 2) off so only the right motor would be running thus making our robot turn right. Our turn left code is mostly the same , but we run pin 1 instead of pin 2 and enA instead of enB.
void _mTurnRight(int pin1,int pin2)
{
digitalWrite(pin1,HIGH);
digitalWrite(pin2,LOW);
analogWrite(enA,0);
analogWrite(enB,255);
Our backwards code is the same as the turn toward right but instead of pin 1 on we run pin2 and run enA and enB at the same time at 255
getstr=Serial.read();
if(getstr=='I')
{
Serial.println("gear 1!");
_mStop(in1,in2);
_mStop(in3,in4);
_mTurnFowardLeft(in1,in2);
_mTurnFowardLeft(in3,in4);
}
Attachments
Step 3: Materials
1 sheet of wood roughly 13 x 10.5 inches
2 PITTMAN motors (GM8712B661) 12 vdc, 6.3:1 ratio
A 20 volt battery
2 small segments of metal to stick in the battery
A Bluetooth module
A L298 motor driver
A Pengda Technology 5V-DC fan
An arduino uno with a motor sheild
2 14-15 inch stainless steel 6mm rods
2 sets of wire quick disconnects
A set of GT2 pulleys (20 teeth in our case)
16 1.5in M6 bolts
2 GT2 belts
Assortment of jumper wires/ heavier duty wires
6 half inch M3 bolts for the motor mounts
2 half inch screws for the wiring case