. Arduino Two-Wheel Self-Balancing Robot ~ SmartElectronicsDIY

Arduino Two-Wheel Self-Balancing Robot

 Design and Implementation of an Arduino-Based Two-Wheel Self-Balancing Robot


🔷 Abstract

A two-wheel self-balancing robot is a robot that maintains its upright position using feedback from motion sensors. This project uses an Arduino UNO, an MPU6050 accelerometer & gyroscope, and DC motors to continuously measure the tilt angle and correct it using a PID control algorithm. The robot behaves like an inverted pendulum and balances itself in real time.


🔷 Objectives

  • To design a self-balancing robot using Arduino

  • To understand gyroscope & accelerometer sensors

  • To implement PID control

  • To control motors using motor driver

  • To study real-time feedback systems


🔷 Block Diagram

MPU6050 Sensor → Arduino UNO → PID Controller → Motor Driver → DC Motors

🔷 Components Required

🔹 Hardware

ComponentQuantity
Arduino UNO1
MPU6050 (Gyro + Accelerometer)1
L298N / L293D Motor Driver1
DC Gear Motors2
Robot Chassis + Wheels1 set
18650 Battery / 12V Battery1
Buck Converter (optional)1
Jumper WiresAs required
Power Switch1

🔷 Working Principle

  • The MPU6050 measures tilt angle (pitch).

  • Arduino calculates error between current angle and setpoint (0°).

  • PID algorithm calculates motor speed correction.

  • Motors rotate forward or backward to balance robot.

  • This loop runs hundreds of times per second.


🔷 Circuit Connections

🔹 MPU6050 → Arduino

MPU6050Arduino
VCC5V
GNDGND
SDAA4
SCLA5

🔹 Motor Driver (L298N) → Arduino

L298NArduino
IN1D5
IN2D6
IN3D9
IN4D10
ENAD3 (PWM)
ENBD11 (PWM)

🔷 Arduino Code (Basic Working)

#include <Wire.h> #include <MPU6050.h> MPU6050 mpu; float angle, error, lastError; float Kp = 18, Ki = 0.8, Kd = 0.9; float integral, derivative; float setPoint = 0; void setup() { Wire.begin(); mpu.initialize(); pinMode(3, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); } void loop() { angle = mpu.getAccelerationY() / 16384.0 * 90; error = setPoint - angle; integral += error; derivative = error - lastError; float output = Kp * error + Ki * integral + Kd * derivative; lastError = error; motorControl(output); } void motorControl(float speed) { speed = constrain(speed, -255, 255); if (speed > 0) { digitalWrite(5, HIGH); digitalWrite(6, LOW); } else { digitalWrite(5, LOW); digitalWrite(6, HIGH); } analogWrite(3, abs(speed)); }

🔷 Output

  • Robot stands upright automatically

  • Maintains balance when pushed slightly

  • Corrects tilt in real time


🔷 Advantages

✔ Real-time control system
✔ Educational (PID, sensors, robotics)
✔ Low cost
✔ Expandable (Bluetooth, obstacle avoidance)

0 comments:

Post a Comment