Tiny Smartphone Controlled Arduino Tank
by Ynze- in Circuits > Arduino
8242 Views, 181 Favorites, 0 Comments
Tiny Smartphone Controlled Arduino Tank
I tried to make the TinyTank as small as possible, I also wanted to control it with a smartphone.
At least I wanted to make it easy to disasemble so I can try out other controls like IR and 2.4GHz.
I will explain stap by stap how I made it and I will share the code and schematics so you can make it to.
I came up with the design myself.
What You Will Need
Parts:
2x 9g fullyrotational servo. Here is my Instructables for that: Fullyrotational-Servo
1x Bluetooth module (hc-06)
2x 5mm white LEDs
2x 5mm red LEDs
1x Arduino nano
1x Perfboard (at least 31x24holes or 15x49 holes)
3x aaa batterys to power the TinyTank
1x Boost module (3,5/4,5volt - 9 volt)
1x A little gun or something simular(optional) I have mine from an old rc helicopter I think.
2x 100 ohm resistors
1x 1K ohm resistor
1x 47 ohm resistor
1x BC547 (NPN) Transistor or simular
about 56x small lego tracks
4x 26 tooth LEGO gears
2x lego part: 4526985
2x lego part: 4512363
2x lego part: 4142865
2x lego part: 4206482
1x small switch
3x little springs
1x passive buzzer
Some wires
A lot of female headers
A lot of male headers
Some pieces of headschrinktube
A little thin piece (about 4 cm x 4 cm) of sheet metal (you have to be able to solder it)
Tools:
Soldering iron
Pc with Arduino IDE
Glue gun
Helping hand
A smartphone with Android
Double sided tape
Duct tape
Knife
Pliers
Scissors
Prepairing the Headers and the Perfboard
2x 15 Pins
2x 24 Pins
2x 4 Pins
1x 2 Pins
2x 13 Pins
4x 1 Pin
Cut your male headers in to pieces of:
2x 9 Pins
2x 24 Pins
2x 4 Pins
Cut your Perfboard in to two pieces of 15 By 24 Holes
Now solder a female header of 4 pins to a male header of 4 pins in a 90 degree angle and a 4 pins female to a 4 pins male without an angle and put some heatschrinktube around it like the pictures.
I will tell you later where this is for.
Making the Battery Parts
Take your sheet metal and cut two pieces of 2 cm by 0,8 cm and two pieces of 1 cm by 1,5 cm (these measurments are very important)
take the piece of 2 by 0,8 and cut a cross at one end like the pictures.
Now bend two of the four triangels and place the spring between them.
Bend the triangels back in place and make sure the spring is secure, I soldered it from the back aswell. Do this twice.
Now take one of the smaller pieces and cut it at 8 mm but leave a small soction of about 1,5 mm wide on.
Now make a cross again and secure the spring like the other one.
Make the 1,5 mm piece thinner and stronger with pliers (make sure it fits into the perfboard).
Now tin the little pin you just made and solder the spring from the back in place (watch the pictures for better detail).
Do the same with the other metal piece but don't attach a spring.
Prepare the Servos
I had this idea from: Servo-motor-Adapted-to-Lego .Take a fullyrotational servo and cut a cross in the rotating part and make sure a lego part can fit on. Next cut the lego parts with the cross in them to 11 mm. Now take that piece and put a screw in it and screw it on to the servo(make sure you put the screw in the long part of the lego piece) and try to get it as straight as possible. To finish the servo cut the sides of.
Repeat that for the other one aswell.
The Drive System
Making the Shield
Take your other piece of perfboard and solder male headers to the sides and connect the left back two pins as shown. Now solder 15 pin long female headers on top so the arduino nano can fit, make sure the two connected pins are not next to them. (Check the pictures)
Now solder 4 female headers to the back so you can fit in your boost converter later. Connect pins 9 and 10 to the pins next to them using some short wires. Solder the positive and negative female header of the boost converter to the pins next to them and solder the output negative female header to a ground pin of the arduino and the positive to the vin pin of the arduino. Next solder on the extra long straight header behind the arduino and connect vcc of the Bluetooth module to 5volt, ground to ground and tx of the module to rx of the arduino. Now we are going to connect the lights. First solder on the red leds on the back and connect the negative and the positive leads of the leds to each other and connect negative to ground with a 100 ohm resistor and positive to pin 2 of the arduino. Now solder on the white leds on to the perfboard and connect the positive leads and negative leads to each other again. To finish this part you will only have to connect the negative of the leds to ground and the positive with a 47 ohm resistor to pin 8 of the arduino and connect the buzzer (it has polarity) to pin 6 and with a 100 ohm resistor to ground.
Now stick a piece of tape on the bottom and your shield is done if you don't have a gun for it. If you have one you will have to follow the next step.
Connect the Gun (optional)
Like the transistor, the resistors and the 2 pin female header.
First solder on the 2 pin female header and the bc547 transistor next to it with the flat Side towards the headers for the arduino. Now solder the middel (base) pin of the transistor with a 1K ohm resistor to pin 3 of the arduino and the left pin (the emitter) of the transistor to the right pin of the female header. The only thing left to do is connecting the right pin of the transistor (the collector) to the about 4 volts positive of the batterys and the left pin of the 2 pin female header to ground.
Now everything is done we can assemble the TinyTank and give it a try.
Connect Everything
Do not flick the switch just yet.
The Code and the App
The Bluetooth module will mess up the programming so you have to unplug the Bluetooth module before uploading anything.
So, to upload the code, disconnect the Arduino(I don't know what happens if you leave it in so just take it out), plug in a usb cable and copy and paste the code from here into the Arduino IDE. Make sure you select the right arduino and com. Now upload the code.
You can copy the code from here:
TinyTank code:
It will receive the data from the Bluetooth module and drive the little tank forward backward left and right. It will also fire the gun and turn the lights on and off when you press the buttons on the app and you can set the speed from the app. It beeps when started up and when the connection is lost.
-----------------------------------------------------------------------------------------------------------------------------------------
/* this sketch will drive the TinyTank with bluetooth.
* When you turn it on it will make a sound and if you disconnect it it will make an other sound and
* the lights will blink twice.
* It is obvious that when you press the forward button on the app that the tank will drive
* forward and so on. When you press the button for the headlights the headlighst will turn on,
* and this is the same for the backlights. when you press the horn button the horn will turn on
* and if you press again it will turn off. When you press the triangle button the gun will fire once.
* you can change the speed the tank will drive by sliding the slide back and forth.
*
* the only thing you will have to change is the time the gun is set high so it will shoot once, it will
* depend on your type of gun.
*
* Made by: Ynze Selders
*/
#include
int rSpeed=0;
int lSpeed=0;
Servo rightservo;
Servo leftservo;
char command;
const int headLights = 8;
const int backLights = 2;
const int gun = 3;
const int buzzer = 6;
void setup() {
Serial.begin(9600);
rightservo.attach(9);
leftservo.attach(10);
pinMode(headLights, OUTPUT);
pinMode(backLights, OUTPUT);
pinMode(gun, OUTPUT);
pinMode(buzzer, OUTPUT);
rightservo.write(90);
leftservo.write(90);
tone(buzzer, 750); //startup tone
delay(150);
tone(buzzer, 1000);
delay(150);
tone(buzzer, 1250);
delay(150);
noTone(buzzer);
}
void loop() {
if(Serial.available() > 0){
command = Serial.read();
Stop();
switch(command){ //these are all the letters and numbers the app sends to the bluetooth
case 'F': //module
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
case 'G':
forwardleft();
break;
case 'I':
forwardright();
break;
case 'H':
backwardleft();
break;
case 'J':
backwardright();
break;
case '0': //these are the different speeds
rSpeed=85;
lSpeed=95;
break;
case '1':
rSpeed=83;
lSpeed=97;
break;
case '2':
rSpeed=81;
lSpeed=99;
break;
case '3':
rSpeed=79;
lSpeed=101;
break;
case '4':
rSpeed=77;
lSpeed=103;
break;
case '5':
rSpeed=74;
lSpeed=106;
break;
case '6':
rSpeed=70;
lSpeed=110;
break;
case '7':
rSpeed=65;
lSpeed=115;
break;
case '8':
rSpeed=59;
lSpeed=121;
break;
case '9':
rSpeed=25;
lSpeed=155;
break;
case 'q':
rSpeed=0;
lSpeed=180;
break; //end of the speeds
case 'W': // if headlightbutton is pressed turn headlights on
digitalWrite(headLights, HIGH);
break;
case 'w': // if headlightbutton is pressed again turn headlights off
digitalWrite(headLights, LOW);
break;
case 'U': // if backlightbutton is pressed turn backlights on
digitalWrite(backLights, HIGH);
break;
case 'u': // if backlightbutton is pressed again turn backlights off
digitalWrite(backLights, LOW);
break;
case 'X': // if gun button is pressed shoot once
digitalWrite(gun, HIGH);
delay(150); // tweak this value so it shoots once if you press the button
digitalWrite(gun, LOW);
break;
case 'x': // this is the same as the one above here but otherwise you had to press the
digitalWrite(gun, HIGH);//button twice to shoot once
delay(150); // so tweak this value to the same value as the other one
digitalWrite(gun, LOW);
break;
case 'V': // if the horn button is pressed turn the buzzer on
tone(buzzer,1000);// modify this value to get other tones
break;
case 'v': // if the horn button is pressed again turn the buzzer off
noTone(buzzer);
break;
case 'D':
rightservo.write(90); //if disconected turn motors off
leftservo.write(90);
digitalWrite(gun, LOW); //if disconected make sure the gun is off
tone(buzzer, 2000); //if disconected blink lights and make sound
digitalWrite(headLights, HIGH);
digitalWrite(backLights, HIGH);
delay(250);
digitalWrite(headLights, LOW);
digitalWrite(backLights, LOW);
delay(250);
digitalWrite(headLights, HIGH);
digitalWrite(backLights, HIGH);
delay(250);
digitalWrite(headLights, LOW);
digitalWrite(backLights, LOW);
delay(250);
noTone(buzzer);
break;
}
}
}
void forward() //define what is forward
{
rightservo.write(rSpeed); //it moves with the speed you selected in the app
leftservo.write(lSpeed);
}
void back() //define what is backward
{
rightservo.write(lSpeed);
leftservo.write(rSpeed);
}
void left() //define what is left
{
rightservo.write(rSpeed);
leftservo.write(rSpeed);
}
void right() //define what is right
{
rightservo.write(lSpeed);
leftservo.write(lSpeed);
}
void forwardright() //define what is forwardright
{
rightservo.write(90);
leftservo.write(lSpeed);
}
void forwardleft() //define what is forwardleft
{
rightservo.write(rSpeed);
leftservo.write(90);
}
void backwardleft() //define what is backwardleft
{
rightservo.write(90);
leftservo.write(rSpeed);
}
void backwardright() //define what is backwardright
{
rightservo.write(lSpeed);
leftservo.write(90);
}
void Stop() //define what is stop
{
rightservo.write(90);
leftservo.write(90);
}
-------------------------------------------------------------------------------------------------------------------
The app:
https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&hl=nl
Finished Product
Now your TinyTank is done, you can start playing with it and maybe improve it.
To connect it with your phone, turn the TinyTank on, you should hear a beeping sound, go to the app and click the gear, connect to car and connect to it with the code 1234 or 0000. If the red light turns green it is connected. Now you can start driving.
I would like to hear it if you made the TinyTank.
I posted a video on Youtube, you can click on this link if you want to see it in action:
TinyTank
I will maybe make an other shield with a NRF24L01 module in the near future to make it 2.4GHz controlled.
Ask my in the comments if you have any questions.