loading

It is far better if the tank can move according to my instruction at instant rather than the directions set before. After some researches I plan to control the tank with my mobile phone via Bluetooth module.

Step 1: Parts

Bluetooth module

Smart Tank, or here

Arduino UNO

Small Breadboard

Battery Box AA x 4

Battery Box 9-volt

Actually I just add the Bluetooth module to the third project.

Step 2: Wiring

It is quite simple. On top of the third project I connect RXD to pin 7, TXD to pin 6, GND to GND in Arduino and VCC to 5V. The wiring can be done with a small breadboard.

Step 3: Code

The code is very similar to previous one except the initial Bluetooth pin setting and the final loop. For example: if the Bluetooth receive a letter "w", then the tank moves forward.

#include <SoftwareSerial.h>
SoftwareSerial BT(6, 7); //set TX and RX on bluetooth to pin 6 and 7 respectively

char command;

int motorPin = 8; //right side to IB - forward

int motorPin2 = 9; //left side to IA - forward

int motorPin3 = 10; //right side to IA - backward

int motorPin4 = 11; //left side to IB - backward

void setup() {

BT.begin (9600);

pinMode(motorPin, OUTPUT);

pinMode(motorPin2, OUTPUT);

pinMode(motorPin3, OUTPUT);

pinMode(motorPin4, OUTPUT);

}

void stop() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

}

void forward(){

digitalWrite(motorPin, HIGH);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, LOW);

}

void backward() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, HIGH);

}

void turnLeft() {

digitalWrite(motorPin, HIGH);

digitalWrite(motorPin2, LOW);

digitalWrite(motorPin3, LOW);

digitalWrite(motorPin4, HIGH);

}

void turnRight() {

digitalWrite(motorPin, LOW);

digitalWrite(motorPin2, HIGH);

digitalWrite(motorPin3, HIGH);

digitalWrite(motorPin4, LOW);

}

void loop() {

if (BT.available() > 0) {

command = BT.read();

switch (command) {

case 'w' :

forward();

break;

case 'x' :

backward();

break;

case 'a' :

turnLeft();

break;

case 'd' :

turnRight();

break;

case 's' :

stop();

break;

}

}

}

Upload this code to Arduino first before moving to the next step.

Step 4: App

I choose to create an app in Android just because my phone is in Android. : P (Please let me know if you find a similar app for iOS) With MIT App Inventor we can create an app free. Here is the link:

http://appinventor.mit.edu/explore/

The rationale behind is pretty simple: Pair the mobile with Bluetooth module. Send "w" to the module when pressing forward button. When the module receives "w", Arduino will instruct the tank moving forward. The App can be downloaded here.

Step 5: Result

After installing this app, go to Setting > Bluetooth > and searching for the device. Do the pairing and input the password. This password is either 0000 or 1234 usually. Then open the App.

You may see the screen with just an button "Connect to Bluetooth". Press it on and select the device. Five direction buttons appear if success. Yeah! Let's start!

Thanks again for watching it. See you.

<p>Thanks, I enjoyed making this with my son. I used a Teensy 2.0 and made the following adaptation:</p><p> Above char command substitute HardwareSerial BT = HardwareSerial(); </p><p>Now the Teensy expects pin 7 and 8 to be RX and TX. I rearranged the IA and IB pins to be 9, 10, 11, 12 to suit my layout.</p><p>It works well for us. Thanks for sharing your projects.</p>
<p>This is an awesome write up, I am looking forward to putting mine together.</p>
<p>Thanks very much for sharing, help a lot to this newby</p>

About This Instructable

2,215views

41favorites

License:

More by Rookie P:My Ninth Project: Robot Arm with Joystick Shield My Eighth Project: Robot Arm with Smart Tank Chassis and Bluetooth My Seventh Project: Robot Arm Set 
Add instructable to: