In this tutorial, you will learn how to make a Bluetooth controlled car using Arduino and LM293 motor driver. Previously, I made tutorial one and tutorial two on how to design a robotic arm with Arduino. In this tutorial, I will show you how to design an Arduino RC car that is controlled via Bluetooth with your smartphone. This is a very interesting project as it will enable you explore the G-sensor and Bluetooth features in your smartphone. See video tutorial below.
Design materials – Bluetooth controlled car
- A wooden board cut in the shape shown in figure 1 below
- Arduino board
- HC-05(06) Bluetooth module
- L298 motor driver
- Three 3.7V lithium ion batteries
- Some jumper wires
- Breadboard cut
- One caster wheel
- Two gear motors with wheels
- Switch
Figure one above shows the wooden board cut into a trapezoid with the caster wheel and the gear motors attached to the board.
Circuit diagram – Bluetooth controlled car
To connect the Arduino robotic car to your phone, you need to download and install the RemoteXY application. Here is the link for Android and for iPhone. The application has the free version and the Pro version, I recommend you buy the Pro version, it gives a better response.
After that, you upload the Arduino code for the design to your Arduino board. Below is the Arduino code, however, make sure you added the RemoteXY library to your IDE before uploading the code. If you do not know how to add Arduino library, check this tutorial. Make sure the switch of the design is turned off before uploading the Arduino code. Upload the code below.
Arduino code
/////////////////////////////////////////////
// RemoteXY include library //
/////////////////////////////////////////////
/* RemoteXY select connection mode and include library */
#define REMOTEXY_MODE__SOFTWARESERIAL
#include <SoftwareSerial.h>
#include <RemoteXY.h>
/* RemoteXY connection settings */
#define REMOTEXY_SERIAL_RX 2
#define REMOTEXY_SERIAL_TX 3
#define REMOTEXY_SERIAL_SPEED 9600
/* RemoteXY configurate */
unsigned char RemoteXY_CONF[] =
{ 3,0,23,0,1,5,5,15,41,11
,43,43,1,2,0,6,5,27,11,5
,79,78,0,79,70,70,0 };
/* this structure defines all the variables of your control interface */
struct {
/* input variable */
signed char joystick_1_x; /* =-100..100 x-coordinate joystick position */
signed char joystick_1_y; /* =-100..100 y-coordinate joystick position */
unsigned char switch_1; /* =1 if switch ON and =0 if OFF */
/* other variable */
unsigned char connect_flag; /* =1 if wire connected, else =0 */
} RemoteXY;
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
/* defined the right motor control pins */
#define PIN_MOTOR_RIGHT_UP 7
#define PIN_MOTOR_RIGHT_DN 6
#define PIN_MOTOR_RIGHT_SPEED 10
/* defined the left motor control pins */
#define PIN_MOTOR_LEFT_UP 5
#define PIN_MOTOR_LEFT_DN 4
#define PIN_MOTOR_LEFT_SPEED 9
/* defined the LED pin */
#define PIN_LED 13
/* defined two arrays with a list of pins for each motor */
unsigned char RightMotor[3] =
{PIN_MOTOR_RIGHT_UP, PIN_MOTOR_RIGHT_DN, PIN_MOTOR_RIGHT_SPEED};
unsigned char LeftMotor[3] =
{PIN_MOTOR_LEFT_UP, PIN_MOTOR_LEFT_DN, PIN_MOTOR_LEFT_SPEED};
/*
speed control of the motor
motor - pointer to an array of pins
v - motor speed can be set from -100 to 100
*/
void Wheel (unsigned char * motor, int v)
{
if (v>100) v=100;
if (v<-100) v=-100;
if (v>0) {
digitalWrite(motor[0], HIGH);
digitalWrite(motor[1], LOW);
analogWrite(motor[2], v*2.55);
}
else if (v<0) {
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], HIGH);
analogWrite(motor[2], (-v)*2.55);
}
else {
digitalWrite(motor[0], LOW);
digitalWrite(motor[1], LOW);
analogWrite(motor[2], 0);
}
}
void setup()
{
/* initialization pins */
pinMode (PIN_MOTOR_RIGHT_UP, OUTPUT);
pinMode (PIN_MOTOR_RIGHT_DN, OUTPUT);
pinMode (PIN_MOTOR_LEFT_UP, OUTPUT);
pinMode (PIN_MOTOR_LEFT_DN, OUTPUT);
pinMode (PIN_LED, OUTPUT);
/* initialization module RemoteXY */
RemoteXY_Init ();
}
void loop()
{
/* event handler module RemoteXY */
RemoteXY_Handler ();
/* manage LED pin */
digitalWrite (PIN_LED, (RemoteXY.switch_1==0)?LOW:HIGH);
/* manage the right motor */
Wheel (RightMotor, RemoteXY.joystick_1_y - RemoteXY.joystick_1_x);
/* manage the left motor */
Wheel (LeftMotor, RemoteXY.joystick_1_y + RemoteXY.joystick_1_x);
}
Once you’ve uploaded the sketch to the Arduino board, unplug the USB cable from the Arduino board and turn on the device. Turn on the Bluetooth device on your phone as well and open the RemoteXY application, click the + button on the top right corner of the application to add new device, then click Bluetooth for Android devices or Bluetooth BLE for Apple devices. Connect your phone’s Bluetooth to the Bluetooth on the RC robotic car, once that is done, the Bluetooth icon will appear on your phone to show that the Arduino application and the Android GUI to control the robotic car have been successfully uploaded, then click the Bluetooth icon and the phone will connect with the robot, immediately you will see the GUI to control the robotic car appear on phone screen. Now you can control your robotic car with your cell phone by holding down the directional button to the direction you want the car to go, or by tilting your phone to the direction you want the car to move after switching to G-sensor mode.
This is how you can design a cell phone controlled robotic car with Arduino and Bluetooth. I will be making more videos like this in the future, so, consider subscribing to my YouTube channel so you don’t miss any interesting tutorial.
Further reading
Check out these other tutorials
Bluetooth controlled scrolling text display
Password based door lock
Remote controlled light switch
Arduino water level indicator