Bluetooth RC Car

Bluetooth RC Car

This project is basically a remote-controlled car that is controllable via an application installed on a Bluetooth-equipped smartphone. Here's my version of a Bluetooth RC Car.

Bluetooth RC Car

Introduction

For this project, I used ShieldBot, which was originally a line-follower car with two DC motors driven with an L298D motor driver IC. However, the code for this project can be implemented in any Arduino-based car as long as the L298D controller is present.

The Bluetooth connection is made possible by the HC-05 module. For a more detailed tutorial on this module, read this Arduino bluetooth serial tutorial. Basically, the module replaces a serial cable that is normally used to send data to the Arduino.

For building the app, I used appinventor. There are plenty of options to build an app but I found this the easiest way. Note that this project requires an Android phone. For Bluetooth control using iOS devices, see Arduino BLE.

Schematic Diagram

Here's the schematic diagram for this project:

Arduino Bluetooth RC Car Schematic Diagram

The motors are controlled through the states of the pin IN1, IN2, IN3, IN4, ENA, and ENB. Basically, ENA and ENB enables or disable the left and right motors respectively while the other pins control which direction the car travels. It is also possible to control how fast the car is traveling by applying pulses, instead of constant voltage, to ENA and ENB.

IN1 and IN2 are connected to my left motor on my circuit while IN3 and IN4 are connected to my right motor. Here is a summary of the pin states and the movement of the car:

 

Arduino Sketch

#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(3, 2); // RX, TX

int leftMotorIn = 8;
int leftMotorOut = 11;
int rightMotorIn = 12;
int rightMotorOut = 13;
int leftMotorEN = 9;
int rightMotorEN = 10;

int Data; // the data received
int lastData;

void setup() {
  Bluetooth.begin(9600);
  Serial.begin(9600);
  Serial.println("Waiting for command...");
  Bluetooth.println("Waiting for command");
  pinMode(leftMotorIn,OUTPUT);
  pinMode(leftMotorOut,OUTPUT);
  pinMode(rightMotorIn,OUTPUT);
  pinMode(rightMotorOut,OUTPUT);
  pinMode(leftMotorEN,OUTPUT);
  pinMode(rightMotorEN,OUTPUT);  

}

void loop() {
  if (Bluetooth.available()){ //wait for data received
    Data=Bluetooth.read();
    
    if(Data=='f'){  
      moveForward();
      Serial.println("Move forward!");
      Bluetooth.println("Move forward!");
    }
    else if(Data=='l'){  
      moveLeft();
      Serial.println("Move forward!");
      Bluetooth.println("Move forward!");
    }
    else if(Data=='r'){  
      moveRight();
      Serial.println("Move forward!");
      Bluetooth.println("Move forward!");
    }
    else if(Data=='b'){
       moveBackward();
       Serial.println("Move backward!");
       Bluetooth.println("Move backward!");
    }
    else if(Data=='s'){
       stopMoving();
       Serial.println("Stopped!");
       Bluetooth.println("Stopped!");
    }
    else{;}
  }
delay(100);
}

void moveForward(){
  analogWrite(leftMotorEN, 100);
  analogWrite(rightMotorEN, 100);
  digitalWrite(leftMotorIn, HIGH);
  digitalWrite(leftMotorOut, LOW);
  digitalWrite(rightMotorIn, HIGH);
  digitalWrite(rightMotorOut, LOW);
}

void moveBackward(){
  analogWrite(leftMotorEN, 100);
  analogWrite(rightMotorEN, 100);
  digitalWrite(leftMotorIn, LOW);
  digitalWrite(leftMotorOut, HIGH);
  digitalWrite(rightMotorIn, LOW);
  digitalWrite(rightMotorOut, HIGH);
}

void moveLeft(){
  analogWrite(leftMotorEN, 50);
  analogWrite(rightMotorEN, 10);
  digitalWrite(leftMotorIn, HIGH);
  digitalWrite(leftMotorOut, LOW);
  digitalWrite(rightMotorIn, LOW);
  digitalWrite(rightMotorOut, HIGH);
  delay(500);
}

void moveRight(){
  analogWrite(leftMotorEN, 10);
  analogWrite(rightMotorEN, 50);
  digitalWrite(leftMotorIn, LOW);
  digitalWrite(leftMotorOut, HIGH);
  digitalWrite(rightMotorIn, HIGH);
  digitalWrite(rightMotorOut, LOW);
  delay(500);
}

void stopMoving(){
  analogWrite(leftMotorEN, 0);
  analogWrite(rightMotorEN, 0);
  digitalWrite(leftMotorIn, HIGH);
  digitalWrite(leftMotorOut, HIGH);
  digitalWrite(rightMotorIn, HIGH);
  digitalWrite(rightMotorOut, HIGH);
}

The sketch is straightforward; the commands from the HC-05 are read serially and interpreted. The motors are then controlled following the table shown above.

See wireless controller for Bluetooth-based controller for this car.

 

 

Leave a Reply

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