Bluetooth controlled robot car Using Arduino

In this we will see how to take strings from user and Bluetooth controlled robot car using arduino according to the instruction received. In this we are providing three instructions to robot

  1. First one is to move forward
  2. Second one is to move reverse
  3. Third one to stop or hold the robot

BLUETOOTH CONTROLLED ROBOT CAR USING ARDUINO

#define del 2000

// Set pin number
int motor1Pin1 = 8;
int motor1Pin2 = 9;
int motor2Pin1 = 6;
int motor2Pin2 = 7;

String input_string;

void setup() {
  // Set the pins as output
  pinMode(motor1Pin1, OUTPUT);
  pinMode(motor1Pin2, OUTPUT);
  pinMode(motor2Pin1, OUTPUT);
  pinMode(motor2Pin2, OUTPUT);

  // Initialize serial communication at 9600 bits per second
  Serial.begin(9600);
}

void loop() {
  // To check if data is available on Serial port
  if (Serial.available() > 0) {
    // To read a data from HC05 via serial communication protocol
    input_string = Serial.readString();
   
    if (input_string == "forward") {
      forward();
    }
    else if (input_string == "reverse") {
      reverse();
    }
    else if (input_string == "hold") {
      hold();
    }
  }

}

void forward() {
  digitalWrite(motor1Pin1, HIGH);
  digitalWrite(motor1Pin2, LOW);
  digitalWrite(motor2Pin1, HIGH);
  digitalWrite(motor2Pin2, HIGH);
  Serial.println("Forward! status");
  delay(del);
  hold();
}

void reverse() {
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin1, LOW);
  digitalWrite(motor2Pin2, HIGH);
  Serial.println("Reverse! status");
  delay(del);
  hold();
}

void hold() {
  digitalWrite(motor1Pin1, LOW);
  digitalWrite(motor1Pin2, HIGH);
  digitalWrite(motor2Pin1, LOW);
  digitalWrite(motor2Pin2, HIGH);
  Serial.println("stop! status");
}     

CIRCUIT DIAGRAM

BLUETOOTH CONTROLLED ROBOT CAR

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 (Pin 15)
2. Pin 7 IN3 (Pin 10)
3. Pin 8 IN2 (Pin 7)
4. Pin 9 IN1 (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. After successful connection made with mobile phone
  2. User will send instruction in the form of string like “forward”, which is then received by microcontroller and check it in If condition and call function made by us forward(), this will move robotic car in forward direction and after a delay of 2000 millisecond we call another function hold so that it will not stuck with the boundary
  3. You can change the value of delay
  4. Or you can remove hold and delay function and left for user to send “hold” as a string to stop
  5. User can also send string “reverse” to move car in reverse direction.

OUTPUT

In this we can send data in String form using function Serial.readString(). When we send “forward” as a string it calls forward function and moves forward then automatically stops the motors by calling hold function & when we send “reverse” as a string it calls reverse function and moves backward then automatically stops the motors by calling hold function.

output Robot control

Leave a Reply

avatar
  Subscribe  
Notify of

Arduino Tutorials with Basic Electronics: CONTENT

Translate »