Bluetooth Control Car

Introduction

Robots are always a fancy topic for students, hobbyists and DIYers. If you are beginner, then building a robot (like a car or an arm) is probably one of the important projects to do after learning about the basics.  
If you remember the earlier tutorial, I have discussed about HC-05 Bluetooth Module and how to interface one with Arduino. Also, I have provided a simple Bluetooth Controller App, which can be installed on your Android Phone and start transmitting the data.
As a continuation to that project, I will be implementing Bluetooth Controlled Robot using Arduino and a few other components and build a simple robotic car that can be controlled using an Android Phone (through an App) over Bluetooth Communication.

Circuit Design

I wouldn’t go into the details of the construction of the robot as your robot chassis might be different from mine and you can easily figure it out how to build the robot from the available parts and possible cable management for making the robot more appealing.
Coming to the design of the circuit, first is the HC-05 Bluetooth Module. The +5V and GND pins of the Bluetooth Module are connected to +5V and GND of Arduino.
Since I will be only transmitting data related to the Robot’s movement from Android Phone to Bluetooth Module and do not intend to receive any data from Arduino, I will connect only the TX pin of the Bluetooth Module to RX Pin of Arduino.
This RX pin of Arduino is based on SoftwareSerial library (Pin 2 and Pin 3 are configured as RX and TX on Arduino). The RX pin of the Bluetooth is left open.




PHOTO





Code

The Arduino code for Bluetooth Controlled Robot project is given below.
//prateek
#include
#define IN1 12
#define IN2 11
#define IN3 10
#define IN4 9
//#define EN1 6
//#define EN2 5

SoftwareSerial mySerial(2, 3); // RX, TX

String data;
int btVal;

void setup() 
{  
  //Serial.begin(115200);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  //pinMode(EN1, OUTPUT);
  //pinMode(EN2, OUTPUT);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
  //analogWrite(EN1,63);
  //analogWrite(EN2,63);
  mySerial.begin(9600);
}

void loop()
{
 while (mySerial.available())
 {  
  {  
      data = mySerial.readStringUntil('\n');
      //Serial.print(str);             
  } 
    
    btVal = (data.toInt());
    //Serial.print("BlueTooth Value ");
    //Serial.println(btVal);    



  switch (btVal) 
   {
      case 1:                                
        //Serial.println("Forward");
        forward();
        break;

      case 2:                 
       //Serial.println("Reverse");
        reverse();
        break;

      case 3:         
       //Serial.println("Left");
        left();
        break;
        
      case 4:                     
        //Serial.println("Right");
        right();
        break;
        
      case 5:                                            
        //Serial.println("Stop");
        stoprobot();
        break;      

  }

 } 

                                                              
   if (mySerial.available() < 0)                              
    {
     //Serial.println("No Bluetooth Data ");          
    }
  
}

void forward()
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

void reverse()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

void left()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

void right()
{
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}

void stoprobot()
{
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}

Android App

If you remember the HC-05 Bluetooth Module tutorial, I have used a simple app called Bluetooth Controller, which is installed on an Android Phone to communicate with the Bluetooth Module.

Working

Assemble the robot, make the necessary connections and upload the code to Arduino. If you understood the HC-05 Bluetooth Module tutorial, then understanding the Bluetooth Controlled Robot project is very easy.

Applications

  • Low range Mobile Surveillance Devices
  • Military Applications (no human intervention)
  • Assistive devices (like wheelchairs)
  • Home automation

0 Comments