Skip to content

06 · TK-101 · Projects

ESP32 PID motor position controller

A closed-loop motor position controller combining encoder feedback and PWM with PID tuning through physical buttons, an OLED and a local web interface.

Actual interface preview with no device connected: ESP32 PID motor position controller
Stack
ESP32C++ArduinoPIDQuadrature encoderPWMOLEDWi-Fi

The problem

Reaching a target angle requires continuous position feedback and error correction, together with a practical way to tune the controller.

Solution and data flow

Interrupt handlers count quadrature encoder pulses and convert them to an angle. A periodic PID loop computes motor direction and PWM output. The OLED shows values and a trace, while the ESP32 web server exposes readings and tuning controls.

Implementation and challenges

The implementation includes setpoint and gain adjustment, bounded integral accumulation, button debounce and long-press handling. Coordinating encoder capture, control and display updates is the main integration challenge. The configured 10 ms loop interval is not a measured response-time guarantee.

Skills developed

Feedback control, PID tuning, encoder interrupts, PWM motor drive, OLED interfaces and embedded web integration.