Arduino TutorialsDIY Arduino Projects For BeginnersRobotics

Arduino robotic car with Bluetooth

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

Arduino robotic car with bluetooth

Design materials

  • 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
  • Two wheels
  • Switch
Arduino robotic car body design
Figure 1: Arduino robotic car body design

Figure one above shows the wooden board cut into a trapezoid with the caster wheel and the gear motors attached to the board.

Arduino robotic car circuit diagram
Figure 2: Arduino robotic car circuit diagram
Arduino robotic car design
Figure 3: Arduino robotic car design

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.


///////////////////////////////////////////// 
//        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 uploaded the sketch to the Arduino board, unplug the USB cable from the Arduino board and turn on the device. Turn on 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 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

Leave a Reply

Your email address will not be published. Required fields are marked *