Introduction: Arduino Bluetooth Tank With Custom Android Application (V1.0)

Hello! this is a guide for how to build a simple and cheap Arduino based Bluetooth tank. This is the first stage of this project and only involves the development of a moving tank track based vehicle. The second stage is the Android Application that will be used to control the tank. I intend to build on this project in the future by adding either a controllable turret or a robotic claw! So follow if you want to see future updates! :D

so what you will need to start this project is:

9V Battery Button Clip to 1mm DC Power Plug ~ £2.60

9V Battery (Rechargeable is a good idea) ~ £6.00

L293D Motor Driver Shield Arduino Expansion Board ~ £2.89

Tamiya 70168 Double Gearbox Kit ~ £7.00

Tamiya Tracked Vehicle Chassis ~ £13.00

Arduino HC-06 Bluetooth Transceiver Module 4-Pin serial ~ £6.99

Arduino Uno R3 (Other Uno versions or the duemilanove should be fine) ~ £3.50 - £10.00

This entire project should cost around £42 (Sorry for the UK links at some point i'll add US & CA ones as well)

This is my first Instrucatbles guide so apologies if anything is unclear, please feel free to message me or email me directly at js702@kent.ac.uk

Step 1: Chassis Construction

So the first step of this project is to construct the Tamiya Tracked Vehicle Chassis.

Once the chassis has been constructed instead of installing the single motor gear box you then want to install the Tamiya 70168 Double Gearbox Kit

I apologise that i do not have any images of me constructing the chassis, i advice you follow the instructions included with both of these kits especially with the gear box ones. I constructed my gear box with a gearing ratio of 38.2:1 you can chose another if you wish.

Alternatively you could build your own chassis or use another one as long as it has two separate DC motors the rest of the project onwards should still be applicable!

Step 2: Circuit Design

The Circuit diagram for this project can be seen above, its extremely simple.

First you want to solder wires to each of the motors in the gear box.

You then want to connect one motor to the M1 connections on the L293D Shield then the second motor to the M2 connections. Don't worry about which one goes to which right now you will be able to flip the variable names in the Arduino code later if your tanks motors are connected in reverse.

Now that the motors are connected you want to attach the HC-06 Bluetooth Module. As the L293D Shield i chose did not have a pass through for the Rx & Tx connections on the Arduino i had to resort to soldering directly to the header pins as shown in the images above.

You want to connect the Rx of the Bluetooth module to the Tx of the Arduino and the Tx of the Bluetooth module to the Rx of the Arduino.

I wanted to be able to quickly detach and reattach my HC-06 Module so that i could use it in other projects as well so i used some female header pins soldered to some spare Proto-board i had laying around.

Now you want to connect your 9V battery to your DC connection. Optionally you can cut the positive wire and solder an On/Off switch in. Make sure you do this with the positive wire not the neutral, it is good practise to always have switches attached to circuits on the high connection.

Step 3: Finalising Hardware

Now that you have the circuit and chassis assembled its time to put it together.

As i intend to build upon this project and i want to keep the costs down i decided to use some cardboard for mounting and holding the Arduino in place.

I first measured the size of card that i would need to lift the Arduino above the tank tracks, i then cut it out and secured it using electrical tape. This can be seen in the images above.

I then used some sticky Velco tape for holding my Arduino board in place.

To ensure that the Bluetooth module and power cable do not short with the Arduino or Motor Shield i then cut out another small piece of card as a separator seen in the images above.

All of the hardware for this project has now been completed!

Step 4: Arduino Code

The code that was uploaded to the Arduino can be seen bellow. It requires you to install the AFMotor.h Library, this will allow you to use the Motor Shield properly.

In case you do not know how to install Arduino Libraries click here for a quick tutorial.

The way the the program currently works is by setting up the serial communication through the Bluetooth Module. The Arduino monitors the Rx pin to check for changes in state. Once the Bluetooth Module has been sent data from a connected Bluetooth device. If the Arduino recognised the received data as an instruction for motor control it will enter the corresponding part of the if statement I.E if Rx receives "0" the tank will enter the forward motor state until told otherwise. The system flow diagram above roughly shows how this code functions.

Once you have uploaded this code to the Arduino, you can keep the USB-B connection attached and open the Serial-Monitor, you can type 0 - 9 into the command line to test each of the motor states to make sure everythings working as intended.

    
#include <AFMotor.h>

AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motor1(1, MOTOR12_64KHZ);
int state = 0;

void setup() <br>{
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Welcome: Forward = 1 Left = 2 Right = 3 Backwards = 4 Stop = 0");
  motor2.setSpeed(200);     // set the speed to 200
  motor1.setSpeed(200);     // set the speed to 200
}

void loop(){   //if some data is sent, read it and save it in the state variable

if(Serial.available() > 0)
  {
    state = Serial.read();
    Serial.print("I received: ");
    Serial.println(state);
    delay(10);</p>
if (state == '0') 
    {
      motor2.setSpeed(200);     // set the speed to 200/255
      motor1.setSpeed(200);     // set the speed to 200/255
      motor2.run(RELEASE);      // turn it on going forward
      motor1.run(RELEASE);      // turn it on going forward
      Serial.println("Stopped");
      delay(100);
      state = 0; 
    }
else if (state == '1')      // If 1 Forwards
    {
      motor2.run(RELEASE);      // turn it on going forward
      motor1.run(RELEASE);      // turn it on going forward
      motor2.setSpeed(200);     // set the speed to 200
      motor1.setSpeed(200);     // set the speed to 200
      motor2.run(FORWARD);      // turn it on going forward
      motor1.run(FORWARD);      // turn it on going forward
      Serial.println("Forward");
      delay(100);
      state = 0; 
    }
else if (state == '2')      // If 2 Turn Left
    { 
      motor2.run(RELEASE);      // turn it on going forward
      motor1.run(RELEASE);      // turn it on going forward  
      motor1.setSpeed(255);     // set the speed to 200/255
      motor1.run(FORWARD);
      //motor2.run(BACKWARD);      
      Serial.println("Left");
      delay(100);
      state = 0;     
    }
else if (state == '3') {    // If 3 Turn Right
      motor2.run(RELEASE);      // turn it on going forward
      motor1.run(RELEASE);      // turn it on going forward
      motor2.setSpeed(255);     // set the speed to 255
      motor2.run(FORWARD);      
      //motor1.run(BACKWARD);    
      Serial.println("Right");
      delay(100);
      state = 0;  
    }
else if (state == '4')       // If 4 Backwards
    {
      motor2.run(RELEASE);      // turn it on going forward
      motor1.run(RELEASE);      // turn it on going forward
      motor2.setSpeed(200);      // set the speed to 200
      motor1.setSpeed(200);      // set the speed to 200
      motor2.run(BACKWARD);      // Motor 2 backwards
      motor1.run(BACKWARD);      // Motor 1 backwards
      Serial.println("Backward");
      delay(100);
      state = 0;   
    }
else if (state == '5') 
    {
      motor2.run(RELEASE);      // turn it on going release
      motor1.run(RELEASE);      // turn it on going release
      motor2.setSpeed(255);     // set the speed to 255
      motor1.setSpeed(140);     // set the speed to 140
      motor2.run(FORWARD);      // Motor 2 forward
      motor1.run(FORWARD);      // Motor 1 forward
      Serial.println("Forward Right");
      delay(100);
      state = 0;   
     }
else if (state == '6') 
    {
      motor2.run(RELEASE);      // turn it on going release
      motor1.run(RELEASE);      // turn it on going release
      motor1.setSpeed(255);     // set the speed to 255
      motor2.setSpeed(140);     // set the speed to 140
      motor2.run(FORWARD);      // Motor 2 forward
      motor1.run(FORWARD);      // Motor 1 forward
      Serial.println("Forward Left");
      delay(100);
      state = 0;   
     }
else if (state == '7')       // If 4 Backwards
    {
      motor2.run(RELEASE);      // turn it on going forward
      motor1.run(RELEASE);      // turn it on going forward
      motor1.setSpeed(255);     // set the speed to 255
      motor2.setSpeed(140);     // set the speed to 140
      motor2.run(BACKWARD);      // Motor 2 backwards
      motor1.run(BACKWARD);      // Motor 1 backwards
      Serial.println("Backward Right");
      delay(100);
      state = 0;   
    }
else if (state == '8')       // If 4 Backwards
    {
      motor2.run(RELEASE);      // turn it on going forward
      motor1.run(RELEASE);      // turn it on going forward
      motor2.setSpeed(255);     // set the speed to 255
      motor1.setSpeed(140);     // set the speed to 140
      motor2.run(BACKWARD);      // Motor 2 backwards
      motor1.run(BACKWARD);      // Motor 1 backwards
      Serial.println("Backward Left");
      delay(100);
      state = 0;   
    }
else if (state >= '9')
    {
      Serial.println("Invalid");
      delay(100);
      state = 0; 
    }
  }
}
<br>


Step 5: Android Application

So now that you hopefully have your working Bluetooth Tank its time to work out how to control it.

On the Google Play store there are many options for Bluetooth serial communication applications that would be capable of controlling your tank such as BlueTerm or ArduDroid and many more.

If you wish to download my application that currently offers 8 directional controls you can download it from the Play Store here: Bluetooth Arduino Tank

How i created this application was through App Inventor 2, which is a really awesome way for you to quickly develop Android Applications.

The images above how both the "Designer" & "Block" view of my application so you can build and change thing up if you wish!

If you have never used App Inventor 2 before heres a link to some helpful tutorials to get you started: App Inventor Tutorials

Once you have the application installed there are a few steps before it will work. The images above show all the steps needed to get the Bluetooth Arduino Tank application working. Make sure that the Arduino is powered on before attempting this!

  1. Go to setting
  2. Click on the Bluetooth Tab
  3. Turn Bluetooth on
  4. Wait for your phone to find the HC-06 Bluetooth module
  5. Once it has been found click it and input the password by default it should be either "1234" or "1111"
  6. Now it should say the time that you were last paired with the HC-06 module
  7. Now enter the Bluetooth Arduino Tank Application and click the "Pick Bluetooth Module" button
  8. You should see the HC-06 Module (If not re-try the steps above) click on the Module
  9. The Application will then return automatically to the main screen with directional controls and now under the "Pick Bluetooth Module" Button it should now say "connected"
  10. At this point the HC-06 Modules Red LED should now be constantly on instead of pulsing meaning a device is currently connected

Step 6: Project Conclusion

So at this point you should have a cool, simple and cheap Bluetooth controlled tank, that you can now use as a starting point for more development.

The Motor shield i selected allows another 2 Motors and 2 Servos to be added, as i mentioned in the Intro i intend to update this guide with any developments i make on this build (Maybe a turret or grabbing claw).

If any of you guys decide to add on to this i'd love to see how it worked out for you!

If you had any issues or questions about this project please feel free to ask, i will do my best to help you!

Thanks for reading!

I have a few ideas for other future projects so i hope you hear from me again soon!

Comments

author
JackSoldano (author)2016-05-27

Massive thanks to anyone who voted for my in the ROBOTICS CONTEST 2016 contest! I can't believe i came second place! Please follow me to make sure you see my upcoming projects!

author
vvashurin made it! (author)2017-07-22

I built my robot based on this Arduino Bluetooth Tank Project. Thanks for Your idea and Android Application!

Picture 11.jpgPicture 8.jpgPicture 9.jpgPicture 10.jpg
author
JackSoldano (author)vvashurin2017-07-25

Awesome looks great Vvashurin! no problem glad you found it useful!

author
mp 15-22 (author)2017-06-12

hi I have a question for the arduino tank. I've built one for myself but with a army tank tracks and motors and gearboxes. I've done everything as in your build. my Bluetooth module does connect as it should but I can't get the tank to do anything at all. is there any advice or ideas of what I need or should do. thanks again I'll be looking forward to hearing from you soon.

author
98TheCiaran98 (author)2017-03-18

would it be possible to make the bluetooth module connect to a dualshock 4 for control or would you need to make a program on an android device to translate the dualshock 4 to connect to the arduino bluetooth ???

author

Hello, yes it would be possible to do this the functions would just need to be called by the dualshocks outputs instead of my apps output which was just integers. I found this guide for using the HC-06 module with a dualshock controller. I would advice trying something like this first then modding my code a little.

author
OWH made it! (author)2016-06-13

Well I got the tank done looks good. Having trouble downloading the code as per all instructions. Every time I try keep getting error on arduino program

DSC_1348.JPG
author
JackSoldano (author)OWH2016-06-14

Hey OWH, looks awesome what exactly is the problem your getting with the code? Do you get an error message?

author
OWH (author)JackSoldano2016-06-14

These are the errors I get

sketch_tank.ino:8:14: error: expeced initializer before '<' token
sketch_tank.ino: In function 'void loop()':
sketch_tank.ino:22:15: error: expected primary-expression before '/' token
sketch_tank.ino:22:16: error: expected primary-expression before '/' token
skecth_tank.ino:22:17: error: 'p' was not declared in this scope
sketch_tank.ino:23:1: error: expected primary-expression before 'if'
sketch_tank.ino:23:1: error: expected ';' before 'if'
sketch_tank.ino:33:1: error: expected '}' before 'else'
sketch_tank.ino: At global scope:
sketch_tank.ino: 133.1: error: expected before '}' token
Error compiling.

author
JackSoldano (author)OWH2016-06-14

Hmm that is strange, did you copy and paste the code from the instructables because I've just noticed that is has added some strange strings to it that shouldn't be there like
& . Could you try downloading the Arduino code file instead this should "fingers crossed" fix the issue

author
OWH (author)JackSoldano2016-06-15

Yes I copied and pasted the code from instructables. I downloaded afmotor library. Where is Arduino code file located?

author
98TheCiaran98 (author)OWH2017-03-18

copying and pasting code can sometimes cause errors because Arduino uses ASCII and your clipboard will use utf-8 (specifically unicode quotation marks have a separate character for the closing and opening marks wheres ascii has one)

author
JackSoldano (author)OWH2016-06-16

on page 4/6 of this instructables there is a attachment called BluetoothRobotV1_2.ino. You can open this file through the Arduino coding software then upload it to your Arduino device. Hope this helps

author
OWH (author)JackSoldano2016-06-18

I got the code installed with no errors. Runs great tanks for the help.

author
JackSoldano (author)OWH2016-06-20

Awesome glad to hear OWH, if you have any other questions just ask

author
amritl3 (author)JackSoldano2016-12-16

can we use a hc-05 btooth module if yes then what changes in the code.

author
homers12 (author)2017-01-18

Hi jack

My android phone is not picking up the bluetooth hc-06 module signals what could be wrong since I have checked the connections and nothing seems to be odd.

author
JackSoldano (author)homers122017-01-18

hey Homers just a few little questions, have you ever used this Bluetooth module before in any other projects? (Just so we can rule out if the modules working or not) if this is the first time your using it I would advice following a guide for a simple Bluetooth test like one here: https://arduino-info.wikispaces.com/BlueTooth-HC05-HC06-Modules-How-To

If it works on there then it must be down to something on the wiring up of the tank or the tanks code, maybe the library you have used is different maybe re-download that.

I assume that the blinking red LED is on when you have tested this and it is not constantly on (meaning that it has connected to a device )

Also check that the module is getting 3v3 not 5v if you have a multimeter

hope one of these helps you solve this problem if it still is an issue feel free to message again, but if you check these things hopefully it can resolve the problem, thanks for the comment Jack

author
homers12 (author)JackSoldano2017-01-28

Hi Jack

I have narrowed down theh issue to communication between the bluetooth HC-06 and phone app I tried it on two different apps now.

The arduino motor shield works on serial monitor and the bluetooth connection and power-supply are fine .

author
gzuñiga1 (author)2016-05-26

Hello again guys. Questionmy motors run very slow is there a way to increase the power to the motor and if so how you modify the code to do so?.

author
JackSoldano (author)gzuñiga12016-07-05

Hey sorry for the really slow reply! must have missed this you can do this both in the code and with the gearing ratio.

With the code you can:

See these lines in each of the statements bellow,

motor2.setSpeed(200); // set the speed to 200

motor1.setSpeed(200); // set the speed to 200

you can change the 200 to 255 this will effectively change the PWM to increase the speed. So it should look like this for max speed:

motor2.setSpeed(255); // set the speed to 255

motor1.setSpeed(255); // set the speed to 255

With the hardware you can:

Change the gearing ratio from 38.2:1 to another one which will reduce torque but increase speed.

Or you can add two batteries like you did :)

