How to make a customizable Bluetooth controller car using Arduino

How to make a customizable Bluetooth controller car using Arduino

Hello, welcome back. In this tutorial, we will learn how to make a customizable Bluetooth controller car using Arduino. Also, this Bluetooth car is different from the other Bluetooth control cars. That is, we can change the shape of the car as we want. I used two servo motors for that. The other components are operating normally. A module called HC-05 is used for Bluetooth control. Also, the l293d motor driver shield has been used to control the motors. All of these are controlled using the Arduino UNO board. Keep reading.

The process of this Bluetooth control car

When powering on this car, The Bluetooth module activates and data communication begins. That is, data is communicated between the Bluetooth module and the mobile app. Then, the data is transmitted to the Arduino UNO board via serial communication. After, the Bluetooth control car moves according to that data. All these motors are controlled by using the L293D driver shield.

OK, let’s do this Bluetooth control car step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, let’s identify these components.

Step 2

Secondly, cut the car chassis using a foam board piece or cardboard piece. For that, use the following sizes.

Step 3

Thirdly, attach the gear motors to it.

Step 4

Then, connect the servo motors as follows.

Step 5

Now, connect the motor driver shield to the Arduino board. After that, attach it to the car chassis.

Step 6

Then, connect the gear motors and the servo motors to the motor driver shield. For that, use the circuit diagram below.

How to make a customizable Bluetooth controller car using Arduino

Step 7

Now, attach the Bluetooth module to the car chassis and connect it to the driver board. For that, use the circuit diagram above.

Step 8

Ok, now attach the wheels to the motors. After, glue the battery holder to the car chassis and connect it to the driver board.

Step 9

Then, connect this car to the computer. Now, let’s create the program. It is as follows.

How to make a customizable Bluetooth controller car using Arduino
  • The complete program of this project – download
/*How to make a Bluetooth control car
 * https://srituhobby.com
 */
 
#include <AFMotor.h>
#include <Servo.h>
#define Speed 150

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

Servo servo1;
Servo servo2;

void setup() {
  Serial.begin(9600);
  motor1.setSpeed(Speed);
  motor2.setSpeed(Speed);
  motor3.setSpeed(Speed);
  motor4.setSpeed(Speed);

  servo1.attach(9);
  servo2.attach(10);
  servo1.write(70);
  servo2.write(180 - 70);
}

void loop() {
  if (Serial.available() > 0) {
    char value = Serial.read();
    Serial.println(value);

    if (value == '1') {
      servo1.write(70);
      servo2.write(180 - 70);
    } else if (value == '2') {
      servo1.write(80);
      servo2.write(180 - 80);
    } else if (value == '3') {
      servo1.write(90);
      servo2.write(180 - 90);
    } else if (value == '4') {
      servo1.write(100);
      servo2.write(180 - 100);
    } else if (value == '5') {
      servo1.write(120);
      servo2.write(180 - 120);
    } else if (value == '6') {
      servo1.write(140);
      servo2.write(180 - 140);
    } else if (value == '7') {
      servo1.write(150);
      servo2.write(180 - 150);
    } else if (value == '8') {
      servo1.write(160);
      servo2.write(180 - 160);
    } else if (value == '9') {
      servo1.write(170);
      servo2.write(180 - 170);
    } else if (value == 'F') {
      forward();
    } else if (value == 'B') {
      backward();
    } else if (value == 'L') {
      left();
    } else if (value == 'R') {
      right();
    } else {
      Stop();
    }
  }
}

void forward() {
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
}
void backward() {
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
}
void left() {
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
}
void right() {
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
}
void Stop() {
  motor1.run(RELEASE);
  motor2.run(RELEASE);
  motor3.run(RELEASE);
  motor4.run(RELEASE);
}

Code explanation

Firstly, library files included. After, the motor speed defined.

#include <AFMotor.h>
#include <Servo.h>
#define Speed 150

Secondly, objects are created for the gear motors and the servo motors.

AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

Servo servo1;
Servo servo2;

In the setup function,

void setup() {
//The serial monitor begins
  Serial.begin(9600);
//Motor speed included
  motor1.setSpeed(Speed);
  motor2.setSpeed(Speed);
  motor3.setSpeed(Speed);
  motor4.setSpeed(Speed);
//Servo motor pins included
  servo1.attach(9);
  servo2.attach(10);
//Sets the servo motor starting position.These values depend on your servo motor horn positions
  servo1.write(70);
  servo2.write(180 - 70);
}

In the loop function,

void loop() {
//The serial communication checked
  if (Serial.available() > 0) {
//The serial communication values read
    char value = Serial.read();
//These values print on the serial monitor
    Serial.println(value);
//Those values checked using the IF condition
    if (value == '1') {
      servo1.write(70);
      servo2.write(180 - 70);
    } else if (value == '2') {
      servo1.write(80);
      servo2.write(180 - 80);
    } else if (value == '3') {
      servo1.write(90);
      servo2.write(180 - 90);
    } else if (value == '4') {
      servo1.write(100);
      servo2.write(180 - 100);
    } else if (value == '5') {
      servo1.write(120);
      servo2.write(180 - 120);
    } else if (value == '6') {
      servo1.write(140);
      servo2.write(180 - 140);
    } else if (value == '7') {
      servo1.write(150);
      servo2.write(180 - 150);
    } else if (value == '8') {
      servo1.write(160);
      servo2.write(180 - 160);
    } else if (value == '9') {
      servo1.write(170);
      servo2.write(180 - 170);
    } else if (value == 'F') {
      forward();
    } else if (value == 'B') {
      backward();
    } else if (value == 'L') {
      left();
    } else if (value == 'R') {
      right();
    } else {
      Stop();
    }
  }
}

These are motor control functions.

void forward() {
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
}
void backward() {
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
}
void left() {
  motor1.run(FORWARD);
  motor2.run(FORWARD);
  motor3.run(BACKWARD);
  motor4.run(BACKWARD);
}
void right() {
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);
  motor3.run(FORWARD);
  motor4.run(FORWARD);
}
void Stop() {
  motor1.run(RELEASE);
  motor2.run(RELEASE);
  motor3.run(RELEASE);
  motor4.run(RELEASE);
}

Step 10

Now, remove the RX and TX jumper wires. Then, select board and port. After, upload this code to the Arduino board.

Step 11

Now, reconnect the RX and TX jumper wires. Afterward, put the batteries in the battery holder and switch on this Bluetooth control car.

Step 12

Ok, now let’s set up the Bluetooth control app step by step. For that, follow the steps below.

  • First, download and install the app below.
  • Then, go to the Bluetooth settings and turns on the Bluetooth. After, select the Bluetooth module name and connect for it. For that use the “0000” or “1234” password.
  • Finally, open the Bluetooth control app and connect this app to the Bluetooth module.

OK, now you can control the car using this app. The full video guide is given below. So, we will meet in the next tutorial.

How to make a customizable Bluetooth controller car using Arduino

Similar Posts

Leave a Reply

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