ESP32-CAM RC Car

by vitorccsiqueira in Circuits > Arduino

10 Views, 0 Favorites, 0 Comments

ESP32-CAM RC Car

car_front_view_1.jpg
car_rear_view.jpg
car_board_view.jpg
car_front_view_2.jpg
ESP32-CAM Car - Front View
ESP32-CAM Car - Using Smartphone

Remote Controlled Car using ESP32-CAM board (Ai Thinker).

Supplies

  1. 01 - ESP32-CAM board
  2. 01 - Car Chassis (2WD or 4WD)
  3. 02 - DC Motors (3v - 6v)
  4. 01 - L298N Dual H-Bridge board
  5. 02 - White Leds
  6. 02 - 18650 batteries (3.7v - 4.2v)
  7. 01 - Battery support
  8. 01 - Electrolytic Capacitor 1000 μF (16v - 50v)
  9. 01 - (Optional) Antenna for ESP32-CAM board - improves video streaming and prevents lags
  10. 01 - (Optional) OV2640 ESP32 CAM (120 or 160 degree lens) - wide-angle capture

Note: in order to enable the external antenna, it is required to change resistor position in ESP32-CAM board see tutorial.

Schematics

Esp32CamRcCar_v3_bb.png

The schematics is using the L298N board because it is easier to build the connections, but you can also use other motor drivers such as L293D, L9110, DRV833 and TB6612FNG.

About Car Chassis

274774013-a79de4b0-ea64-42f6-b933-a801766820ab.png
274776787-6e92b8e4-c452-4b1f-b8ce-b5e51e591bed.png
274776238-ab262906-3d15-41b7-8fab-b9664d6263a4.png

Install VS Code With Platform IO Plugin

Screenshot from 2025-05-01 02-03-23.png

Download and install PlatformIO, a plugin for Microsoft Virtual Studio Code

It is a more robust IDE compared to Arduino IDE. It also allows us to easily create our own private libraries and use a more object oriented code.

Upload the Code

The project is hosted in Github at:

https://github.com/vitorccs/esp32cam-rc-car

Download the ZIP file containing the source code at:

https://github.com/vitorccs/esp32cam-rc-car/archive/refs/heads/master.zip

Once you open the project folder at VS Code with PlatformIO, it automatically downloads and install all library dependencies - much easier than Arduino IDE and risks free of downloading incorrect source or version (!)

Customization

The PINs can be customized in the main.cpp

#include <Arduino.h>
#include <WifiHandler.h>
#include <StreamServer.h>
#include <SocketServer.h>
#include <DCMotor.h>
#include <WebJoystickHandler.h>
#include <JoyCoords.h>
#include <Car.h>
#include <sensor.h>

// Replace with your network credentials
#define WIFI_SSID "YOUR_SSID"
#define WIFI_PWD "YOUR_PWD"
#define WIFI_AP_MODE false // Access Point mode (no internet connection)
#define JOYSTICK_DEBUG true
#define PIN_FRONT_LED 2
#define PIN_CAMERA_LED 4
#define PIN_M1_IN1 14
#define PIN_M1_IN2 15
#define PIN_M2_IN1 12
#define PIN_M2_IN2 13
#define MIN_MOTOR_SPEED 80 // (0 to 255)
#define FRAME_SIZE FRAMESIZE_VGA
#define JPEG_QUALITY 25 // (0 to 63) lower means higher quality


Fine-tuning customization can be done in the individual files like ServoMotor.h for servo motor angle

#ifndef DCMOTOR_H
#define DCMOTOR_H
#include <Arduino.h>

class DCMotor
{
public:
DCMotor(uint8_t pinIn1, uint8_t pinIn2);
void backward(uint8_t speed = 100);
void forward(uint8_t speed = 100);
void setMinAbsSpeed(uint8_t absSpeed);
void stop();

private:
uint8_t pinIn1;
uint8_t pinIn2;
uint8_t absSpeed = 0;
uint8_t maxAbsSpeed = 255;
uint8_t minAbsSpeed = 50;
uint8_t ignoreAbsSpeed = 30;

void setSpeed(uint8_t speed);
};
#endif


Control

283484274-ea42572a-f59b-4444-ae26-d2b4ac0d762e.png

The ESP32-CAM connects to your Wi-Fi network and provides a Web page containing a virtual joystick.

Note: In order to control your car remotely from your public internet IP address, you need to set up Port Forwarding in your home router for ports 80 (Web page), 81 (video streaming) and 82 (web socket/joystick commands).

Advices

Power Supply

I recommend to use high quality 18650 batteries (3.7v - 4.2v, 2200mAh, at least 2C of discharge rate).

Most people prefer to use different power sources for ESP32-CAM (3.3v or 5v) and Bridge driver (7.4 - 8.4v).

I prefer to have a single power source and thus a single power switch. However, it is recommended to use capacitor to filter the electrical noise created by the 02 DC motors.

Resources

Fritzing file

The eletronic schematic was created in the Fritzing software and can be downloaded at

  1. Esp32CamRcCar_v3.zip