author
ohoilett (author)2016-06-05

Good job. Great first Instructable.

author
JackSoldano (author)ohoilett2016-06-05

Hey thanks Ohoilett! had a busy few weeks with uni, hopefully should get a new one out soon!

author
ohoilett (author)JackSoldano2016-06-05

Cool. I look forward to seeing it.

author
LeeC8 (author)2016-05-27

Hi Jack, yes it is a 3d printed arm. I found it, also on instructables.

https://www.instructables.com/id/EEZYbotARM/

theGHIZmo is the author and also did a great job explaining it's operation. I followed his recommendation and an controlling it with a Pololu USB servo Mini Maestro. If you haven't played with one, they are fun, not cheap, but fun. The arm is pretty jumpy at full speed, but this controller does a great job slowing it down so it's a lot smoother. This controller is very easy to program, No C+ code!!! It also can remember a pre-programmed routine and repeats it. If I understand correctly if can be used with an Arduino so it should be able to be blue toothed somehow. This is where I get lost... I don't know if you have access to a printer. I have 2 and would be happy to help you out with printing if you need it, in exchange for helping teach me the Arduino control side of it.

Thanks again, Lee

author
JackSoldano (author)LeeC82016-06-05

Sorry for the late reply Lee the last week has been crazy. This robotic arm looks awesome, now i have some free time I'll go through this guide and see what were working with here :) sure it can be adapted to make this tank even better

