Simple RC Car for Beginners (Android Control Over Bluetooth) _ 10 Steps (with Pictures) - Instructables
Simple RC Car for Beginners (Android Control Over Bluetooth) _ 10 Steps (with Pictures) - Instructables
By tolik777 in CircuitsRobots
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.
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.
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.
3. Controller (MCU)
You need any Arduino-compatible controller (Nano, Uno, Leonardo, Mini and other)
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.
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.
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
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.
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
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
#include "EEPROM.h"
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
void Flash_Op(char FCMD, uint8_t z1, uint8_t z2, uint8_t z3, uint8_t z4){
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