← Theo Bui
Imperial College

Self-Balancing Segway

PID control · Beat detection · Python

A self-balancing robot built on the PyBench platform — a series of challenges that culminated in a PID-controlled segway that dances to music.

How it works

Balance is maintained using a PID controller fed by an IMU (accelerometer + gyroscope). The raw sensor data is noisy — a complementary filter removes accelerometer noise with a low-pass filter and gyroscope drift with a high-pass filter, giving a clean angle reading.

Beat detection uses a microphone with a moving average filter to measure instantaneous energy relative to recent noise, then maps that to LED brightness. The same beat signal drives the dancing behavior.

GitHub →