author
LeeC8 made it! (author)2016-05-27

Hello Jack and gzuñiga, I'm glad someone else had success with your design too! Mine didn't run to well on the 9 volt either, very sluggish. I printed a AA battery holder with 6 AAs and it runs great with that! My dog is about wore out chasing it. I designed and printed a chassis for it too. I didn't like the wood. I've been playing with a robot arm, but I can't figure out the Arduino coding and Bluetooth app. I'm a lot better with mechanics than programing :( Jack, I'm hoping you find time some day to take your to instructable to the next level with an arm on it so I can continue to learn from you.

Thanks again for making the fun project

Lee

20160527_172145.jpg
author
JackSoldano (author)LeeC82016-05-27

Wow, that looks really awesome i've actually just ordered a 6 AA holder for that little boost as well! Think were going to need it especially if were mounting the arm :) Don't worry i haven't forgotten about this project I've got my last bit of assessed work next Tuesday should have a fair bit of free time after that to work on this! out of curiosity is that a 3D printed robotic arm? looks really cool I'm jealous of your kit! :D

author
gzuñiga1 made it! (author)2016-05-26

Problem solved i desided to change transmission configuration for mor torque and added two 9V.batteries instead of one for more current output. It gives better performance. Not fast but lots of torque!! It pusshes my shues arround lol.

14642857227101613007244.jpg
author
JackSoldano (author)gzuñiga12016-05-26

Looks awesome gzuñiga! yeah i did have pretty low torque with my configuration it was struggling to go over my notepad sure with two 9v batteries as well its crazy! Glad the project worked for you and thanks for making it!

author
LeeC8 (author)2016-05-08

Hello again Jack, The newbie figured out my problem... Step 1 follow Jack's schematic :) lol I had the Tx to TX and Rx to Rx I switch them, as your schematic shows...lol and it works great! Thanks again for the great instructable!

Lee

author
JackSoldano (author)LeeC82016-05-11

Hey Lee, glad to hear you got it working! yeah i've made that mistake many times :)

author
LeeC8 (author)2016-05-04

Hello, last time I'll bother you tonight! Just wanted to add, it works great through the serial monitor when I type in the numbers... Thanks again

author
JackSoldano (author)LeeC82016-05-05

Just updated the guide to show how to properly sync your mobile to the HC-06 and how to use my Android Application with images, i hope this solves your issue if not please message me again! :)

