I built a self-balancing robot using two simple brushed DC motors, an Arduino and motor controller, and a MPU6050 IMU sensor unit for sensing the tilt angle of the robot body, all powered by 6 AA batteries.
Using a PID control algorithm, the robot is able to correctly actuate its wheels depending on the tilt angle detected, maintaining a level body angle. The P, I and D gains were tuned and tested iteratively until appropriate values were obtained that enabled balancing of the robot with minimal overshoot of robot angle when adjusting, yet achieving target angle quickly.


First self-balancing robot version. Used a drone motor and ESC for the actuators. Found control of the robot to be too difficult and imprecise, especially since the motors feature a low-torque high-speed response (opposite of the desirable actuator properties for a self-balancing robot).




Second robot version. Two high-torque low-speed DC motors are used instead. The orange LiPo battery is used as a counterweight only; the robot is powered by 6 AA batteries here.
Video:
The code for this project can be found in this GitHub repository.