Portfolio
Controls & Embedded Systems

Self-Balancing Robot

A two-wheeled inverted pendulum on an Arduino Uno. The MPU-6050's onboard DMP handles sensor fusion, feeding stable pitch angles into a PID controller that drives two geared DC motors through an L298N at 100Hz — keeping the robot upright in real time.

ComponentPartDetails
MicrocontrollerArduino UnoATmega328P, 5V
IMUMPU-60506-axis accel/gyro, I2C, onboard DMP
Motor DriverL298NDual H-bridge, up to 12V motor supply
Motors (×2)JGA25-370Geared DC, 1:34 ratio, 126 RPM @ 12V, 73mm wheel
Motor Supply9VApplied to motors via L298N
kP
30
Main balance force — responds to current tilt
kI
90
Corrects steady-state lean and slow drift
kD
0.5
Damps oscillation and motor judder

Sample rate: 10ms (100Hz)  ·  Trim angle: 2.85°  ·  Output limits: −255 to +255 PWM

Click any image to view full size

SketchDescription
RobotTest.inoIMU validation — raw MPU-9250 output, verifies wiring before PID integration
TWRbalance-1.inoFirst balance attempt. L293D pinout, kP=150/kI=400/kD=5, trimAngle=−4.3°
TWRbalanceOURS.inoAdapted to L298N pinout, gains reduced, trimAngle=3.125°
TWRbalanceOURS_v2.inoFinal version — adds timed moveForward/standStill state machine, kP=30/kD=0.5