author
JackSoldano (author)LeeC82016-05-05

Hey glad you liked the guide Lee! So are you having issues with syncing to the HC-06 module, I just realised i did forget to explain that before using my Android application you want to go to - Settings -> Bluetooth (Make sure its on) -> scan for devices -> connect to the HC-06 Module, the password should be either 1234 or 1111 once you have paired retry my Android Application i will update my guide when i get a change with this. To use my Android Application you first want to click the "Pick Bluetooth Module" button select the HC-06 (It will take a second to sync) once it successfully is connected it will come up with a pop-up message confirming this. The red LED on the HC-06 module should change from pulsing to solid at this point, then you will be able to control the tank

author
LeeC8 (author)2016-05-04

Hello again, I hope you can help a poor newbie... I'm having some trouble. I have mine wired just like your schematic. only difference is I'm running on a 9 volt power supply instead of a battery and this power is connected to the 9v and gnd connections on the motor shield. When I jump to the power feed to the motor terminals on the motor shield, they run. I had to disconnect the HC-06 to get the .ino file to load, but once I did, It loaded perfectly with no errors. I am using your app and am connected to the HC-06 with a solid red light. But I get no response... Any help would be appreciated. Thank you!

author
LeeC8 (author)2016-05-04

Hello, I've got all the part to build this and I'm starting now!!! please do step 2 with the turret and claw!!! I can't wait. I've been hoping someone a lot smarter with arduino code would build one of these! So I can learn what I'm doing. Great job explaining the steps and great pictures

Thanks you

About This Instructable

6,832views

182favorites

License:

Bio: I'm currently studying my MEng in Electronic & Communications Engineering, i have always been interested in how stuff works with a focus on electronics.
More by JackSoldano:Automated Navigation Robot with Gas (MQ-2), Temperature & Humidity (DHT11) SensorsCheap Smart RFID Packet for Moisture DetectionArduino Bluetooth Tank with Custom Android Application (V1.0)
Add instructable to: