Skip to content

Tiny 32-Neuron Network Balances an ESP32 Robot, Making a Decision 500 Times a Second

A maker demonstrates a TinyML experiment where a 32-neuron network on an ESP32 balances a two-wheeled robot by imitating a Linear Quadratic Regulator teacher. The system makes decisions at 500 Hz, completing inference in roughly 33 microseconds while handling sensor filtering and motor limits. This approach avoids reward-based training and simulated environments, using instead behavior cloning to copy an existing controller's outputs. The network successfully completes ten out of ten freestanding starts and travels about 40 meters when driven from a keyboard.

Article text · Original source

How small can a neural network be and still do a real job? The maker behind the Build Mode channel answered that with his ESP32 self-balancing robot: a network of just 32 neurons now keeps it upright, making a decision 500 times a second. It is a clean, measurable TinyML experiment on hardware many makers already own, and it shows a smarter way to train a controller than trial and error.

Three brains, one robot

The robot is a 16 cm, roughly 1 kg two-wheeler with brushed DC gear motors, two motor drivers, an MPU-6500 gyro and accelerometer, and an ESP32 with a small display. In the first episode it balanced on three cascaded PID loops for angle, speed and position. In the second, those loops were replaced by LQR, a linear quadratic regulator: one equation that watches five states at once (angle, tipping rate, position, speed and an integral term) with gains computed from a model of the robot rather than tuned by hand. LQR initially made the motors chatter about 20 times a second because of up to 3 degrees of gearbox backlash, until two fixes calmed it down.

Learning from a teacher, not from falling

For the third brain, Build Mode did not let the robot learn by falling over. Instead, his PC generated made-up robot states, asked the LQR controller what it would do in each one and trained the network to copy those answers. There were no rewards and no simulated robot, and one training run takes about 40 seconds on a PC. This approach is often called imitation learning or behaviour cloning.

The result is two hidden layers of 16 neurons, 385 learned numbers in total, taking five inputs and producing one base motor command. An inference takes about 33 microseconds on the ESP32, leaving plenty of time inside the 500 Hz control loop. The existing code still filters the sensors, steers and limits the final command, but the balancing decision belongs to the network.

The results

The first two trained networks failed their test. The third was first run silently alongside LQR, and its outputs stayed within about 0.18 percent of LQR's even when the robot was pushed. Given control, it completed ten out of ten freestanding starts and was driven about 40 metres from the keyboard. In push tests it behaved like LQR, while the original PID setup leaned less but rolled almost twice as far.

The honest verdict from the video is that the network can only be as good as its teacher, and it landed right there. If you want to try the basics first, our Arduino self-balancing robot project walks through the PID version, and Build Mode shares the robot's parts, 3D models and files on the channel's website.

About the author: Aswinth Raj is an electronics engineer and the editor of CircuitDigest, where he has published more than 150 hands-on projects and tutorials across Arduino, PIC, ESP32, Raspberry Pi and EV battery systems. He selects the stories on this page for what engineers and makers can actually learn or build from. Connect on LinkedIn

Source notes

  1. Tiny 32-Neuron Network Balances an ESP32 Robot, Making a Decision 500 Times a Second↩
Source evidence

Reported by the source; not independently verified.

decision frequency
500[2]
robot height
16[3]
robot mass
1[3]
training duration
≈40 seconds[4]
inference time
≈33[4]
  1. How small can a neural network be and still do a real job? The maker behind the Build Mode channel answered that with his ESP32 self-balancing robot: a network of just 32 neurons now keeps it upright , making a decision 500 times a second. It is a clean, measurable TinyML experiment on hardware many makers already own, and it shows a smarter way to train a controller than trial and error. Three brains, one robot The
    Exact source↩
  2. robot is a 16 cm, roughly 1 kg two-wheeler with brushed DC gear motors , two motor drivers, an MPU-6500 gyro and accelerometer , and an ESP32 with a small display. In the first episode it balanced on three cascaded PID loops for angle, speed and position. In the second, those loops were replaced by LQR, a linear quadratic regulator: one equation that watches five states at once (angle, tipping rate, position, speed a
    Exact source↩
  3. troller what it would do in each one and trained the network to copy those answers. There were no rewards and no simulated robot, and one training run takes about 40 seconds on a PC. This approach is often called imitation learning or behaviour cloning. The result is two hidden layers of 16 neurons, 385 learned numbers in total, taking five inputs and producing one base motor command. An inference takes about 33 micr
    Exact source↩
  4. oseconds on the ESP32, leaving plenty of time inside the 500 Hz control loop. The existing code still filters the sensors, steers and limits the final command, but the balancing decision belongs to the network. The results The first two trained networks failed their test. The third was first run silently alongside LQR, and its outputs stayed within about 0.18 percent of LQR's even when the robot was pushed. Given con
    Exact source
  5. trol, it completed ten out of ten freestanding starts and was driven about 40 metres from the keyboard. In push tests it behaved like LQR, while the original PID setup leaned less but rolled almost twice as far. The honest verdict from the video is that the network can only be as good as its teacher, and it landed right there. If you want to try the basics first, our Arduino self-balancing robot project walks through
    Exact source

Automatically extracted; no manual editorial approval recorded.

Article details
Signal

The author demonstrates a 32-neuron network on an ESP32 that imitates a Linear Quadratic Regulator teacher, achieving stable balance without reward-based training.

Timezone · UTC

Article dates follow your selected timezone. Briefing editions use Hong Kong time (UTC+8).