Android Controlled RC CAR (Easy-Fun-DIY)

Android Controlled RC CAR (Easy-Fun-DIY)

In this tutorial we will make a remote control car which can be controlled by any android device.It is a fun and cool ,yet easy project to start with if you are trying to start with robotics. So, don’t be afraid even if its your first robotics project. just follow the instructions and you will end up holding your android device controlling the car. ūüôā
let’s start then…

 

First lets see what we need for this tutorial !!

Well, for this tutorial we only need:

1. An Arduino Uno

2. Robot Car Chassis.

3. L298n Motor driver.

4. Hc-06 bluetooth module.

5. 9v battery*

6. 9v battery holder.

7. jumper wire (m-m / m-f)

8.small rocker switch (can be found at any electric shop)

9. screws for arduino and motor driver

10. spare wires (1 meter will be more than enough)

11. screw driver

12. Android device.

Battery Selection

Here ¬†I am preferring 9 volt batteries because they are easily available and quite serves my purpose.But there are many other batteries that can be used also.like lead acid batteries or series of li-ion mobile batteries and also rechargeable li-ion 18650 cells that are used in high powered torch. 9 volt batteries are safe and easy to use but not rechargeable . 9 volt batteries may give backup¬†to this kind of robot upto 15 mins .For better backup of course you can use any rechargeable battery of 8-12 volt that you find easy to interface and charge. here’s some help.

too much of discussion…now lets start making the bot…

Preparing the chassis

the robotic car chassis kit is a DIY(do it yourself) kit.so first task to make the robot would be to prepare the chassis as per the instruction provided in the kit. There is a battery case for AAA batteries included in the kit.As we are using 9 volt batteries we won’t be needing those.So follow the instructions and make the chassis,just exclude the battery case.you can also exclude the round encoders.
it will look like this,

Intelligent-Car-Robot-Chassis-with-Speed-Encoder-diy-RC-Toy-remote-control-r3-raspberry-pi-development

Connections

for connections you will need wire cutter and screw driver.For securing the motor driver connections you will need a Philip head screw driver. For cutting the wires you have the freedom to use your teeth if you don’t have any wire cutter. ūüėÄ

here’s the connection diagram,

9v battery(+)       > switch > motor driver +12v
9v battery (-)       > motor driver ground (gnd) >arduino Gnd
motor driver +5v > arduino vcc
bluetooth vcc      > arduino 5v
bluetooth gnd      > arduino gnd
bluetooth txd       > arduino pin 0
motor driver in1  > arduino pin 5
motor driver in2  >  arduino pin 6
motor driver in3  >  arduino pin 10
motor driver in4  >  arduino pin 11
motors                > as shown

there is no marking on the motors included in the Chassis kit to know the positive or negative sides of the motor cables, so in the first attempt while we will be controlling the car it might happen that the forward button is driving the car crazy ūüėÄ .
don’t panic i will discuss the problem at the end of this tutorial to calibrate the rotating direction of the motors.

use spare wires to connect the switch.Now to combine the chassis and the circuit use the following positions for switch,motor driver and arduino. you can also use both sided tape or hot glue gun or zip tie to fix the components(including bluetooth module) on the chassis.
to fix the battery use both sided tape or electric tape.Don’t permanently fix the battery as we are using a non rechargeable one.

Final Look

 

roughly our robot car should look like this,

F96LLQ0IEA9GZ8E.MEDIUM

here in the picture i’ve used an 9v to barrel jack¬†pin to power the arduino. But to use a cable connector is more convenient as shown in the diagram.

Coding the arduino

the code is here, Copy and paste it on your arduino ide. To know the full procedure to upload a code to arduino you can click here.
for this project you have to disconnect the bluetooth tx wire from arduino pin0 while uploading the code and when the code is successfully uploaded, again reconnect the wire to pin 0.
now lets concentrate on the code.The code is not very complicated. You can easily understand the functions and commands.

 //This program is used to control a robot using a app that communicates with Arduino through a bluetooth module.
//Error Code Chart: Code 01; Turnradius is higher than Speed; Code 02; Speed is higher than 255;
#define in1 5 //L298n Motor Driver pins.
#define in2 6
#define in3 10
#define in4 11
#define LED 13
int command; //Int to store app command state.
int Speed = 204; // 0 - 255.
int Speedsec;
int buttonState = 0;
int lastButtonState = 0;
int Turnradius = 0; //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed.
int brakeTime = 45;
int brkonoff = 1; //1 for the electronic braking system, 0 for normal.
void setup() {
 pinMode(in1, OUTPUT);
 pinMode(in2, OUTPUT);
 pinMode(in3, OUTPUT);
 pinMode(in4, OUTPUT);
 pinMode(LED, OUTPUT); //Set the LED pin.
 Serial.begin(9600); //Set the baud rate to your Bluetooth module.
}

