Introduction: Android Controlled Arduino Bluetooth Panzer

About: Just an ordinary person who loves #thinking and #tinkering

Remote Control cars are fun to drive around the room or wandering the house. What could be more fun of it? When you have the visibility as if you are riding in it. A wireless IP camera is the answer. Or let's say you have CCTV cameras around the house or office but there are some blind spots, then this project can be your Patrol Cam. Do It Yourself? Yeah, that is another fun of it. You can buy any rover on the market that has gorgeous futuristic cases. This project is for fanatics who love boards and wires and some headache :P

I am encouraged by ASCAS with his DIY Phone Controlled FPV Rover (Fast & Agile). What I built is similar to his, but I change some parts because of budget, and some parts I got at special price at special occasions. Then it get the title "Triple S" : Slow & Sluggish Spy :D

Step 1: Bill of Materials

Step 2: Chassis

There are several modes of chassis can be made by Tamiya Universal Plate and Tamiya Track and Wheel Set. Try several combination to get what mode you desire. Some configuration are only suitable for flat tracks. The other may be good for All Terrain Forward.

I pick Tank mode because it is best for All Terrain Forward and Backward moving. I am not explaining how to assemble the motor gear set because the instruction manual is already included in the box in one piece of paper. It has a very clear steps with images. The Track and Wheel set is also comes with a manual, but you can design a new model by your imagination and the parts you have in hand. I only provide some images to boost your imagination to get the style you love or what purpose of your RC toy will be.

Now get two pieces of female to female jumper cables with different colors, cut them into two in the middle with same lengths. Solder them to the DC motors' terminals. This is not crucial but it will make you easier to swap the terminals in accordance with the codes we write. Solder each motor with two colors on its terminals. In my case, I use grey wire for left terminal and purple wire for right terminal.

Step 3: Wiring : Bluetooth Module to Arduino

After some reviews on the net, I pick up JY-MCU Bluetooth Module. It is small in size, low in price, plug and play. It is a HC-06 module which support only in "slave mode" and also known as "Linvor" while there is a HC-05 module which can be configured to master or slave. To know more about HC-06 Bluetooth Module you can visit this link or just google keyword "HC-06".

Wiring it on Arduino Uno R3 is pretty simple for it has only four cables. This JY-MCU Bluetooth Module comes with four pins female to female cables mark with red dashes and dots. I change this cables, because I need female headers on bluetooth module and male headers on Arduino.

I use rainbow-color cables so that it is easier to follow and I will guide you and explain with the colors I use.

  1. Red wire from HC-06 VCC to Arduino 5V.
  2. Brown wire from HC-06 GND to Arduino GND.
  3. Black wire from HC-06 TXD to Arduino Digital Pin 0 (Rx).
  4. White wire from HC-06 RXD to Arduino Digital Pin 1 (Tx).

Some of you would have this question crossing your mind : The color code for Ground is Black, then why I use Brown instead? Well, the jumper cables I have is 40 pins in a group. I torn up a group of four, I keep the Red for VCC, then Brown is next to it. I think it is not bad to use Brown as Ground rather than messing up the group of cables.

Step 4: Wiring : L298N Motor Driver to Arduino

Again I will explain the connection in my colors :)

  1. Red wire from Motor Driver +5V to Arduino VIN.
  2. Brown wire from Motor Driver GND to Arduino GND.
  3. Orange wire from Motor Driver ENB to Arduino Digital Pin 6.
  4. Yellow wire from Motor Driver IN4 to Arduino Digital Pin 7.
  5. Green wire from Motor Driver IN3 to Arduino Digital Pin 5.
  6. Blue wire from Motor Driver IN2 to Arduino Digital Pin 4.
  7. Purple wire from Motor Driver IN1 to Arduino Digital Pin 2.
  8. Grey wire from Motor Driver ENA to Arduino Digital Pin 3.

