Tiny Neural Network Balances Two-Wheeled Robot Using ESP32

A maker using the YouTube channel Build Mode developed a 32-neuron neural network running on an ESP32 microcontroller to balance a two-wheeled robot. The network, trained on data from a linear-quadratic regulator (LQR) controller, replicates the LQR's output with less than 0.18% difference. It processes inputs in just 33 microseconds, enabling real-time control within a 500 Hz loop.
A maker known as Build Mode, whose YouTube channel documents DIY robotics projects, developed a 32-neuron neural network that runs on an ESP32 microcontroller to balance a two-wheeled robot. The network, trained using data generated by a pre-existing linear-quadratic regulator (LQR) controller, replicates the LQR’s output with less than 0.18% deviation. The robot’s control system processes five inputs—such as lean angle and motor response—producing a single motor command in just 33 microseconds, enabling real-time operation within a 500 Hz control loop. The robot, constructed from 3D-printed parts and powered by DC gear motors and batteries, uses an ESP32 as its central processor, with a small display showing real-time data. The neural network was trained on a PC in about 40 seconds using synthetic data from the LQR, eliminating the need for physical trials during training. After validation, the network successfully controlled the robot through ten freestanding starts and over 40 meters of keyboard-driven travel without requiring backup controllers. However, during aggressive testing, timing issues emerged due to computational load, and the network replicated the LQR’s tendency to oscillate on soft surfaces.
Build Mode, a content creator focused on robotics and hardware innovation, aims to explore the limits of small-scale machine learning in embedded systems. The project demonstrates that even minimal neural networks can effectively mimic complex control algorithms, challenging assumptions about the necessity of large models for real-world tasks. While replacing five LQR gain parameters with 385 neural weights currently offers no practical advantage, the experiment opens doors for future integration—such as adding memory or combining the network with PID control. What remains unresolved is whether such tiny networks can eventually outperform or adapt beyond their teachers, and how robust they will be in unpredictable environments. The broader implications for embedded AI, especially in low-power, low-cost devices, are still emerging.
This project highlights a growing trend in TinyML—deploying minimal neural networks on resource-constrained devices like microcontrollers. By demonstrating that a 32-neuron network can match a well-established control algorithm with near-perfect accuracy, it suggests that AI may not always require massive computational power to deliver meaningful results. This could influence education, where students learn control theory through hands-on projects using accessible hardware. It may also impact industries like robotics, wearables, and IoT, where power efficiency and real-time responsiveness are critical. A comparable earlier case is the rise of microcontrollers in the 2000s, which democratized embedded development much like TinyML is doing today. While not yet a replacement for traditional control systems, such experiments may eventually lead to adaptive, self-tuning systems in consumer and industrial devices. What to watch for next is whether developers begin embedding such networks in production hardware, and how firmware and hardware design will evolve to support them.