Arduino ESP32 Bluetooth RC CAR

This post is about making an RC car using the NodeMCU ESP32. Unlike an Arduino development board, the ESP32 is easier to use for this project because it has built-in Bluetooth and Wi-Fi, so you don’t need an external Bluetooth module. Let’s get started!

ESP32 RC CAR

This project is a great way for kids and young enthusiasts to learn how to use Bluetooth with the ESP32 microcontroller. In 2024, we’ll complete this full RC car project, which also covers learning about H-bridge circuits using the L298N motor driver. To build the RC car, you’ll need a few key components, and I’ll include purchase links for Sri Lanka. If you’re from another country, you can find similar components on sites like AliExpress.

first, we need these components

  1. Nodemcu ESP32-Buy here
  2. Gear Motors-Buy here
  3. Wheels -Buy here
  4. L298 Motor driver-Buy here
  5. Battery Case x2 - Buy here
  6. Battery 3.7v - Buy here

making an RC CAR

Start by using a board as the chassis for your car—it can be plastic, cardboard, or any sturdy material. Then, place two yellow gear motors side by side, just like in a real car. Attach a caster wheel under the car at the front center of the chassis for stability. You can position the motor driver and battery wherever it best fits your design.

ESP32 RC CAR assemble

Here’s the wiring diagram for the circuit. Be careful when connecting the power wires to avoid any short circuits. If the motors turn in the wrong direction, simply switch the motor wires to correct it. It's also a good idea to add a switch to control the power of the Bluetooth car. When connecting the USB cable to your laptop, make sure the RC car is already powered by its battery; otherwise, it may try to draw power from the USB port, which could damage your port.

ESP32 Bluetooth Car Wiring diagrams

You don’t need to use a breadboard for this project; you can simply connect the ESP32 using jumper wires or by soldering the connections directly.

esp32 car

To power up your RC car, you'll need a 8V power supply to ensure proper operation. Once everything is set up, the next step is programming the ESP32 microcontroller. For this, you will use the Arduino IDE. Simply plug in the USB cable, select the correct COM port that the ESP32 is connected to, and then download the necessary code and libraries. Make sure all dependencies are installed, and once you're ready, proceed with uploading the code to the ESP32. This process will allow you to control your RC car through Bluetooth, bringing your project to life.

Keep in mind that ESP32 programming requires a well-configured environment within the Arduino IDE, including selecting the correct board model under the "Tools" menu.


Arduino Full code   

#include 

BluetoothSerial SerialBT;

#define LEFT_MOTOR_PIN1    27
#define LEFT_MOTOR_PIN2    26
#define RIGHT_MOTOR_PIN1   32
#define RIGHT_MOTOR_PIN2   33
#define LIGHT_PIN          2

 int MOTOR_SPEED = 200;   //  speed

void setup() {
  Serial.begin(115200);
  SerialBT.begin("RC-CAR"); // Bluetooth device name
 
  pinMode(LEFT_MOTOR_PIN1, OUTPUT);
  pinMode(LEFT_MOTOR_PIN2, OUTPUT);
  pinMode(RIGHT_MOTOR_PIN1, OUTPUT);
  pinMode(RIGHT_MOTOR_PIN2, OUTPUT);

  pinMode(LIGHT_PIN,OUTPUT);
}

void loop() {
  if (SerialBT.available()) {
    char command = SerialBT.read();
    Serial.println(command);

    switch (command) {
      case 'F':
        moveForward();
        break;
      case 'B':
        moveBackward();
        break;
      case 'L':
        turnLeft();
        break;
      case 'R':
        turnRight();
        break;
      case 'S':
        stop();
        break;
      case 'W':
        lights(true);
        break;
        case 'w':
       lights(false);
        break;
      case '0':
        MOTOR_SPEED = 100;
        break;
      case '1':
        MOTOR_SPEED = 140;
        break;
      case '2':
        MOTOR_SPEED = 153;
        break;
      case '3':
        MOTOR_SPEED = 165;
        break;
      case '4':
        MOTOR_SPEED = 178;
        break;
      case '5':
        MOTOR_SPEED = 191;
        break;
      case '6':
        MOTOR_SPEED = 204;
        break;
      case '7':
        MOTOR_SPEED = 216;
        break;
      case '8':
        MOTOR_SPEED = 229;
        break;
      case '9':
        MOTOR_SPEED = 242;
        break;
      case 'q':
        MOTOR_SPEED = 255;
        break;
      default:
        stop();
        break;
    }

  }

}


void moveForward() {
  analogWrite(LEFT_MOTOR_PIN1, MOTOR_SPEED);
  analogWrite(LEFT_MOTOR_PIN2, 0);
  analogWrite(RIGHT_MOTOR_PIN1, MOTOR_SPEED);
  analogWrite(RIGHT_MOTOR_PIN2, 0);
}

void moveBackward() {
  analogWrite(LEFT_MOTOR_PIN1, 0);
  analogWrite(LEFT_MOTOR_PIN2, MOTOR_SPEED);
  analogWrite(RIGHT_MOTOR_PIN1, 0);
  analogWrite(RIGHT_MOTOR_PIN2, MOTOR_SPEED);
}

void turnLeft() {
  analogWrite(LEFT_MOTOR_PIN1, 0);
  analogWrite(LEFT_MOTOR_PIN2, MOTOR_SPEED);
  analogWrite(RIGHT_MOTOR_PIN1, MOTOR_SPEED);
  analogWrite(RIGHT_MOTOR_PIN2, 0);
}

void turnRight() {
  analogWrite(LEFT_MOTOR_PIN1, MOTOR_SPEED);
  analogWrite(LEFT_MOTOR_PIN2, 0);
  analogWrite(RIGHT_MOTOR_PIN1, 0);
  analogWrite(RIGHT_MOTOR_PIN2, MOTOR_SPEED);
}

void stop() {
  analogWrite(LEFT_MOTOR_PIN1, 0);
  analogWrite(LEFT_MOTOR_PIN2, 0);
  analogWrite(RIGHT_MOTOR_PIN1, 0);
  analogWrite(RIGHT_MOTOR_PIN2, 0);
}

void lights(bool st){
digitalWrite(LIGHT_PIN,st);
}

Once everything is set up, you're almost done! To control your Bluetooth RC car, you'll need a Bluetooth remote. You can either use a mobile phone app or another ESP32 to create a Bluetooth remote. In this post, I’ll provide some links to Android apps that can be used for this purpose. In the next lesson, we will focus on building the Bluetooth remote.

youtube video

1 Comments

Previous Post Next Post