If you are using another Motor Driver, maybe you need to adjust the connection to Arduino refer to your board's manual. If you have any question, I will give my best to help.

Step 5: Wiring : Battery and Motors

  1. Purple and Blue wires from Motor Driver MOTOR-A to Right Motor terminals.
  2. Green and Yellow wires from Motor Driver MOTOR-B to Left Motor terminals.
  3. Red wire from Motor Driver VMS to Mini Switch bottom terminal.
  4. Another Red wire from Mini Switch middle terminal to Battery 5V (Red wire).
  5. Black wire from Motor Driver GND to Battery GND (Black wire).

For point 1 and 2, later on testing when the wheels move the opposite way than the button you pressed, you need to interchange the terminal wires. That is why I solder female headers on the motors' terminals, so that we can swap them easily.

Step 6: Get Things on Board

The L298N Motor Driver I use is not Arduino stackable board, so I put all the boards vertical. I put my Arduino and Motor Driver back to back, and I use a thin foam in between to avoid short circuit. I shape the foam to leave the holes unblocked so that I can tie the boards to Tamiya Universal Plate using zip ties.

Battery is best placed at the back to give more weight at the back, because in front of the tank lies Dual Motor Gearbox. We should distribute the weight well so that it is stable in movement. You don't want your tail up while moving, do you? :)

Cables are another problem. You can tidy up those cables by adjusting the length of the cables needed, but that will kill your plug and play jumper wires. For me, I try to keep those cables in groups and shape them as you can see in my photos, as long as they don't block the wheels' movement :)

Step 7: Adding a WiFi Camera

Now we put an eye on the tank. I get this one less than $50 with pan and tilt ability, night vision IR LEDs and audio support. The most important thing is : it runs at 5V DC which is perfect match for Arduino project. Can we just set it up on the tank? Well, you can do so, but I think it weigh too much for my little tank with standard DC motors, and also too bulky. The camera base will block the tank treads movement. You can put something to set it up higher, but I think it is still too heavy and bulky.

Actually all we need is the mainboard which handle the video streaming wirelessly and the camera module itself. Take a look at my iBle showing how to dismantle it. I have reduced approximately 70% of its weight, sacrificing its pan and tilt ability. The size? Only a thin mainboard which I can put it vertically and the camera case about the size of a golf ball.

The camera comes with an AC adapter. I cut the wire off and as you see in my photos, I solder it to a switch. You don't need to do this, you can simply screw the Black wire to Motor Driver GND and the Red wire to Motor Driver 5V as seen on photo number 3. The switch I use was preventing power consumption while I was testing the tank movement.

Below the DC power jack there is a curve on the board. I put the antenna there. But before that, I put some tape on the board to prevent short circuit, because there lay some solder pads. I put a double tape below the camera and then tie it to its mainboard and the tank's plate.

Step 8: Optional Camera

Sadly I have to tell you that my OpAmp chip on my camera mainboard smokes... T-T

It was while I am testing my camera alone without the tank. I was carelessly grab a 7.4V battery fully charged to 8.2V. Either that caused the burnt or my setting in higher resolution that draw too much current to the chip. I tell you this so that you don't experience the same bad luck like me.

It's okay. My project will go on. While I am searching for a replacement chip, I found my old android phone which I use for backup, lying in my drawer. I found a software streaming the phone's camera through wifi. I will go on with this application on the next step 10.

I use a tweeter (speaker) stand to hold my phone. I puts some foam and cable ties. I use double tape to stick it on the motor gear box. It is done. Now we move to softwares.

Step 9: Arduino Sketch

Upload this sketch to your Arduino :

/*
  Chienline @ 2015
  Controlling an Arduino car/tank using an Android phone over Bluetooth connection. 
  Android Software : BlueCam 2 by Johnny Visser [in PlayStore].
*/
char dataIn  = 'S';        //Character/Data coming from the phone. S=Stop;

