A feature-rich RC car built with ESP32, controlled via PS4 DualShock controller over Bluetooth. Includes advanced lighting system, trip computer, battery monitoring, and real-time telemetry.
- Hardware Specifications
- Functional Features
- Wiring Diagram
- Software Architecture
- Building and Uploading
- Controls
- Display System
- Troubleshooting
- Development
- Microcontroller: ESP32-WROOM-32 Development Board
- Motors: 2ร DC Geared Motors with Quadrature Encoders (3638 counts/rev)
- Motor Driver: L298N-compatible Dual H-Bridge
- Servo: Standard servo motor for steering (controlled via PCA9685)
- Display: 128ร64 SSD1306 OLED (I2C)
- PWM Driver: PCA9685 16-Channel PWM Driver (I2C)
- Battery: Conrad Energy 20C 3700mAh 7.4V LiPo
- Lighting: 8ร LEDs (4ร White headlights, 4ร Red tail lights)
- Idle: ~360mA
- Normal Driving: ~1.75A
- Aggressive Driving: ~2.55A
- Battery Life: 1.5-2+ hours continuous driving
- Wheel Circumference: 0.2199m (calibrated)
- Encoder Resolution: 3638 counts per revolution
- Servo Range: 50ยฐ-130ยฐ (mechanically limited)
- Maximum Speed: Variable (PID controlled)
- Wireless Control: PS4 DualShock controller via Bluetooth HID
- Auto-reconnection: Automatic connection recovery
- Safety Systems: Motor stop on connection loss
- Connection Health Monitoring: Real-time connection status
- Differential Drive: Independent left/right motor control
- PID Motor Control: Precise speed regulation
- Encoder Feedback: Real-time speed and distance measurement
- Multiple Drive Modes: Normal, High-speed, Direct control, Diagnostics
- 4-Pin Independent Control: Separate left/right headlights and tail lights
- Automatic Turn Signals: Activated by steering input (ยฑ100 threshold)
- Brake Lights: Automatic activation on brake trigger (>50)
- Headlight Flashing: 2-second flash sequence (5Hz)
- Smart Priority System: Flashing โ Turn Signals โ Brake Lights โ Normal
- 4-Page Navigation: Total ODO, Trip 1, Trip 2, Current Trip
- Persistent Storage: NVS-based odometry storage
- Distance Formatting: Automatic m/km conversion
- Trip Reset: Hold D-pad DOWN for 3 seconds
- Circular Navigation: D-pad LEFT/RIGHT page switching
- Real-time Monitoring: ADC-based voltage measurement
- Voltage Divider: 4:1 ratio (3ร 10kฮฉ resistors)
- Percentage Display: 6.4V-8.8V range mapping
- Filtered Readings: Stable battery percentage calculation
- Visual Indicator: Top-right corner percentage display
- Startup Screen: Battery%, Bluetooth status, Total ODO
- Trip Computer: 4-page odometry with navigation dots
- Status Icons: Bluetooth, LED status, turn signals
- Real-time Updates: 1-second refresh rate
GPIO 15 โ Left Headlights (2ร White LEDs + 220ฮฉ resistors)
GPIO 4 โ Right Headlights (2ร White LEDs + 220ฮฉ resistors)
GPIO 16 โ Left Tail Lights (2ร Red LEDs + 220ฮฉ resistors)
GPIO 17 โ Right Tail Lights (2ร Red LEDs + 220ฮฉ resistors)
GPIO 18 โ Left Motor PWM
GPIO 19 โ Left Motor INA
GPIO 13 โ Left Motor INB
GPIO 5 โ Right Motor PWM
GPIO 23 โ Right Motor INA
GPIO 12 โ Right Motor INB
GPIO 25 โ Left Encoder A
GPIO 26 โ Left Encoder B
GPIO 14 โ Right Encoder A
GPIO 27 โ Right Encoder B
GPIO 21 โ I2C SDA (OLED + PCA9685)
GPIO 22 โ I2C SCL (OLED + PCA9685)
GPIO 34 โ Battery Voltage (via 4:1 voltage divider)
- 0x3C: SSD1306 OLED Display
- 0x40: PCA9685 PWM Driver (Servo Channel 0)
- Main Power: 7.4V LiPo โ Motors, Servo
- Logic Power: ESP32 3.3V โ LEDs, Logic circuits
- Voltage Divider: 7.4V โ 1.85V (GPIO 34)
- Bluepad32 Framework: PS4 controller HID support
- FreeRTOS: Dual-core task management
- NVS Storage: Non-volatile odometry persistence
- I2C Communication: Multi-device bus management
- Main Loop: Controller input, lighting updates, display refresh
- Motor Control: PID-based speed regulation (50Hz)
- Encoder Reading: Interrupt-based quadrature decoding
- Battery Monitoring: 1Hz filtered voltage reading
- Watchdog Timer: System stability monitoring
- Connection Timeout: 2-second controller loss detection
- Motor Safety: Automatic stop on disconnection
- Servo Limiting: Mechanical binding prevention (50ยฐ-130ยฐ)
- PlatformIO (VS Code extension or CLI)
- Python 3.9+ with pip
- Git for version control
-
Clone Repository
git clone <repository-url> cd esp32-rc-car
-
Install PlatformIO
python3 -m pip install platformio
-
Build Firmware
python3 -m platformio run
-
Upload to ESP32
python3 -m platformio run --target upload
-
Monitor Serial Output
python3 -m platformio device monitor
- Platform: [email protected]
- Framework: Arduino with Bluepad32
- Board: ESP32 Dev Module
- Upload Speed: 921600 baud
- Monitor Speed: 115200 baud
lib_deps =
adafruit/Adafruit GFX Library@^1.11.9
adafruit/Adafruit SSD1306@^2.5.10
adafruit/Adafruit PWM Servo Driver Library@^3.0.2
- Left Stick X: Steering (ยฑ511 range)
- Right Trigger (R2): Throttle (0-1023)
- Left Trigger (L2): Brake (0-1023)
- D-pad UP (tap): Toggle all lights ON/OFF
- D-pad UP (hold 1s): Flash headlights for 2 seconds
- Steering: Auto turn signals (ยฑ100 threshold)
- Brake Trigger: Auto brake lights (>50 threshold)
- D-pad LEFT/RIGHT: Navigate trip computer pages
- D-pad DOWN (hold 3s): Reset current trip
- X Button: High-speed mode override
- Square: Direct PWM motor test mode
- L1 + R1: Motor diagnostics mode
- L1 + R1 + Circle: Battery diagnostics
- Turn Signals: Activate when steering beyond ยฑ100
- Brake Lights: Activate when brake > 50
- Auto-reconnection: Attempts reconnection every 5 seconds
- Safety Stop: Motors stop immediately on connection loss
[BT][LED] [BATT%]
โโโโโโโโโโโโโโโโโโโโโโโ
โ Robot Logo โ
โ (Bitmap) โ
โโโโโโโโโโโโโโโโโโโโโโโ
ODO: 123.4m
[BT][LED] [BATT%]
Page Title
โโโโโโโโโโโโ
โ 123.4m โ
โโโโโโโโโโโโ
Footer Text (if any)
โโโโ (page dots)
- Bluetooth: Connected/Disconnected state
- LED Status:
- ๐ก Filled bulb: Lights ON
- ๐ก Hollow bulb: Lights OFF
- โ Left arrow: Left turn signal
- โบ Right arrow: Right turn signal
- Ensure PS4 controller is in pairing mode (hold Share + PS buttons)
- Check Bluetooth range (<10 meters)
- Restart ESP32 and try pairing again
- Verify Bluepad32 framework is correctly installed
- Check motor driver connections (PWM, INA, INB pins)
- Verify motor power supply (7.4V)
- Test with motor diagnostics mode (L1 + R1)
- Check encoder connections for feedback
- Verify GPIO pins are not input-only (avoid 34, 35, 36, 39)
- Check LED polarity (long leg to resistor)
- Test individual LEDs with multimeter
- Ensure 220ฮฉ current-limiting resistors are used
- Verify I2C connections (SDA=21, SCL=22)
- Check OLED I2C address (0x3C)
- Test I2C bus with scanner code
- Ensure 3.3V power supply to OLED
- Verify voltage divider (3ร 10kฮฉ resistors)
- Check ADC pin connection (GPIO 34)
- Test with multimeter: expect 1.85V for 7.4V battery
- Calibrate voltage constants if needed
- Battery Diagnostics: L1 + R1 + Circle
- Motor Tests: L1 + R1 (hold)
- Serial Monitor: 115200 baud for debug output
- Connection Status: Displayed on OLED
src/
โโโ main.cpp # Main application code
โโโ trip_computer.cpp # Odometry and navigation (integrated)
โโโ led_control.cpp # Lighting system (integrated)
โโโ motor_control.cpp # PID and motor drivers (integrated)
โโโ display.cpp # OLED graphics (integrated)
platformio.ini # Build configuration
CLAUDE.md # Development documentation
README.md # This file
// Motor Control
#define MAX_PWM 255
#define MIN_PWM 50
#define COUNTS_PER_REV 3638
#define WHEEL_CIRCUMFERENCE_M 0.2199f
// Battery Monitoring
const float batteryMaxVoltage = 8.8f;
const float batteryMinVoltage = 6.4f;
const float voltageDividerRatio = 4.0f;
// Servo Control
#define SERVO_CENTER 90
#define SERVO_MAX_LEFT 130
#define SERVO_MAX_RIGHT 50
- Update pin definitions in main.cpp header
- Add initialization code in setup()
- Implement control logic in processGamepad()
- Update display in displayTripComputer() or displayStartupScreen()
- Test thoroughly with serial monitor output
- RAM Usage: 27.1% (88,660 bytes)
- Flash Usage: 24.6% (774,165 bytes)
- Loop Frequency: ~50Hz (20ms cycle time)
- I2C Frequency: 400kHz (fast mode)
This project is open source. Feel free to modify and distribute according to your needs.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- Bluepad32 framework for PS4 controller support
- Adafruit libraries for hardware drivers
- PlatformIO for excellent ESP32 development environment
- ESP32 community for extensive documentation and examples
๐ Happy driving! Built with โค๏ธ and ESP32