void loop() {
 if (Serial.available() > 0) {
 command = Serial.read();
 Stop(); //Initialize with motors stoped.
 switch (command) {
 case 'F':
 forward();
 break;
 case 'B':
 back();
 break;
 case 'L':
 left();
 break;
 case 'R':
 right();
 break;
 case 'G':
 forwardleft();
 break;
 case 'I':
 forwardright();
 break;
 case 'H':
 backleft();
 break;
 case 'J':
 backright();
 break;
 case '0':
 Speed = 100;
 break;
 case '1':
 Speed = 140;
 break;
 case '2':
 Speed = 153;
 break;
 case '3':
 Speed = 165;
 break;
 case '4':
 Speed = 178;
 break;
 case '5':
 Speed = 191;
 break;
 case '6':
 Speed = 204;
 break;
 case '7':
 Speed = 216;
 break;
 case '8':
 Speed = 229;
 break;
 case '9':
 Speed = 242;
 break;
 case 'q':
 Speed = 255;
 break;
 }
 Speedsec = Turnradius;
 if (brkonoff == 1) {
 brakeOn();
 } else {
 brakeOff();
 }
 }
}

void forward() {
 analogWrite(in1, Speed);
 analogWrite(in3, Speed);
}

void back() {
 analogWrite(in2, Speed);
 analogWrite(in4, Speed);
}

void left() {
 analogWrite(in3, Speed);
 analogWrite(in2, Speed);
}

void right() {
 analogWrite(in4, Speed);
 analogWrite(in1, Speed);
}
void forwardleft() {
 analogWrite(in1, Speedsec);
 analogWrite(in3, Speed);
}
void forwardright() {
 analogWrite(in1, Speed);
 analogWrite(in3, Speedsec);
}
void backright() {
 analogWrite(in2, Speed);
 analogWrite(in4, Speedsec);
}
void backleft() {
 analogWrite(in2, Speedsec);
 analogWrite(in4, Speed);
}

void Stop() {
 analogWrite(in1, 0);
 analogWrite(in2, 0);
 analogWrite(in3, 0);
 analogWrite(in4, 0);
}

void brakeOn() {
 //Here's the future use: an electronic braking system!
 // read the pushbutton input pin:
 buttonState = command;
 // compare the buttonState to its previous state
 if (buttonState != lastButtonState) {
 // if the state has changed, increment the counter
 if (buttonState == 'S') {
 if (lastButtonState != buttonState) {
 digitalWrite(in1, HIGH);
 digitalWrite(in2, HIGH);
 digitalWrite(in3, HIGH);
 digitalWrite(in4, HIGH);
 delay(brakeTime);
 Stop();
 }
 }
 // save the current state as the last state,
 //for next time through the loop
 lastButtonState = buttonState;
 }
}
void brakeOff() {

}

 

Android App
download the app from playstore.The app is called Arduino Bluetooth RC Car .click on the name and you will be directed to playstore or visit the following link,
https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&hl=en

install it on your android device.And we are ready for our first attempt.

Connecting to car bluetooth
First turn on your mobile bluetooth and turn on the switch of your rc car.Open the app and click on the red circle on the top left corner.then you will see the available devices.Your bluetooth car will be named as HC-05 or HC-06. Select the device name and the red coloured circle will become green.It means you are successfully connected.
now first adjust the slider on the top right corner to maximum and try to go forward pressing the forward button on the left side of the app.
if the car accelerates forward then BRAVO!

play with it! ūüėÄ

calibration
if the forward button doesn’t move the car forward then there are some cases that might happen. First you have to observe the rotation of the wheels.Based on the error in direction of the wheel rotation swap the motor wires that are connected to motor driver. For example if the right wheel is moving forward but the left wheel is moving backward¬†then swap the two cables of the left motor.
if it happens that pressing left button, your car is moving right.Then you can swap the right motor cable with the left one.

Facts
1. The side with two wheels is the front of your car.
2. You can also control your car by motion.Yes, there is a accelerometer option in the app.
3. The code was originally written by the person who made the app.I made some minor changes to simplify.
4. you have the full authority to leave a comment if you face any problem or have any suggestion,query regarding the project.
5.Have fun!!    

stay cool,stay smart,
stay with Robotics¬†ūüėÄ


What are your thoughts?