loading

This is a simple project of Android Bluetooth Car with Bluetooth control. Arduino controller is used

To control the car used Android-device with a built-in accelerometer. Tilt forward - car goes forward, tilt to the left - car turns to the left, tilt back - car goes back. Speed of movement or rotation depends on how much you tilt the device. Sensitivity and value of the tilt set in the configuration Android-apps. Also are provided a normal way to control: the buttons on the screen. In addition to all I implemented the touch control. Total 3 ways to control the RC Car.

Capabilities of the device you can see on the video above

Step 1: Android device

Parts needed

1. Android device

The most important part - Android device with accelerometer and Bluetooth: tablet, smartphone and other... As an Android device, I used a cheap Chinese tablet "Ainol Aurora" with an external USB-Bluetooth module (because its not have own), connected via USB Host.

Step 2: DIY Car Chassis

2. DIY Car Chassis

We also need any chassis with 2 or 4 DC motors. You can use an old RC toy car. As a platform I used a small RC DIY platform, bought on AliExpress for 25$. It's most suitable track chassis for this project.

Step 3: Controller (MCU)

3. Controller (MCU)

You need any Arduino-compatible controller (Nano, Uno, Leonardo, Mini and other)

The controller should contain 2 PWM and UART.

Step 4: Bluetooth module

4. Bluetooth module

As a Bluetooth module uses cheap Chinese module Bluetooth Serial HC-06 (3-4$ on AliExpress). Instructions guide on connecting bluetooth module to Arduino is here.
You can use HC-05, HC-07 and other serial Bluetooth modules

Step 5: Motor Driver

5. Motor Driver

I used L298N Dual Bridge DC stepper Motor Driver module. It cost 3-5$ on AliExpress.

Step 6: Other parts

6. Other parts

Step 7: Theory

Theory

All calculations are performed in the Android-application, and immediately calculate the values 2‹2‹of the PWM for the left and right motor. Application has flexible settings, such as the range of the PWM, the sensitivity of tilt, the minimum threshold for the PWM and other. Example commands transmitted by Bluetooth:
L-255\rR-120\r
L - the command to the left engine, R - for the right
A dash means the motor rotation to move back
255 - PWM value (for Arduino is the maximum speed of rotation)
\r - end of command.
On this command RC car will move forward and slightly rotated to the right, as right engine rotates slowly left.

L255\rR-255\r
On this command the left engine will rotate back and forward right, forcing a car to rotate around its axis counterclockwise.

H1\r
Command is an additional channel to which you can connect for example lights, sound, etc.

Symbols command L, R and H can be defined in the settings of Android-applications.

In the MCU control program provides a timer that shuts off the engine if the last command was received more than n-seconds ago. The data are stored in the EEPROM memory of the controller and can be changed from Android device. The range of this setting is from 0.1 seconds to 99.9 seconds. This setting can be disabled. To work with EEPROM provides commands: Fr - reading values 2‹2‹and Fw - record values.

Electronics

Block diagram see on picture above

Step 8: Android Application

As we can see, the Arduino connects to Bluetooth module and a motor driver with two or four connected motors.

Android Application

The application for Android was written in Eclipse IDE. All sources of the project and the project for Eclipse, you can download below. Android version on your device must be > 3.0.

The application contains several activity. Main activity is a home screen with buttons running different operating modes and settings

There are 3 control modes Bluetooth-car: from accelerometer, screen buttons and touch-control.

Android application settings

Screenshot of settings CxemCar Android application version 1.0

MAC address

To establish a connection with the RC Car's Bluetooth module, you must set MAC-address in the application settings. But first, you must configure the pair the devices on Android-device: open Settings -> Bluetooth and click "Search for devices". When the phone finds our Bluetooth-module, click them and enter password for pairing (usually "1234")

To know Bluetooth module MAC-address possible from any application, such as Bluetooth Terminal. To do this, click "Connect a device - Secure" and in the resulting window, click the button "Scan for devices". Software will be scans the Bluetooth devices and displays them MAC-address.

Step 9: Arduino RC car wiring

Wiring diagram for Arduino controller

In the circuit I used a jumper (in the scheme Jmp1), because with a connected Bluetooth module is impossible be load sketch to the Arduino.

