• Sun. Oct 24th, 2021
    • Introduction:
    • In this project, I will show you how to design and develop a Bluetooth Controlled Robot using Arduino, HC-05 Bluetooth Module and L298N Motor Driver Module. On the other end of the Bluetooth Communication, I will be using a Smart Phone and a simple Android App to control the Robotic Car.

    Robots are always a fancy topic for students. 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.

    • Materials:
      • Arduino UNO
      • L298N Motor Driver Module
      • HC-05 Bluetooth Module
      • Robot Chassis
      • 4x5v Geared Motors
      • Connecting Wires
      • Battery Holder
      • Power Supply
      • Android Phone
      • Bluetooth Controller App
    • Note: I have used L298N Motor Driver Module to drive the motors of the robot. You can use either this one or L293D Motor Driver Module. If you are using L293D, then check out for the connections.
    • How To Make:

    Circuit Diagram

      • We 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 we 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, We 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.
      • Now, the L298N Motor Driver Module. Digital I/O Pins 9 through 12 of Arduino are configured as Input pins of the Motor Driver and are connected to IN1 through IN4 of the L298N Motor Driver Module. Both the Enable Pins are connected to 5V through provided jumper.
      • The robot chassis which We are using in this Bluetooth Controlled Robot Car project is supplied with 4 geared motors. Since L298N has slots for only two motors, we have joined the left side motors as one set and the right side motors as other set and connected both these sets to the output of L298N Module.

    Code

    #include<SoftwareSerial.h>
    #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

      • We are using a simple Android App called “Bluetooth Controller” for pairing HC-05 with my Android Phone and transmitting data. At the time of developing this project, this particular Bluetooth Controller App is no longer available in the Play Store.
      • Make the connections and power on the Bluetooth Module. If this is the first time you are using your Bluetooth Module, then the LED will blink rapidly. In order to pair the module with your phone, open Bluetooth Settings in your phone and connect to “HC-05” with pin “1234”. If 1234 doesn’t work, try “0000”.
      • Once the Bluetooth Module is paired with your phone, you can start using the App. Open the Bluetooth Controller App and click on scan. A list of Bluetooth Devices will appear on the screen. Select HC-05.
    • Working
      • Assemble the robot, make the necessary connections and upload the code to Arduino.
      • First, in the Android App, I have used 5 keys as Forward, Reverse, Left, Right and Stop. The corresponding data associated with each key is as follows:
        • Forward – 1
        • Reverse – 2
        • Left – 3
        • Right – 4
        • Stop – 5
      • When a key is pressed, the corresponding data is transmitted to the Bluetooth Module from the Phone over Bluetooth Communication.
      • In the Arduino code, the Arduino UNO receives any of this data from the Bluetooth Module (as per the key pressed) and performs a simple switch case operation, where each case associated with appropriate instructions to the Motor Driver Input Pins.
      • For example, if ‘Forward’ key is pressed in the Android Phone, then ‘1’ is transmitted. Arduino will then make IN1 and IN3 as HIGH and IN2 and IN4 as LOW to achieve a forward motion.
    • Limitations:
      • As the range of the Bluetooth Communication is limited (a maximum of 10 meters for class 2 devices for example) the control range of Bluetooth Controlled Robot is also limited.
      • Make sure that sufficient power is provided to all the modules especially the Bluetooth Module. If the power is not sufficient, even though the Bluetooth Module powers on, it cannot transmit data or cannot be paired with other Bluetooth devices.

    And Here You Go…..

    Leave a Reply

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