PATH: /PROJECTS_ARCHIVE/PID_SELF-BALANCING_ROBOT

PID Self-Balancing Robot

Two-wheeled inverted pendulum stabilized via real-time PID feedback loops and IMU sensor processing

PID Self-Balancing Robot overview
Overview

Goals:

  • - Design and build a two-wheeled robot that balances itself continuously
  • - Process IMU sensor data in real time to calculate tilt and adjust motor output
  • - Complete system ownership from custom electronics and software to the physical design
  • - Learn control theory and circuit board design
Design
  • - KiCad designed PCB to route power and integrate all peripherals and modules
  • - Microcontroller: ESP32 for the additional wireless connectivity
  • - IMU: MPU6050 with 3-axis accelerometer and gyroscope to detect tilt and orientation
  • - C++ Control Loop: handles raw sensor processing, PID, motor driver commands
  • - Bluetooth tunable Kp / Ki / Kd without rewriting firmware every iteration
  • - CAD: Fusion 360 chassis, with a PLA frame and TPU tires for additional traction
PID Self-Balancing Robot design 1PID Self-Balancing Robot design 2PID Self-Balancing Robot design 3
PID Self-Balancing Robot implementation
Implementation

Isolated the motor power supply from 3.3V logic rails to keep motor switching noise off MCU power.

Combined the MCU, IMU, and motor drivers onto one PCB. No jumper wire mess or parasitics.

Firmware runs a fixed-rate loop that reads the IMU each control cycle, filters pitch and rate, and runs the PID to control both wheels.

Chassis modeled to align the battery and electronics for a higher center of mass, for easier balancing.

Testing and Results

Testing:

  • - Checked if motors could recover from small lean disturbances while iteratively tuning Kp, Ki, Kd parameters
  • - Logged real-time pitch angles to the terminal while testing to reduce overshoot and error
  • - Pushed the robot while actively balancing to make sure motor drivers handled sudden current spikes without cutting power

I was able to achieve a stable self-balancing robot (which also looked cool) within a ±2° angle margin and fast recovery under minor external forces. I personally found that integrating the components onto a single PCB with an enclosed chassis helped with loop stability compared to typical breadboard prototypes.

PID Self-Balancing Robot testing and results
← View all projects