I soldered a Bluetooth-module to the Arduino and led status light. For communication between Arduino and Bluetooth, read this article: Arduino and Bluetooth. Module HC-06 placed in heat-shrink tube 10mm. Bluetooth-state LED with current limiting resistor (calculator) were also placed in heat-shrink tube.

In the breadboard platform, I drilled a hole and secure motor driver L298N. Arduino board attached with double-sided tape

Between the car platform and breadboard I placed 3 Li-Po battery 3.7V 1100 mAh. Power to the controller and motors separately: Arduino powered by a 3.7 V battery, and the motors and driver L298N from two 3.7V batteries connected in series. There are two 2-position power switch - one position is the power from the batteries to consumers, in the other position to charging terminals.

Beetween BT pin RX (2) and Arduino pin TX may require level shifter. For this, you can use voltage divider: calculator 5V to 3.3V

Step 10: Software

The program was written in Arduino IDE 1.01.


#include "EEPROM.h"

#define D1 2 // direction of motor rotation 1
#define M1 3 // PWM left motor
#define D2 4 // direction of motor rotation 2
#define M2 5 // PWM right motor
#define HORN 13 // additional channel 1
//#define autoOFF 2500 // milliseconds after which the robot stops when the connection

#define cmdL 'L' // UART-command for left motor
#define cmdR 'R' // UART-command for right motor
#define cmdH 'H' // UART-command for additional channel (for example Horn)
#define cmdF 'F' // UART-command for EEPROM operation
#define cmdr 'r' // UART-command for EEPROM operation (read)
#define cmdw 'w' // UART-command for EEPROM operation (write)

char incomingByte; // incoming data

char L_Data[4]; // array data for left motor
byte L_index = 0; // index of array L
char R_Data[4]; // array data for right motor
byte R_index = 0; // index of array R
char H_Data[1]; // array data for additional channel
byte H_index = 0; // index of array H
char F_Data[8]; // array data for EEPROM
byte F_index = 0; // index of array F
char command; // command

unsigned long currentTime, lastTimeCommand, autoOFF;

void setup() {
Serial.begin(9600); // initialization UART
pinMode(HORN, OUTPUT); // additional channel
pinMode(D1, OUTPUT); // output for motor rotation
pinMode(D2, OUTPUT); // output for motor rotation
/*EEPROM.write(0,255);
EEPROM.write(1,255);
EEPROM.write(2,255);
EEPROM.write(3,255);*/
timer_init(); // initialization software timer
}

void timer_init() {
uint8_t sw_autoOFF = EEPROM.read(0); // read EEPROM "is activated or not stopping the car when losing connection"
if(sw_autoOFF == '1'){ // if activated
char var_Data[3];
var_Data[0] = EEPROM.read(1);
var_Data[1] = EEPROM.read(2);
var_Data[2] = EEPROM.read(3);
autoOFF = atoi(var_Data)*100; // variable autoOFF ms
}
else if(sw_autoOFF == '0'){
autoOFF = 999999;
}
else if(sw_autoOFF == 255){
autoOFF = 2500; // if the EEPROM is blank, dafault value is 2.5 sec
}
currentTime = millis(); // read the time elapsed since application start
}

void loop() {
if (Serial.available() > 0) { // if received UART data
incomingByte = Serial.read(); // raed byte
if(incomingByte == cmdL) { // if received data for left motor L
command = cmdL; // current command
memset(L_Data,0,sizeof(L_Data)); // clear array
L_index = 0; // resetting array index
}
else if(incomingByte == cmdR) { // if received data for left motor R
command = cmdR;
memset(R_Data,0,sizeof(R_Data));
R_index = 0;
}
else if(incomingByte == cmdH) { // if received data for additional channel
command = cmdH;
memset(H_Data,0,sizeof(H_Data));
H_index = 0;
}
else if(incomingByte == cmdF) { // if received data for EEPROM op
command = cmdF;
memset(F_Data,0,sizeof(F_Data));
F_index = 0;
}
else if(incomingByte == '\r') command = 'e'; // end of line
else if(incomingByte == '\t') command = 't'; // end of line for EEPROM op

if(command == cmdL && incomingByte != cmdL){
L_Data[L_index] = incomingByte; // store each byte in the array
L_index++; // increment array index
}
else if(command == cmdR && incomingByte != cmdR){
R_Data[R_index] = incomingByte;
R_index++;
}
else if(command == cmdH && incomingByte != cmdH){
H_Data[H_index] = incomingByte;
H_index++;
}
else if(command == cmdF && incomingByte != cmdF){
F_Data[F_index] = incomingByte;
F_index++;
}
else if(command == 'e'){ // if we take the line end
Control4WD(atoi(L_Data),atoi(R_Data),atoi(H_Data));
delay(10);
}
else if(command == 't'){ // if we take the EEPROM line end
Flash_Op(F_Data[0],F_Data[1],F_Data[2],F_Data[3],F_Data[4]);
}
lastTimeCommand = millis(); // read the time elapsed since application start
}
if(millis() >= (lastTimeCommand + autoOFF)){ // compare the current timer with variable lastTimeCommand + autoOFF
Control4WD(0,0,0); // stop the car
}
}

