In the previous article, I have shared how to use a Bluetooth module. If you haven’t checked it already, here is a link to that tutorial. In this tutorial, I will share how to make a robot car which can be controlled using a smartphone over Bluetooth. Let’s see what we need to make this robot.

Requirements:

  • Arduino Uno
  • Arduino Motor shield
  • Bluetooth Module
  • Geared DC Motors
  • Batteries
  • 2k ohm and 1k ohm Resistors each.

Along with the hardware components we also need following software:

Making The Chassis:

I will be making the chassis using sunboard, but you can buy a 2WD robotic platform too. Here is a picture of my design :

Robot Chassis

As you can see I have used 2 pieces of sunboard, On bottom board I have attached 2 geared motors using angled brackets.
Then I placed another board on top and placed arduino + motor shield and Bluetooth module on top.

Making Connections:

Make the connections as shown in the diagram below:

Circuit diagram

Make sure to note the Pinouts and make the connection correctly. Also It is important to make the voltage divider using the resistors. If not done correctly, you can end up with a dead module.

  • Tx => Rx of Arduino (Pin 0)
  • Rx => Tx of Arduino (Pin 1)
  • GND => GND
  • Vcc => +5v


Here is a picture of how I connected the wires:

Next place the motor shield on top slowly. Be careful not to bend any pins.

Connect the motors to M1 and M2 terminals of the Motor Shield .

Coding:

To make the robot work we have to upload a code to the Arduino. Refer the Following code , I have kept it simple and clean for beginners, If you are an experienced coder you can add more things to it like additional sensors, Lights etc.
I suggest you write the code instead of coping it so that you get a better understanding of it.

#include<AFMotor.h>

AF_DCMotor motorR(1);
AF_DCMotor motorL(2);
char data = 0;

void setup()
{
    Serial.begin(9600);                               
    Serial.println("Motor test !");
    motorR.setSpeed(200);
    motorL.setSpeed(200);
}

void forward()
{
  Serial.println("Going Forward...");
  delay(500);
  motorR.run(FORWARD);
  motorL.run(FORWARD);
}

void backward()
{
  Serial.println("Going Backward...");
  delay(500);
  motorR.run(BACKWARD);
  motorL.run(BACKWARD);
}

void left()
{
  Serial.println("Turning Left...");
  delay(500);
  motorR.run(FORWARD);
  motorL.run(RELEASE);
}

void right()
{
  Serial.println("Turning Right...");
  delay(500);
  motorR.run(RELEASE);
  motorL.run(FORWARD);
}

void hold()
{
  Serial.println("Stop...");
  delay(500);
  motorR.run(RELEASE);
  motorL.run(RELEASE);
}

void spinRight()
{
  Serial.println("Spining Right...");
  delay(500);
  motorR.run(BACKWARD);
  motorL.run(FORWARD);
}

void spinLeft()
{
  Serial.println("Spining Left...");
  delay(500);
  motorR.run(FORWARD);
  motorL.run(BACKWARD);
}
void loop()
{
   if(Serial.available() > 0)  
   {
      data = Serial.read(); 
      Serial.println(data);
                
      if(data == 'a')
      {
        forward();
      }
      else if(data == 'c')
      {
        backward();
      }
      else if(data == 'b')
      {
        right();
      }
      else if(data == 'd')
      {
        left();
      }
      else if(data == 'g')
      {
        hold();
      }
   }
 }

Before you upload the code, Make sure that you disconnect the Tx and Rx wires of Arduino if not the code wont upload and the IDE will throw an error. Once the code is uploaded you can connect the Tx & Rx to module again and you are good to go.

You can download the code file from here.

Testing…

First power up the robot using batteries , I have used two separate batteries one for powering the arduino and another to power the motor shield. Make sure before you connect the batteries remove the jumper from the shield because if you don’t it may damage the arduino board.

Once the robot is powered up you will see the light on Bluetooth module blinking, Now open the BLEJoystick app. Click on the top right corner (Bluetooth Symbol).

BLR joystick app

Next you will list of Bluetooth addresses (For some reason it shows the same address multiple time ) Select the first one as that is the only one that works.

When you select the Bluetooth address you will notice that the blinking LED on module stops blinking and is solid on, That indicates connection is established now you can start using the controller to control the robot.

Video:

Video Demo

That’s all for this tutorial. If you have any questions or face any difficulty , feel free to ask in the comments.
If you are into robotics and want to get started, Check out my eBook “Mini WiFi Robot” which covers everything form CAD modeling to Programming.