Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32-WROOM-32UE Bluetooth-Controlled Robotic Car with L298N Motor Driver

View and Edit Project In Cirkit DesignerImage of ESP32-WROOM-32UE Bluetooth-Controlled Robotic Car with L298N Motor Driver

Circuit Documentation

Summary

This circuit is designed to control a remote-controlled car with two DC gearmotors for movement and a servo motor for steering. The ESP32-WROOM-32UE microcontroller is used as the central processing unit, interfacing with a Bluetooth module for remote commands and driving the motors through an L298N DC motor driver. The system is powered by a lipo battery.

Component List

ESP32-WROOM-32UE

L298N DC Motor Driver

Servomotor MG90S

Lipo Battery 2200mAh 30C

Gearmotor DC Wheels Right

Gearmotor DC Wheels Left

Wiring Details

ESP32-WROOM-32UE

L298N DC Motor Driver

Servomotor MG90S

Lipo Battery 2200mAh 30C

Gearmotors DC Wheels (Right and Left)

Documented Code

#include <BluetoothSerial.h>
#include <Servo.h>

BluetoothSerial SerialBT;
Servo steeringServo;

const int motorPin1 = 19;
const int motorPin2 = 18;
const int motorPin3 = 5;
const int motorPin4 = 17;
const int enablePinA = 22;
const int enablePinB = 15;
const int steeringPin = 2;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32_RC_Car"); // Bluetooth device name

  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(enablePinA, OUTPUT);
  pinMode(enablePinB, OUTPUT);

  steeringServo.attach(steeringPin);
}

void loop() {
  if (SerialBT.available()) {
    char command = SerialBT.read();
    handleCommand(command);
  }
}

void handleCommand(char command) {
  switch (command) {
    case 'F': // Move forward
      digitalWrite(motorPin1, HIGH);
      digitalWrite(motorPin2, LOW);
      digitalWrite(motorPin3, HIGH);
      digitalWrite(motorPin4, LOW);
      analogWrite(enablePinA, 255);
      analogWrite(enablePinB, 255);
      break;
    case 'B': // Move backward
      digitalWrite(motorPin1, LOW);
      digitalWrite(motorPin2, HIGH);
      digitalWrite(motorPin3, LOW);
      digitalWrite(motorPin4, HIGH);
      analogWrite(enablePinA, 255);
      analogWrite(enablePinB, 255);
      break;
    case 'L': // Turn left
      steeringServo.write(45);
      break;
    case 'R': // Turn right
      steeringServo.write(135);
      break;
    case 'S': // Stop
      digitalWrite(motorPin1, LOW);
      digitalWrite(motorPin2, LOW);
      digitalWrite(motorPin3, LOW);
      digitalWrite(motorPin4, LOW);
      analogWrite(enablePinA, 0);
      analogWrite(enablePinB, 0);
      break;
    default:
      break;
  }
}

This code is responsible for setting up the ESP32 microcontroller to control the motors and servo via Bluetooth commands. It initializes the motor and servo pins, sets up Bluetooth communication, and defines the handleCommand function to interpret the received commands to control the vehicle's movement.