void Control4WD(int mLeft, int mRight, uint8_t Horn){

bool directionL, directionR; // direction of motor rotation L298N
byte valueL, valueR; // PWM M1, M2 (0-255)

if(mLeft > 0){
valueL = mLeft;
directionL = 0;
}
else if(mLeft < 0){
valueL = 255 - abs(mLeft);
directionL = 1;
}
else {
directionL = 0;
valueL = 0;
}

if(mRight > 0){
valueR = mRight;
directionR = 0;
}
else if(mRight < 0){
valueR = 255 - abs(mRight);
directionR = 1;
}
else {
directionR = 0;
valueR = 0;
}

analogWrite(M1, valueL); // set speed for left motor
analogWrite(M2, valueR); // set speed for right motor
digitalWrite(D1, directionL); // set direction of left motor rotation
digitalWrite(D2, directionR); // set direction of right motor rotation

digitalWrite(HORN, Horn); // additional channel
}

void Flash_Op(char FCMD, uint8_t z1, uint8_t z2, uint8_t z3, uint8_t z4){

if(FCMD == cmdr){ // if EEPROM data read command
Serial.print("FData:"); // send EEPROM data
Serial.write(EEPROM.read(0)); // read value from the memory with 0 address and print it to UART
Serial.write(EEPROM.read(1));
Serial.write(EEPROM.read(2));
Serial.write(EEPROM.read(3));
Serial.print("\r\n"); // mark the end of the transmission of data EEPROM
}
else if(FCMD == cmdw){ // if EEPROM data write command
EEPROM.write(0,z1); // z1 record to a memory with 0 address
EEPROM.write(1,z2);
EEPROM.write(2,z3);
EEPROM.write(3,z4);
timer_init(); // reinitialize the timer
Serial.print("FWOK\r\n"); // send a message that the data is successfully written to EEPROM
}

The code uses a library to work with EEPROM AVR-memory. Arduino board by USART from the Bluetooth module receives data ready for the left and right engine. All basic calculations are performed in the Android application.

The project structure in Eclipse you can see on the screenshot above.

You can download the source code for the Arduino, and the project for Eclipse
DownloadAPK application for Android-device

The latest software version can be found on this page
Video of demonstration the virtual steering wheel mode (1.2 version and above):

P.S. Sorry for my bad english

<p>Thanks, Work great.</p><p>A little tweaks and it works on on already buillt car :D</p>
<p>add a } to the end so </p><p>else if(FCMD == cmdw){ // if EEPROM data write command</p><p>EEPROM.write(0,z1); // z1 record to a memory with 0 address</p><p>EEPROM.write(1,z2);</p><p>EEPROM.write(2,z3);</p><p>EEPROM.write(3,z4);</p><p>timer_init(); // reinitialize the timer</p><p>Serial.print(&quot;FWOK\r\n&quot;); // send a message that the data is successfully written to EEPROM</p><p>}}</p><p>then compile</p>
<p>reply guys</p>
<p>expected '}' at end of input<br><br>}<br><br>^<br><br>exit status 1<br><br>expected '}' at end of input</p><p>please help me out</p>
<p>thodi bhain di</p>
<p>Bluetooth is not getting detected I am using HC-05. What could be wrong?</p>
<p>id adding more motor driver possible, where do i hook it up?</p>
<p>i made it. at the end all you got to do is to make a parallel switching from D3 to PWM for right motor and D5 to PWM for left motor. it enables the working of both the motors.</p>
<p>did you mean the program or wires</p>
<p>hi there, i need help, I used arduino uno, correctly done my wiring connection, everything seems in correct order, as per instructions. I installed the Cxemcar 1.2 to my smartphone, connected the bluetooth successfully. But the main problem is, both motors are not moving at all. I measured L289 motor driver output voltages, they are both O volts (while pressing forward or backward from the button controls of Cxemcar). Can anyone help me..thanks a lot.</p>
<p>hi there, i need help, I used arduino uno, correctly done my wiring connection, everything seems in correct order, as per instructions. I installed the Cxemcar 1.2 to my smartphone, connected the bluetooth successfully. But the main problem is, both motors are not moving at all. I measured L289 motor driver output voltages, they are both O volts (while pressing forward or backward from the button controls of Cxemcar). Can anyone help me..thanks a lot.</p>
<p>hi there, i need help, I used arduino uno, correctly done my wiring connection, everything seems in correct order, as per instructions. I installed the Cxemcar 1.2 to my smartphone, connected the bluetooth successfully. But the main problem is, both motors are not moving at all. I measured L289 motor driver output voltages, they are both O volts (while pressing forward or backward from the button controls of Cxemcar). Can anyone help me..thanks a lot.</p>
<p>hi there, i need help, I used arduino uno, correctly done my wiring connection, everything seems in correct order, as per instructions. I installed the Cxemcar 1.2 to my smartphone, connected the bluetooth successfully. But the main problem is, both motors are not moving at all. I measured L289 motor driver output voltages, they are both O volts (while pressing forward or backward from the button controls of Cxemcar). Can anyone help me..thanks a lot.</p>
<p>hi there, i need help, I used arduino uno, correctly done my wiring connection, everything seems in correct order, as per instructions. I installed the Cxemcar 1.2 to my smartphone, connected the bluetooth successfully. But the main problem is, both motors are not moving at all. I measured L289 motor driver output voltages, they are both O volts (while pressing forward or backward from the button controls of Cxemcar). Can anyone help me..thanks a lot.</p>
<p>hi there, i need help, I used arduino uno, correctly done my wiring connection, everything seems in correct order, as per instructions. I installed the Cxemcar 1.2 to my smartphone, connected the bluetooth successfully. But the main problem is, both motors are not moving at all. I measured L289 motor driver output voltages, they are both O volts (while pressing forward or backward from the button controls of Cxemcar). Can anyone help me..thanks a lot.</p>
expected '}' at end of input<br><br>}<br><br>^<br><br>exit status 1<br><br>expected '}' at end of input<br>When i caheched the program it showa like this can anyone help me? Plz. Anyone give the perfect program plz.!
<p>great project </p>
<p>got the car assembled but when i try to test it, it comes up with &quot;socket fail&quot; and wont go or do anything. can someone help me with this? do i need to change anything in the code?</p>
<p>I made it. It works awesome. I made my own motor driver circuit though. I used 2 motor drivers to control 4 motors.</p><p>@<a href="http://www.instructables.com/member/jasonjason931" rel="nofollow">jasonjason931</a>, the code is just fine. All you have to do is go to device manager (if you are using windows) and change the Com port to Com 5. Folow this link - &quot;http://plugable.com/2011/07/04/how-to-change-the-com-port-for-a-usb-serial-adapter-on-windows-7&quot; to change it. Also don't forget to change the MAC address on the android app. Set the MAC address to your bluetooth adapter's address. That should work.</p>
Okay so I tried what you said to do, but still keep getting socket fail, whenever I try it on my phone.
Thanks! I'll give that a try! And let you know!
<p>after pasting the code into the software, i got it checked and it replied with the error: Arduino: 1.6.7 (Windows 8.1), Board: &quot;Arduino Nano, ATmega328&quot;</p><p>Build options changed, rebuilding all</p><p>C:\Users\hugh\Desktop\sketch_feb25a\bluetooth\bluetooth.ino: In function 'void Flash_Op(char, uint8_t, uint8_t, uint8_t, uint8_t)':</p><p>bluetooth:173: error: expected '}' at end of input</p><p> }</p><p> ^</p><p>exit status 1</p><p>expected '}' at end of input</p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences.</p><p>can you help me solve it please?</p>
<p>this is the screenshot</p>
просто у меня эта программа не работает
ena и enb куда подключать и подключать ли вообще?
можно использовать с другим приложением?
<p>i made it. at the end all you got to do is to make a parallel switching from D3 to PWM for right motor and D5 to PWM for left motor. it enables the working of both the motors.</p>
Hey can u pls tell me how did u make it.
<p>Hello all i've made it but the motors are not running :( it is unresponsive to the app!</p>
Same thing is happening with me. I have completed assembling and programming but car's not even moving..
<p>can you tell me which type of motor is preferred for this project? If the attached motor would work???</p>
<p>Yes i'm using the same motors</p>
<p>Hello all I have made it but when I connect it to app it says &quot;socket Failed&quot; and motors won't start i m using uno here is the picture -</p>
<p>Very nice project! If you're interested, an alternative to the Arduino is the IOIO board. There is an Android library that goes with it, so you can put an Android phone on the RC car and control the car by wirelessly connecting to the phone. Have you heard of Android Based Robotics (ABR)? They have instructions and code. Check it out! http://www.socsci.uci.edu/~jkrichma/ABR/index.html</p>
<p>i made it. at the end all you got to do is to make a parallel switching from D3 to PWM for right motor and D5 to PWM for left motor. it enables the working of both the motors.</p>
<p>i made it. at the end all you got to do is to make a parallel switching from D3 to PWM for right motor and D5 to PWM for left motor. it enables the working of both the motors.</p>
<p>i dont know where the fault lies, but i did as it was shown.</p><p>Now the thing goes like,</p><p>from arduino nano, the out put are four for the motor driver L298N in which 2--&gt; are for PWM of left and right (D3, D5) and other 2--&gt; are for the direction of motor (D2, D4).</p><p>But at motor driver's end there are six inputs for direction, the clock and anti clockwise direction for and right motors separately in input ((in1, in2) left motor, (in3, in4) right motor) and two for PWM.</p><p>please guide me that how to attach arduino to the motor driver.</p><p>i used the above code but its still not working.</p><p>So it doesnt take any command. Else, it stops when pressed front or back button. </p>
<p>yes but they are used as pwm only if you want a step motor. Here just power the inA and inB motor pin with 5V and should work fine.</p>
<p>actually i did that. but without using pwm sockets, the motor aint running in any direction. </p>
<p>i keep getting the error message &quot;socket failed&quot; on the android device. Pls Help</p>
<p>can u please send the code very urgent , need for a project plss on nikhildhoka8@gmail.com</p>
<p>Motors are not moving .</p><p>Motor driver requires 6 input pins 2 for PWM and 4 for direction control.</p><p>But in this project there are only $ input pins for motor driver 2 PWM and @ direction.</p><p>Here is a link of Motor Driver working principal</p><p><a href="http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/?ALLSTEPS" rel="nofollow">http://www.instructables.com/id/Arduino-Modules-L2...</a></p>
<p>exactly, even i faced the same problem. from arduino nano, the out put are four in which 2--&gt; are for PWM of left and right (D3, D5) and other 2--&gt; are for the direction of motor (D2, D4).</p><p>But at motor driver's end there are four inputs for direction, the clock and anti clockwise direction for and right motors separately in input ((in1, in2) left motor, (in3, in4) right motor).</p><p>So it doesnt take any command. else, it stops when pressed front or back button. please help </p>
<p>does anyone have the code with no error to send me pls. koffih81@gmail.com</p>
<p>motor is not running,,, what should i do???</p>
See wires
Hello tolik777.a message &quot;socket failed&quot; appeared on my cxem apps when i tried to control it.what does it mean?please help me.

About This Instructable

498,148views

1,004favorites

License:

Bio: I like Electronics, Robots and Arduino!
More by tolik777:Android controlled RC Vehicle with real-time Video via Bluetooth & Wi-FiCxemCAR 1 - Android Control RC Car over BluetoothArduino Ampermeter (ZXCT IC's)
Add instructable to: