ESP3230 minsDifficulty: BEGINNER
ESP32 Motor Control: PWM Generation & Optical Encoders
Learn how to configure the ESP32 MCPWM hardware peripheral for bidirectional H-bridge motor driving and attach hardware interrupts for precise wheel odometry.
Authored by KRS Electronics Team•Published 20 Aug 2026
# ESP32 Closed-Loop Motor Control
Precision robotic navigation begins at the actuator boundary. While open-loop PWM control commands power to a DC motor, friction and voltage fluctuations cause severe drift. Closed-loop PID velocity control using optical quadrature encoders is essential.
## 1. Hardware Pinout & Wiring
- Connect ESP32 GPIO 18 & 19 to your motor driver PWM inputs.
- Connect Encoder Channel A and B to GPIO 34 & 35 with pull-up resistors.
- Ensure common ground between the microcontroller logic and motor power rails.
## 2. Interrupt-Driven Odometry Tracking
Using dedicated hardware interrupts ensures zero pulse drops even under high-RPM operation.