Project tutorial
Smartphone-Controlled Robot Using BLE 4.0

Smartphone-Controlled Robot Using BLE 4.0 © CC BY-NC-SA

Learn how you can build a simple robot using an Arduino and a BLE module to control it.

  • 1,068 views
  • 0 comments
  • 6 respects

Components and supplies

Apps and online services

About this project

In previous tutorial I shared with you how you can use Bluetooth Module (specifically HM10 BLE v4.0) with Arduino to control LEDs using smartphone. You can check it out here. In this tutorial I will show you how to build a robot that can be controlled using smartphone via Bluetooth Low Energy. I Will try to keep it as simple as possible.

Step 1: Things You Will Need

So here I have provided name and details of all the components you will need along with the best buy links.

1. Electronic Components

  • Arduino UNO :- I have used UNO but you can use any other board like Mega if you want to give the robot extra features and require a lot of I/O pins or smaller Nano if you want a tiny compact bot. If you are a beginner I advice you to get the UNO cause it is more versatile and user friendly.
  • Arduino Motor Shield :- I have used L293D motor shield which is cheap and efficient for this project, But if you want you can opt. for a better version Motor shield L298N which is capable of handling Larger motors.
  • Bluetooth Module :- Here I used AT-09 module which is HM-10 compatible. You can go for HM-10 if you like. Even though this tutorial is basically for Bluetooth 4.0v, you can use HC-05 module too if you have that laying around.
  • Geared DC Motors :- The ones I used are cheap and will get the job done. but if you really want to go professional you can buy high torque motors from here.
  • Batteries :- 2 batteries will be needed for this project a 9v-12v battery for the motor driver and a 9v battery for the Arduino. Or else you can use a power bank to power it through USB
  • 2.2k ohm & 1k ohm resistors each.

2. Software Requirements

3. Hardware Requirements

Now hardware requirements differs on many aspects, Like if you want a 2 wheeled robot or a 4 wheeled one. Or maybe you want one with tracks like a Tank. So here I have provided links to few robot chassis which you can buy, or you can make one with objects you have laying around like cardboard / acrylic sheets.

I will use some parts laying around to make the body of the robot. Details in the next step.

Step 2: Making the Chassis

Here I have used a 5mm thick Sunboard for the base, drilled holes for the motor brackets and Arduino on the top. and assembled everything as shown in the pictures. I have made similar design in a previous tutorial you can check it out here it has more details about the design :- Simple & Smart Robot Using Arduino.

Instead of making one yourself you can also buy one which will be easier. Links I have already shared in the previous step.

This post is more about controlling the robot using BLE so lets get into it.

Step 3: Making Connections

First You have to connect the Bluetooth module to arduino like shown in the picture above.

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

Check out the previous intractable for more details.

I soldered two resistors together.

Then I placed their terminal in arduino pins. One terminal of the 2.2k ohm resistor goes to GND and one terminal of 1k ohm resistor goes to Tx (pin 1 of arduino). The point where the two resistors are connected goes to the Rx pin of Bluetooth module.

After that I placed the motor shield on top. If you want you can solder the wires directly to the shield but I was too lazy to solder so I went the easy way... ;p

Connect the motors to M1 and M2 of the Motor Shield

Step 4: Uploading Code

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.

Code file is provided below.

Step 5: Testing!

Video Demo

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), you will see a 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.

That is it for this tutorial, If you have any questions or face any difficulty, feel free to ask in the comments.

Thank you.

Code

BLE_robot.inoArduino
No preview (download only).
Code snippet #1Plain text
#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();
      }
   }
 }

Comments

Similar projects you might like

MeArm Robot Arm - Your Robot - V1.0

Project tutorial by Benjamin Gray

  • 19,308 views
  • 3 comments
  • 35 respects

BLE Robot Using Blynk & Arduino

Project tutorial by Tom Moxon

  • 2,336 views
  • 0 comments
  • 13 respects

Otto DIY+ Arduino Bluetooth Robot Easy to 3D Print

Project tutorial by Team Otto builders

  • 48,225 views
  • 117 comments
  • 162 respects

Bolt Controlled Robot Car

Project tutorial by Team Bolt

  • 1,508 views
  • 1 comment
  • 13 respects

Hand Gesture Controlled Robot

Project tutorial by Mayoogh Girish

  • 55,194 views
  • 78 comments
  • 65 respects

Voice Controlled Robot using your Smart Phone

Project tutorial by Ahmed Yassin

  • 3,059 views
  • 0 comments
  • 7 respects
Add projectSign up / Login