int IN1Pin = 2; // Motor A IN1
int ENAPin = 3; // Motor A Enable
int IN2Pin = 4; // Motor A IN2
int IN3Pin = 5; // Motor B IN3
int ENBPin = 6; // Motor B Enable
int IN4Pin = 7; // Motor B IN4

int delayTime = 100;

void setup() 
{
  Serial.begin(9600);  //Initialize serial communication with Bluetooth module at 9600 baud rate.  
  pinMode(IN1Pin, OUTPUT);
  pinMode(ENAPin, OUTPUT);
  pinMode(IN2Pin, OUTPUT);
  pinMode(IN3Pin, OUTPUT);
  pinMode(ENBPin, OUTPUT);
  pinMode(IN4Pin, OUTPUT);
  
  //Stop both motors on power up.  
  stopMotors();
}

void loop()
{
  if (Serial.available() > 0)    //Check for data on the serial lines.
  { 
    dataIn = Serial.read();  //Get the character sent by the phone and store it in 'dataIn'.
    if (dataIn == 'F'){   //if incoming data is a F, move forward
        moveForward();
        delay(delayTime);
    }  
    else if (dataIn == 'B'){   //if incoming data is a B, move backward
        moveBackward();
        delay(delayTime);
    }  
    else if (dataIn == 'L'){   //if incoming data is a L, move wheels left  
        moveLeft();
        delay(delayTime);
    }  
    else if (dataIn == 'R'){   //if incoming data is a R, move wheels right
        moveRight();
        delay(delayTime);
    }
    else {
        stopMotors();    
    }
    stopMotors();    
  }
}

//These direction functions are designed for Keyes L298N Motor Driver.
//You need to change them to suit your other motor drivers.
void moveForward(){
    digitalWrite(IN1Pin, LOW);
    digitalWrite(IN2Pin, HIGH); //L-Forward
    digitalWrite(IN3Pin, LOW);
    digitalWrite(IN4Pin, HIGH); //R-Forward
    digitalWrite(ENAPin, HIGH);
    digitalWrite(ENBPin, HIGH);
}

void moveBackward(){
    digitalWrite(IN1Pin, HIGH);
    digitalWrite(IN2Pin, LOW); //L-Backward
    digitalWrite(IN3Pin, HIGH);
    digitalWrite(IN4Pin, LOW); //R-Backward
    digitalWrite(ENAPin, HIGH);
    digitalWrite(ENBPin, HIGH);
}

void stopMotors(){
    digitalWrite(ENAPin, LOW);
    digitalWrite(ENBPin, LOW);
}

void moveLeft(){
    digitalWrite(IN1Pin, HIGH);
    digitalWrite(IN2Pin, LOW); //L-Backward
    digitalWrite(IN3Pin, LOW);
    digitalWrite(IN4Pin, HIGH); //R-Forward
    digitalWrite(ENAPin, HIGH);
    digitalWrite(ENBPin, HIGH);
}

void moveRight(){
    digitalWrite(IN1Pin, LOW);
    digitalWrite(IN2Pin, HIGH); //L-Forward
    digitalWrite(IN3Pin, HIGH);
    digitalWrite(IN4Pin, LOW); //R-Backward
    digitalWrite(ENAPin, HIGH);
    digitalWrite(ENBPin, HIGH);
}

Step 10: Android Apps

Video Streaming :

IP Webcam by Pavel Khlebovich.

Download this on your camera phone if you are using an android phone as the camera. This app will stream your camera through wifi and you can open it in any web browser. Then you can also view it within BlueCam 2 which we use as the tank controller.

First, you need to setup your phone connect to your wireless router. Open IP Webcam then you are taken to the setting page. If you attach your phone to stand vertical on the tank, go to "Video preferences" (the first one in settings), set "Video orientation" to portrait. If you attach your phone in landscape mode like mine, you can skip this one. Go back to Settings. Go to the last item in settings that is "Start server". Then you will see what your camera sees on your screen. At the bottom center you will see something like : "http://your.ip.address.here:port". This is how you connect to your streaming camera. If you are using a web browser then just type that in the address bar. I will tell you later about how to connect from BlueCam 2.

