Wi-Fi Controlled ESP32 RC Car with Servo and Ultrasonic Sensors
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a circuit designed using an ESP32 microcontroller, multiple DC motors, servos, an L298N motor driver, ultrasonic sensors, and power converters. The circuit is intended to control an RC car with Wi-Fi capabilities, allowing for motor and servo control via a web interface.
Component List
ESP32 (30 pin)
- Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
DC Motor
- Description: A standard DC motor.
- Pins: pin 1, pin 2
L298N DC Motor Driver
- Description: A dual H-Bridge motor driver that allows for control of two DC motors.
- Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB
Servo
- Description: A standard servo motor.
- Pins: gnd, vcc, pulse
12v to 5v Step Down Power Converter
- Description: A power converter that steps down 12V to 5V.
- Pins: VIN 9v-36v, VIN+, VIN-, USB OUTPUT 5V, 5v OUTPUT, GND
HC-SR04 Ultrasonic Sensor
- Description: An ultrasonic sensor used for distance measurement.
- Pins: VCC, TRIG, ECHO, GND
Battery 12v
- Description: A 12V battery.
- Pins: +, -
48v to 5v Converter
- Description: A power converter that steps down 48V to 5V.
- Pins: out+, out--, in+, in--
Wiring Details
ESP32 (30 pin)
- D32 connected to L298N DC motor driver IN3
- D33 connected to L298N DC motor driver IN4
- D26 connected to L298N DC motor driver IN1
- D27 connected to L298N DC motor driver IN2
- D14 connected to L298N DC motor driver IN3
- D12 connected to L298N DC motor driver IN4
- D13 connected to L298N DC motor driver IN1
- GND connected to 48v to 5v out--, 48v to 5v in--, 12v to 5v Step Down Power Converter VIN-, L298N DC motor driver GND, HC-SR04 Ultrasonic Sensor GND, battery 12v -
- Vin connected to 48v to 5v in+, 12v to 5v Step Down Power Converter VIN+, L298N DC motor driver 12V, battery 12v +
- D23 connected to HC-SR04 Ultrasonic Sensor ECHO
- D22 connected to HC-SR04 Ultrasonic Sensor TRIG
- D21 connected to HC-SR04 Ultrasonic Sensor ECHO
- D19 connected to HC-SR04 Ultrasonic Sensor TRIG
- D18 connected to Servo pulse
- D5 connected to Servo pulse
- D4 connected to Servo pulse
- D2 connected to Servo pulse
- D15 connected to L298N DC motor driver IN2
DC Motor
- pin 1 connected to L298N DC motor driver OUT3
- pin 2 connected to L298N DC motor driver OUT4
L298N DC Motor Driver
- OUT1 connected to DC Motor pin 1
- OUT2 connected to DC Motor pin 2
- OUT3 connected to DC Motor pin 1
- OUT4 connected to DC Motor pin 2
- GND connected to ESP32 GND, battery 12v -
- 12V connected to ESP32 Vin, battery 12v +
Servo
- gnd connected to 12v to 5v Step Down Power Converter 5v OUTPUT
- vcc connected to 12v to 5v Step Down Power Converter GND
- pulse connected to ESP32 D18, ESP32 D5, ESP32 D4, ESP32 D2
12v to 5v Step Down Power Converter
- VIN- connected to 48v to 5v out--, 48v to 5v in--, ESP32 GND, L298N DC motor driver GND, HC-SR04 Ultrasonic Sensor GND, battery 12v -
- VIN+ connected to 48v to 5v in+, ESP32 Vin, L298N DC motor driver 12V, battery 12v +
HC-SR04 Ultrasonic Sensor
- VCC connected to 48v to 5v out+
- TRIG connected to ESP32 D22, ESP32 D19
- ECHO connected to ESP32 D23, ESP32 D21
- GND connected to ESP32 GND, battery 12v -
Battery 12v
- + connected to ESP32 Vin, L298N DC motor driver 12V
- - connected to ESP32 GND, L298N DC motor driver GND
48v to 5v Converter
- out-- connected to ESP32 GND, L298N DC motor driver GND, HC-SR04 Ultrasonic Sensor GND, battery 12v -
- in-- connected to ESP32 GND, L298N DC motor driver GND, HC-SR04 Ultrasonic Sensor GND, battery 12v -
- in+ connected to ESP32 Vin, L298N DC motor driver 12V, battery 12v +
- out+ connected to HC-SR04 Ultrasonic Sensor VCC
Code Documentation
#include <WiFi.h>
#include <ESPAsyncWebServer.h>
#include <Servo.h>
// Motor pins (L298N Motor Driver)
const int motor1Pin1 = 26;
const int motor1Pin2 = 27;
const int motor2Pin1 = 14;
const int motor2Pin2 = 12;
const int motor3Pin1 = 13;
const int motor3Pin2 = 15;
const int motor4Pin1 = 32;
const int motor4Pin2 = 33;
// Servo pins
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
const int servo1Pin = 2;
const int servo2Pin = 4;
const int servo3Pin = 5;
const int servo4Pin = 18;
// Wi-Fi credentials
const char *ssid = "YOUR_SSID";
const char *password = "YOUR_PASSWORD";
// Server object
AsyncWebServer server(80);
// Function to stop all motors
void stopMotors() {
digitalWrite(motor1Pin1, LOW);
digitalWrite(motor1Pin2, LOW);
digitalWrite(motor2Pin1, LOW);
digitalWrite(motor2Pin2, LOW);
digitalWrite(motor3Pin1, LOW);
digitalWrite(motor3Pin2, LOW);
digitalWrite(motor4Pin1, LOW);
digitalWrite(motor4Pin2, LOW);
}
void setup() {
// Initialize Serial Monitor
Serial.begin(115200);
// Setup motor pins
pinMode(motor1Pin1, OUTPUT);
pinMode(motor1Pin2, OUTPUT);
pinMode(motor2Pin1, OUTPUT);
pinMode(motor2Pin2, OUTPUT);
pinMode(motor3Pin1, OUTPUT);
pinMode(motor3Pin2, OUTPUT);
pinMode(motor4Pin1, OUTPUT);
pinMode(motor4Pin2, OUTPUT);
// Attach servos
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
servo4.attach(servo4Pin);
// Connect to Wi-Fi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to Wi