Saturday, November 21, 2015

Arduino Bluetooth Panzer

We have used remote control cars during our childhood and they are fun to drive the room or wandering the house. What could be more fun of these remote control cars. Suppose you have CCTV cameras around the house or office but there are some blind spots that are not covered by them like corner areas,then this project can be your Patrol Cam.

You can make this project very easily.For this,you can buy any rover on the market that has gorgeous futuristic cases.


Step 1: Materials Required

• An Arduino Uno R3 compatible.
• L298N Dual DC Motor Driver.
• A wireless Arduino IP camera.
Arduino Bluetooth Module (the cheapest HC-05 bluetooth module on www.robomart.com).
• Some mini cables or 1-pin project cables. Battery pack, here I use 7.4V Li-Po 
• Mini on/off switch for battery.
• Dual Motor Gearbox complete with two standard DC Motors.
• Tank Treads.
• Universal Plate Set.
• Cable ties.

Materials Required


Step 2: Chassis

We can use several modes of chassis that can be made by Universal Plate and Track and Wheel Set.You can try several combination so that you can get what mode you want.There are some configuration that are only suitable for flat tracks and other may be good for All Terrain Forward.

Here,I have picked Tank mode because it is best for All Terrain Forward and Backward moving. After assembling the motor gear set ,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.

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.
Chassis

Step 3: How to do Wiring : Bluetooth Module to Arduino

Here,I have used HC-05 bluetooth module and you can more about this product by visting this link or you can just google keyword “HC-05”.

Wiring Bluetooth module on Arduino Uno R3 is very easy as 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.

Here,I have used rainbow-color cables so that it will be easy to guide you and now I am explaining you which color 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).


Step 4: Wiring : L298N Motor Driver to Arduino

Now,again I am going to explain you the connections 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, you can post your comment,I will try my best to help you.


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 points 1 and 2,after testing when the wheels move the opposite way than the button you pressed, you need to interchange the terminal wires. That is why, here,I solder female headers on the motors' terminals, so that we can easily swap them.



Step 7: Adding a WiFi Camera

Now we put an eye on the tank. 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 main board which handle the video streaming wirelessly and the camera module itself.  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.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

I have to tell you that my OpAmp chip on my camera mainboard smokes.
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.

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 put 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

/*
  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 :

You have to 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.

Firstly, you need to setup your phone and connect it to your wireless router. After that open your IP Webcam then you will be taken to the settings page. If you attach your phone to stand vertical on the tank,go to “Video preferences”  
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 :

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.

Step 11: Result

Below,I am providing you the link which will show you how will it work.


 




No comments:

Post a Comment