Welcome to Kerala Project Center.

Self-Balancing Robot

Self-Balancing Robot

Home-built two-wheeled self-balancing robot with its control board

Image: Two wheel balancing.jpg by Mitultakiar via Wikimedia Commons, CC BY-SA 4.0

A robot that stays upright on just two wheels, with no third support point, is a genuinely different control challenge from a standard wheeled robot — it has to continuously correct itself the instant it starts to tip.

This project builds a two-wheeled robot that uses an MPU6050 accelerometer/gyroscope to continuously measure its tilt angle, feeding a PID control loop that adjusts motor speed and direction dozens of times per second to keep the robot balanced upright, similar in principle to a Segway.

How It Works

  • The MPU6050 reports the robot's current tilt angle relative to vertical, combining accelerometer and gyroscope data for a stable, low-noise reading.
  • A PID control loop compares the measured tilt against the upright (zero-degree) target and computes a correction value.
  • That correction sets motor speed and direction — if the robot tips forward, the wheels drive forward to move the base back under the center of mass, and vice versa for backward tilt.
  • This loop runs continuously at a high update rate, since any delay in correction lets the robot tip too far to recover.

Components



Arduino Uno/Nano
MPU6050 accelerometer/gyroscope
Motor driver (L298N) + 2x DC gear motors + wheels
Chassis (narrow, two-wheel base)
Battery pack


Applications

  • Educational platform for PID control and inverted-pendulum dynamics
  • Foundational technique behind self-balancing personal transporters
  • Robotics competition entries

Advantages

  • Demonstrates real-time closed-loop PID control in a visually obvious way
  • Compact two-wheel footprint compared to standard four-wheel robots
  • Strong, memorable project demo — balance failure/success is immediately visible

Sample Code — Tilt-Based PID Balance Control



// Simplified self-balancing PID outline - Arduino + MPU6050
#include 
#include 
MPU6050 mpu;
float kP = 20, kI = 0.5, kD = 0.8;
float errorSum = 0, lastError = 0;

void loop() {
  float tiltAngle = readTiltAngle(mpu); // fused accelerometer + gyro angle
  float error = 0 - tiltAngle; // target = upright (0 degrees)

  errorSum += error;
  float derivative = error - lastError;
  float motorSpeed = kP * error + kI * errorSum + kD * derivative;
  lastError = error;

  driveMotors(motorSpeed); // positive = drive forward, negative = drive backward
}


Related Research


Hours

Monday - Saturday: 9:00 AM - 5:00 PM
Sunday: Not Working

Location

2nd Floor, Comptron Arcade, Kallattumukku,
Thiruvananthapuram, Kerala 695012

Book Now

+91 9633118080