Two-wheeled self-balancing robots represent a classic benchmark for underactuated, non-linear dynamic feedback control systems based on the inverted pendulum model. This paper presents the end-to-end design, kinematic modeling, hardware assembly, and experimental calibration of a compact two-wheeled self-balancing robot platform. The proposed system utilizes an Arduino Nano ATmega328P microcontroller as the core computing unit, coupled with a 6-axis MEMS MPU6050 Inertial Measurement Unit (IMU) featuring an onboard Digital Motion Processor (DMP) for real-time attitude sensing. Actuation is achieved via two DC geared motors driven by an L298N dual H-bridge module. A proportional-integral-derivative (PID) control scheme is implemented to compute corrective torque vectors and balance the chassis dynamically along its pitch axis. Experimental evaluation demonstrates that the calibrated controller (Kp = 21, Ki = 140, Kd = 0.9) maintains stable upright posture with recovery times between 1.5 and 3.0 seconds following external impulsive disturbances. The system provides a scalable, cost-effective framework for educational mechatronics and mobile autonomous transport platforms.
Introduction
The paper presents the design, mathematical modeling, implementation, and experimental testing of a two-wheeled self-balancing robot based on the inverted-pendulum principle. The goal is to develop a lightweight, low-cost robot capable of maintaining upright balance using an IMU, microcontroller, DC motors, and classical PID control.
Main problem
Two-wheeled self-balancing robots are inherently unstable because their center of mass must remain above the wheel axle. Continuous sensing and corrective motor torque are therefore required to prevent the robot from falling. This makes the inverted pendulum a useful benchmark for studying real-time control systems.
System design
The prototype consists of:
Arduino Nano (ATmega328P, 16 MHz) as the main controller.
MPU6050 6-axis IMU for measuring orientation using an accelerometer and gyroscope, with its DMP assisting sensor fusion.
Two geared DC TT motors providing wheel torque.
L298N dual H-bridge for motor direction and PWM speed control.
9V Li-Ion battery for system power.
Lightweight foam-board and acrylic chassis designed to provide sufficient rigidity and raise the center of mass.
The IMU is mounted firmly on the upper section of the chassis to reduce vibration-related measurement errors.
Mathematical model and control
The robot is modeled as an inverted pendulum, with its rotational dynamics determined by mass, center-of-mass distance, moment of inertia, gravity, and motor torque.
For small tilt angles, the nonlinear model is approximated using:
sin(θ) ≈ θ
A discrete PID controller then calculates corrective motor action based on the difference between the desired and measured tilt angles:
Kp: provides immediate corrective torque.
Ki: removes persistent tilt/drift caused by mechanical imbalance.
Kd: reduces oscillations and overshoot.
PID tuning
The controller was tuned experimentally:
Parameter
Initial
Final
Setpoint
180°
182°
Kp
5.0
21.0
Ki
50.0
140.0
Kd
0.1
0.9
The 182° setpoint compensates for an asymmetric center of gravity in the physical robot.
Experimental results
The prototype successfully maintained balance on flat surfaces and recovered from disturbances:
Flat surface: stable within approximately 2 seconds.
5 cm forward push: recovered in 1.8 s.
5 cm backward push: recovered in 1.5 s.
3° inclined surface: maintained balance but with some steady displacement.
Voltage below 7V: insufficient motor torque eventually caused the robot to fall.
Conclusion
This study presented the design, implementation, and empirical validation of an inverted pendulum self-balancing robot utilizing an Arduino Nano microcontroller, MPU6050 IMU, and PID closed-loop control algorithm. The experimental findings validate that optimal PID gain selection (Kp = 21, Ki = 140, Kd = 0.9) enables robust dynamic recovery from impulsive force perturbations.
Future work will focus on integrating wireless teleoperation (via Bluetooth HC-05 or Wi-Fi ESP8266), incorporating ultrasonic obstacle avoidance sensors, upgrading the structural chassis to 3D-printed ABS material, and exploring advanced non-linear control strategies such as Model Predictive Control (MPC) and Fuzzy Logic.
References
[1] K. J. Åström and K. Furuta, \"Swinging up a pendulum by energy control,\" Automatica, vol. 36, no. 2, pp. 287-295, 1996.
[2] F. Grasser, A. D\'Arrigo, S. Colombi, and A. C. Rufer, \"JOE: a mobile, inverted pendulum,\" IEEE Transactions on Industrial Electronics, vol. 49, no. 1, pp. 107-114, 2002.
[3] Arduino Project Hub, \"Arduino Two Wheel Self Balancing Robot,\" 2025. [Online]. Available: https://projecthub.arduino.cc/mircemk/arduino-two-weel-self-balancing-robot
[4] California State University, Northridge, \"Implementation of a Self-Balancing Robot,\" ScholarWorks, 2022. [Online]. Available: https://scholarworks.calstate.edu/downloads/08612n93k
[5] InvenSense / TDK, \"MPU-6050 Product Specification Revision 3.4,\" TDK InvenSense, Sunnyvale, CA, 2013.
[6] B. Beauregard, \"Improving the Beginner\'s PID,\" 2011. [Online]. Available: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/
[7] Atmel Corporation, \"ATmega328P 8-bit AVR Microcontroller Datasheet,\" Microchip Technology Inc., 2016.
[8] STMicroelectronics, \"L298N Dual Full-Bridge Driver Datasheet,\" Geneva, Switzerland, 2000.