BLUETOOTH CONTROLLED ROBOT CAR USING ARDUINO

In this we will see how to take input from the user and how to use Bluetooth controlled robot car using arduino according to the instructions received.

In this we provide 5 instructions to the robot to move, forward (f), backward (b), right turn (r), left turn (l) and stop (s).

REQUIRED HARDWARE

S.N.ComponentQuantity
1. Arduino UNO1
2. Bluetooth HC05 / HC061
3. DC motor 5V2
4.L293D IC or Module1
5. Jumper Wires30 (approx)

CIRCUIT DIAGRAM

BLUETOOTH CONTROLLED ROBOT CAR
Click to Zoom

CONNECTION TABLE

S.N. Arduino HC-05
1. + 5V + 5V
2. GND GND
3. Rx Tx
4. Tx Rx
S.N. Arduino L293D
1. Pin 6 IN4 (IC Pin 15)
2. Pin 7 IN3 (IC Pin 10)
3. Pin 8 IN2 (IC Pin 7)
4. Pin 9 IN1 (IC Pin 2)
5. + 5V EN1, EN2, VSS, VS (Pin 1,9,16,8)
6. GND GND (Pin 4,5,12,13)
S.N. L293D Motor
1. OUT 1 (Pin 3) Motor 1 Pin 1
2. OUT 2 (Pin 6) Motor 1 Pin 2
3. OUT 3 (Pin 11) Motor 2 Pin 1
4. OUT 4 (Pin 14) Motor 2 Pin 2

WORKING

  1. Download “robo car app” and make a connection with Android  App.
  2. After successful Bluetooth connection made with mobile app
  3. Then set values for forward, backward, right and left buttons, same as you used in arduino code. For example, f for forward.
  4. Now the user will click over the forward button OR can send instruction ‘f’, using the Serial text box, which will be received by microcontroller and to call forward function f(). This will move robotic car in the forward direction. Once you release finger from the forward button in the app, motors will stop
  5. If you are using any other app then you need to send ‘s’ or any character to stop.
  6. Users can also send  ‘b’ to move car in reverse / backward direction, ‘r’ for right direction and ‘l’ for left direction.

BLUETOOTH CONTROLLED ROBOT CAR USING ARDUINO

/* For Tutorial Click link: https://pijaeducation.com/arduino/bluetooth/bluetooth-controlled-robot-car-using-arduino/
 * Download android app: https://pijaeducation.com/download/
 */
int L1 = 9, L2 = 8, R1 = 7, R2 = 6;
void setup() {
  Serial.begin(9600);
  pinMode(R1, OUTPUT);
  pinMode(R2, OUTPUT);
  pinMode(L1, OUTPUT);
  pinMode(L2, OUTPUT);
}

void loop() {
  if (Serial.available() > 0) {
    char c = Serial.read();
    Serial.print("INPUT : ");
    Serial.println(c);
    if (c == 'f') {
      Serial.println("FORWARD");
      f();
    }
    else if (c == 'b') {
      Serial.println("BACKWARD");
      b();
    }
    else if (c == 'r') {
      Serial.println("RIGHT");
      r();
    }
    else if (c == 'l') {
      Serial.println("LEFT");
      l();
    }
    else {
      Serial.println("Default");
      s();
    }

  } // END OF SERIAL AVAILABLE
} // END OF LOOP

void f() {
  digitalWrite(L1, HIGH);
  digitalWrite(L2, LOW);
  digitalWrite(R1, HIGH);
  digitalWrite(R2, LOW);
}
void b() {
  digitalWrite(L1, LOW);
  digitalWrite(L2, HIGH);
  digitalWrite(R1, LOW);
  digitalWrite(R2, HIGH);
}
void l() {
  digitalWrite(L1, LOW);
  digitalWrite(L2, LOW);
  digitalWrite(R1, HIGH);
  digitalWrite(R2, LOW);
}
void r() {
  digitalWrite(L1, HIGH);
  digitalWrite(L2, LOW);
  digitalWrite(R1, LOW);
  digitalWrite(R2, LOW);
}
void s() {
  digitalWrite(L1, LOW);
  digitalWrite(L2, LOW);
  digitalWrite(R1, LOW);
  digitalWrite(R2, LOW);
}

OUTPUT

In this we receive data in character form using the function Serial.read(), you can use Serial.readString() if you like to receive String.

When we send character ‘f’ as an input it calls forward function f(), and moves forward as you  release the forward key then motors stop moving.

You can send ‘b’ calls backward function b(), ‘r’ calls right function r() and ‘l’ call left function l().

Once you installed the app (download app) & connect your phone with Bluetooth HC05 or HC06 and set data you want to send from the app. Then click forward, backward, right, left arrows to run motors or robot car.

Bluetooth Robot control
Click to zoom

 


READ NEXT
BLUETOOTH AT COMMANDS
To change internal settings like Bluetooth Name, Password and more.


 

Total Visits: 3161
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x