Back

Arduino Self-Balancing Robot

Senior capstone project at Bergen County Academies.

Project Overview

  • Goal: build a self-balancing robot that maintains stability on two wheels
  • Arduino continuously reads data from an accelerometer and gyroscope to determine robot's tilt angle
  • Using a PID feedback loop, the Arduino determines how quickly to drive the motors to restore balance
Working Principle Image 1 Working Principle Image 2 Working Principle Image 3

Hardware

Arduino Nano
Arduino Nano
IMU Sensor
GY-521 (MPU-6050), accelerometer and gyroscope
Ultrasonic Sensor
HC-SR04 ultrasonic sensor
Bluetooth Module
DXBT-16 bluetooth module
Motor Driver
TB6612FNG motor drivers
DC Motor
DC Motors
Lithium Ion Battery
Lithium ion battery
Wheel
Wheels

PID Controller

The controller is responsible for processing sensor data and adjusting the motor outputs to maintain balance. It uses PID control, which aims to minimize the error between the desired and actual positions of the robot based on proportional, integral, and derivative terms.

PID Control Diagram

A large part of the project was dedicated to tuning PID constants. Tuning PID constants precisely is critical for a self-balancing robot because the system behaves like an inverted pendulum: inherently unstable and highly sensitive to small control errors. The robot is always on the edge of tipping over; even a tiny deviation grows quickly if not corrected immediately. Slightly off PID constants can mean the robot either reacts too slowly (falls) or too aggressively (oscillates and falls).

  • Proportional (P): Reacts to the current tilt angle; provides an immediate correcting force proportional to how far the robot is leaning.
  • Integral (I): Corrects long-term bias or small steady-state errors by accumulating past error. I was actually able to set this term to (essentially) 0 because the system's fast dynamics and sensor noise made integration unnecessary and potentially destabilizing.
  • Derivative (D): Predicts motion by responding to the rate of change of tilt — effectively adds damping, preventing overshoot and helping smooth out rapid corrections.

Final Product

Gallery 1
Gallery 2
PID Control
Arduino
PCB Design
I²C Communication
BLE Communication
Signal Processing