PlatformIO test codebase for controlling a DC Geared Mini Motor (N20 6V 100RPM) using an ESP32 Mini C3 microcontroller and a DRV8871 H-Bridge motor driver powered by a 12V power supply.
| Component Pin | Connects To | Notes |
|---|---|---|
| DRV8871 IN1 | ESP32-C3 GPIO 4 | PWM Control Pin 1 |
| DRV8871 IN2 | ESP32-C3 GPIO 5 | PWM Control Pin 2 |
| DRV8871 GND | ESP32-C3 GND & 12V PSU GND | Common Ground (Mandatory!) |
| DRV8871 VM | +12V Power Supply | Driver Power Input (6.5V - 45V) |
| DRV8871 OUT1 | Motor Terminal 1 | N20 Motor Output |
| DRV8871 OUT2 | Motor Terminal 2 | N20 Motor Output |
| ESP32-C3 5V/VBUS | 5V Power / USB | Power ESP32 via USB or step-down buck |
Warning
Motor Protection Guard (12V Supply with 6V Motor): The N20 mini motor is rated for 6V, while the main power supply is 12V. The code automatically limits the maximum PWM duty cycle to 50% (128/255). This provides an effective average output voltage of ~6V across the motor terminals to prevent winding burn-out or gear overheating.
Open terminal in the root directory of this project and run:
pio runConnect your ESP32 Mini C3 via USB and run:
pio run -t uploadLaunch the serial monitor at 115200 baud:
pio device monitorOnce the monitor is running, type commands into the terminal and press Enter:
| Command | Action |
|---|---|
f or F |
Drive motor FORWARD at configured speed percentage |
r or R |
Drive motor REVERSE at configured speed percentage |
s or S |
STOP (Coast / Float mode) |
b or B |
BRAKE (Fast decay mode) |
0 - 100 |
Set speed percentage (e.g. 75 sets speed to 75% of max safe 6V level) |
t or T |
Run automated RAMP SWEEP test sequence |
h or ? |
Display Help Menu |