Design and Implementation of a Two-Wheel Self-Balancing Robot Using PID Control on an ESP32: Custom PCB, Simulink-generated controller, and a Wi-Fi control panel with OTA updates
This report describes the design and construction of a two-wheeled self-balancing robot, from the hardware to the control software. The robot runs on an ESP32 and reads its tilt angle from an MPU-92/65 IMU. It is powered by Li-ion cells, with an ATtiny13A as a secondary microcontroller that keeps the board in a safe state and resets the ESP32 during firmware updates. I designed a two-layer PCB in Altium Designer that also leaves room for a camera and a servo for later additions. The balancing controller is a positional PID built from basic Simulink blocks, with a low-pass filter on the roll signal. C code generated with Embedded Coder was integrated into a C++ program that uses FreeRTOS and ESPAsyncWebServer. A web control panel served by the robot lets the user change controller parameters, monitor the IMU data at about 200 Hz, read non-volatile system logs, and upload new firmware over the air. During testing, the geared DC motors stalled when the PWM command changed by more than 470 counts at once, so a rate-limiting stage was added before the motor output. Two physical models of the robot were tried, but neither gave usable PID gains. A transfer function identified from 120 s of roll data sampled at 200 Hz reached only a 24.49% fit. The gains were therefore tuned experimentally through the control panel, which gave a steady-state error of about 0.3 degrees. Remote driving and live camera streaming are planned as future work.
Authors
- Mohammad Sina Majidi (ORCID: https://orcid.org/0009-0006-9046-3691)
Publication Details
- Journal
- Engineering Archive (engrXiv)
- Published
- 2026-11-20
- DOI
- https://doi.org/10.31224/8857
- Primary Topic
- Control and Dynamics of Mobile Robots
- Type
- preprint