Self-balancing Robot using PID control

Self-balancing Robot using PID control

This website showcases the development, implementation, and final results of our autonomous two-wheeled balancing robot.

🌐 View on GitHub

🧊 STL Files (viewable)

📚 Docs

Self-Balancing Robot

Welcome to the official project page for our Self-Balancing Robot. This website showcases the development, implementation, and final results of our autonomous two-wheeled balancing robot. Built as part of our control systems course (ENEE/ENME 461), this project merges hardware, software, and control theory into a compact, responsive platform.


🚀 Introduction

Inspired by the classic inverted pendulum problem, our robot demonstrates real-time balance using sensor feedback and PID control. It uses an ESP32 microcontroller, an MPU6050 IMU, and two DC gear motors controlled via a dual H-bridge. The challenge? Keep the robot upright on just two wheels—like a miniature Segway.


🛠️ Hardware Design

Our robot features:

Wiring Note: We routed power from the 12V battery through buck converters to deliver clean 5V and 3.3V for logic and sensor components. All grounds from the Arduino, H-bridge, IMU, and buck converters are tied together to form a common ground reference. Motor power lines run directly from the battery to the L298N to handle current draw, while logic control pins are connected from the Arduino to the H-bridge via digital pins. I²C lines from the MPU6050 are connected to A4 and A5, with pull-up resistors handled internally. Each connection was tested using a multimeter for continuity, and critical joints were soldered and insulated with shrink wrap for durability.

All components were selected based on torque calculations and center of mass optimization. The wheels are 5 inches in diameter, offering a balance between responsiveness and ground clearance.

The IMU is mounted close to the motors to reduce sensor lag and noise, while the battery is positioned low in the chassis to help with overall center of mass and balancing. The buck converters provide stable 5V and 3.3V rails from the main 12V battery, which also directly powers the motors and is safe for the Arduino’s VIN input (which tolerates up to 12V). Even with a 2V drop across the motors, our logic power is regulated and isolated from load variations.

🧵 Wiring Details

We routed power from the 12V battery through buck converters to deliver clean 5V and 3.3V for logic and sensor components. All grounds from the Arduino, H-bridge, IMU, and buck converters are tied together to form a common ground reference. Motor power lines run directly from the battery to the L298N to handle current draw, while logic control pins are connected from the Arduino to the H-bridge via digital pins. I²C lines from the MPU6050 are connected to A4 and A5, with pull-up resistors handled internally. Each connection was tested using a multimeter for continuity, and critical joints were soldered and insulated with shrink wrap for durability.



📐 CAD and Mechanical Assembly

The chassis was designed using Fusion360 and printed with PLA. The base houses the motors, driver, and battery. A custom bracket mounts the IMU at wheel axle level to reduce measurement noise. Zip ties and shrink tubing were used to secure and organize wires.

alt text alt text


🧠 Control System

We implemented a PD (Proportional-Derivative) control loop in C++ on the ESP32. Real-time pitch angle is read from the MPU6050, processed, and used to drive the motors with appropriate speed and direction. The system runs a loop every few milliseconds and includes a safety cutoff if the robot tilts beyond ±25°.

Key features:


🧪 Testing and Tuning

Initial tuning was done using only the proportional term (Kp). We observed oscillations and instability at high Kp values. Adding the derivative term (Kd) improved stability and response time.

Final stable tuning:

We used MS Excel’s Data Streamer to collect and visualize data from serial output, allowing analysis of angle, error, and motor input over time.


📹 Demo and Results

Our robot successfully balances under mild disturbances and showcases dynamic feedback in action. It reacts quickly, stabilizes after nudges, and remains upright unless excessive weight or tilt is applied.


🔧 Full Parts List

Refer to the shopping list document for exact components. Major items include:


🔌 Wiring Table

FunctionComponentArduino PinDirectionNotes
Motor A DIR 1H-Bridge INA1D7OutputSets forward/reverse
Motor A DIR 2H-Bridge INB1D8Output
Motor A PWMH-Bridge PWM1D5PWM Output
Motor B DIR 1H-Bridge INA2D9Output
Motor B DIR 2H-Bridge INB2D10Output
Motor B PWMH-Bridge PWM2D6PWM Output
I²C SDAMPU6050A4I²CConnects to MPU6050 SDA
I²C SCLMPU6050A5I²CConnects to MPU6050 SCL
5V Logic PowerH-Bridge / IMU-PowerFrom 5V buck converter
GNDAll Devices-GroundCommon ground for all
VIN9V BatteryVINPower InputPowers Arduino Uno

📅 Timeline

Week 1:

Week 2:

Week 3:


🎓 Conclusion

This project was a successful application of control theory, hardware integration, and real-time feedback systems. Despite minor hardware limitations (motor torque, wheel grip), we achieved a reliable self-balancing robot that visually and functionally reflects our knowledge in embedded control.


📁 Appendix