This document describes the control system for balancing a two-wheeled inverted pendulum robot, such as a Segway. It discusses using a mathematical model and state space equations in a model-based controller or a physical model and PID controller in an error-based controller. It then describes the hardware implementation using an Arduino, accelerometer, encoder, and DC motor to read sensor values, calculate angle and velocity, and provide feedback control to balance the robot.