We don't need this screen on because it is on the tank and it will waste the phone's battery. So you click on the "Actions..." button on upper right corner, then choose "Run in background". It will tell you that you can just press the "Home Key" on your phone and this app will still run in background. Click "Ok, I get it!". You will see the IP Webcam icon is on upper left corner, means that it is streaming the video in background, then you can turn off your screen.

Tank Controller :
BlueCam 2 by Johnny Visser.

Download this one on your controller phone. Before you run this apps make sure you have paired your JY-MCU module to your phone. Turn on your tank. Open bluetooth settings on your phone, search for devices. It will shows up as "LINVOR" or "HC-06" with default password "1234" (without quotes). Make sure your phone's wifi is connectinig to the same router as the phone you use as the tank's camera. Turning on bluetooth first before running the app is important, otherwise you won't see the bluetooth paired devices list and you need to exit the app and then open it again. Okay, now let's run the BlueCam 2.

This app is working in landscape mode only and it is good, we will have a wide camera view on the screen. Press the menu (Three Dots) button then choose "Configure buttons". If you don't see the menu buttons, you need to show it permanently in your navigation key. I haven't told Johnny about this one because I have my menu key "always visible" in navigation pane. Go to your Android Phone Settings > Navigation > Navigation bar > Menu visibility > Always show. This might be different a little bit depends on your phone models, but all you have to search is Menu visibility set to always show and it is under navigation bar setting.

Let's move on ... now we configure the buttons to match the sketch we uploaded to Arduino, that is :

  • F for FORWARD button.
  • B for BACKWARD button.
  • L for LEFT button.
  • R for RIGHT button.

Then turn on both Burstmode buttons next to Forward-Backward and Left-Right buttons. This Burstmode is sending the character every 250 ms. So when our finger is still pressing on the arrow, it will keep sending the character to Arduino. If it is off, it will only send the character once even if your finger is pressing the button, and the tank will move once then stop. Special thanks to Johnny who fixed it for us :) The "+" and "-" buttons are not in use. I configure them to send "S" which I called Brake buttons. When I was in testing, the motor won't stop even when I have released my finger from the buttons. Then I need this button to stop the tank. Something on my mind is to put a servo on the camera so that we can move the camera up and down. We don't need the left and right as we can move the wheels :) Now click on the Diskette button to save the buttons configuration.

On bottom left there is a list of paired bluetooth devices. My bluetooth module is already renamed to "PANZER", find your tank either "LINVOR" or "HC-06". Then click on the bluetooth icon, it will change to orange means connecting. If the connection is successful then the icon will change to red. Now you can move your tank with arrow keys.

On bottom right is the address to connect to your IP camera. The default address is :

http://your.ip.address.here/axis-cgi/mjpg/video.cgi?resolution=320x240

Example : http//192.168.1.1/axis-cgi/mjpg/video.cgi?resolution=320x240

Simply change the IP address with your camera IP address. If you are using a phone as IP Camera then type this on the camera address :

http://your.ip.address.here:port/videofeed

Example : http//192.168.1.1:8080/videofeed

Then Click on the Camera icon. There you go.... Spy Panzer is ready for action ^_^

Step 11: Final Words

It is easier to build the Panzer than to write this instruction. But it is okay, I love to share knowledge. Fiuh... I'm glad that it is done. Taking pictures, writing the details, making video, I try to explain as detail as possible, but if I miss something and you have any question regarding this project I will try my best to help you :)

Special thanks to :

ASCAS who inspired me building this panzer. You have so many inspiring iBles.

Johnny Visser who help me out with his free BlueCam 2 on Android.

Pavel Khlebovich who I haven't contact, but his free IP Webcam app on Android works so well.

Explore Science Contest

Participated in the
Explore Science Contest