12 of 16ElectronicsLab project2025

Balance

A two-wheeled robot that stands itself up and stays there.

A cheap IMU, a small microcontroller and a very opinionated PID loop, tuned through trial after trial.

  1. An STM32 Pyboard runs the loop at about 200 Hz.

  2. Two-cell LiPo, with regulators for the logic and the IMU.

  3. Two geared motors, with a dead zone mapped so small corrections still move.

Balance
BalanceControlNot to scaleSheet 12
Brief
Make a two-wheeled robot stand itself up, and stay there.
Role
Built, programmed and tuned it: sensing, the PID loop, motors and power.
Outcome
It snaps to vertical and shrugs off a shove.
  • Pyboard
  • MPU-6050
  • Complementary filter
  • PID
DesignEngineeringResearchRootsDE NIRORotaryOwnershipMEDIBreatheTalking HatTMJFlowCoolingAirseatBalanceSwipeChairHeat GunDots & Boxes
Balance is a great teacher: sensors lie, motors lag, batteries sag, and the maths still has to work.
A note of my own
How it worksStep 01 of 03
  1. 01

    Sense

    The gyro gives rate, the accelerometer gives gravity. A complementary filter blends them.

  2. 02

    Decide

    Setpoint 0°. PID pushes the wheels to cancel the error, with anti-windup.

  3. 03

    Stand

    Tuned through trial after trial until it shrugs off a shove.

Shove it. It comes back.