Preprint / Version 1

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

##article.authors##

DOI:

https://doi.org/10.31224/8857

Keywords:

self-balancing robot, inverted pendulum, PID control, ESP32, Simulink Embedded Coder, FreeRTOS, over-the-air update, system identification

Abstract

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.

Downloads

Download data is not yet available.

Downloads

Posted

2026-11-20