Self-Balancing Robot

PID Control Embedded C

Overview

A self-balancing robot built around a PID controller, one of my earliest embedded projects, from 2019. The robot uses feedback from its own tilt to drive its wheels in the direction that keeps it upright, the same inverted pendulum problem at the core of everything from Segways to rocket landings.

How it works

A PID controller reads the current tilt angle and continuously computes a correction: the proportional term reacts to how far off vertical the robot currently is, the integral term corrects for any small steady lean that persists over time, and the derivative term reacts to how fast the tilt is changing to avoid overshooting the correction. The animation above shows the same behavior in miniature: a small disturbance tips the pendulum, and the correction pulls it back toward vertical, oscillating a little before settling.

← Back to all projects