Arduino Self Balancing Robot Using MPU6050 Accelerometer

In this robotics project, we are going to make a self balancing robot using Arduino. In this, we can learn the balancing concept and how to control the motors. Its working is too simple.

Once I started to build this project, I realized that it is quite a bit challenging to build. There are so many things to consider for building this project like choosing motors, wheels, chassis, battery position and gyroscope sensor. After researching all criteria I chose some easy parts for building this project easily.

Here we use the MPU6050 accelerometer which interfaces with Arduino and sends some analog signals to the Arduino on the x-axis, y-axis, and z-axis.

Must Read Arduino Bluetooth Controlled Car

What is Self Balancing Robot?

Self Balancing Robot is a two-wheeler automated robot that can balance itself from falling to the ground. This is similar to other typical two-wheeled self balancing robots, such as the Segway. Its function is to maintain balance using the motor’s axis movement of the wheels and body.


Arduino Self Balancing Robot Using MPU6050

Circuit Diagram

self balancing robot circuit diagram

Components Required

  • Arduino
  • Geared DC motors (x2)
  • L298N Motor Driver Module
  • MPU6050 Accelerometer
  • Two Wheels (x2)
  • 3.7V Lithium-Ion Battery (x4)
  • Connecting Wires
  • Foam Sheet

About Self Balancing Robot Project Parts


The microcontroller that I have used here is Arduino Uno because it is simple to use. You can also use an Arduino Nano or Arduino Mini but I would recommend you stick with Arduino Uno since it need not any breadboard for connection setup, so it can easily fit in a small chassis.


The best choice of motor that you can use for a self balancing robot, without a doubt will be a stepper motor. But To keep things simple I have used a DC geared motor. Yes, it is not mandatory to have a stepper motor; the bot works fine with these cheap yellow-coloured DC geared motors as well.

geared motor

Motor Driver

If you have selected the DC geared motors then you can either use the L298N driver module or an L293D driver module. Both are similar in work. The Difference is that L298N is more powerful than L293D. But in that case, we can use any of them. I chose the L298N motor driver.

l298n motor driver


I had a tough time figuring out that the problem was with my wheels. So make sure your wheels have a good grip over the floor you are using. Watch closely, your grip should never allow your wheels to skit on the floor.

robot wheel


The best choice of accelerometer and gyroscope sensor for this project is the MPU6050.

mpu6050 sensor

Self Balancing Robot Parts Assembly

First, we need a foam sheet for making the chassis of the robot.

self balancing robot motor attachment

Next, we need to attach both the DC geared motors with the foam sheet.

self balancing robot l298n motor driver

Connect all the motors with the L298N motor driver and set it in the chassis.

self balancing robot arduino uno

Next, connect the Arduino board to the chassis.

self balancing robot mpu6050

Finally, attach the MPU6050 accelerometer to the top of the chassis. And also attach both wheels to the chassis.

Circuit Connection

Making the connections for this Self Balancing Robot using Arduino is pretty simple. We just have to interface the MPU6050 accelerometer with Arduino and connect the motors through the Motor Driver Module. The whole set-up is powered by the 9V battery.

The Arduino and the L298N Motor Driver Module are directly powered through the Vin pin and the 12V terminal respectively. The onboard regulator on the Arduino board will convert the input 9V to 5V and the ATmega IC and MPU6050 will be powered by it. The DC motors can run from voltage 5V to 12V. But we will be connecting the 9V positive wire from the battery to the 12V input terminal of the Motor Driver Module. This will make the motors operate with 9V.

The following connection chart of the self balancing robot will list how the MPU6050 and L298N Motor Driver Module is connected with Arduino.

  • MPU6050 Vcc pin to +5V pin of Arduino Nano
  • GND pin of Arduino Nano to MPU6050 ground pin
  • Arduino Nano A5 pin to MPU6050 SCL pin
  • MPU6050 SDA pin to A4 pin of Arduino Nano
  • MPU6050 INT pin to D2 pin of Arduino Nano
  • L298N IN1 pin to D6 pin of Arduino Nano
  • IN2 pin to D9 pin of Arduino Nano
  • IN3 pin to D10 pin of Arduino Nano
  • IN4 pin to D11 pin of Arduino Nano

Circuit Design Using PCB Software

To make the circuit compact and give a professional look, I have designed the PCB after testing all the features of the self balancing robot on the breadboard. For that PCB purpose, I use Arduino Nano for a compact build. I will explain in detail how we can design and order PCB for our project.

self balancing robot pcb

Check out this link for Gerber file Self Balancing Robot Gerber File.

Order PCB From PCBWay

I ordered the PCB prototype board from the website. PCBWay is a Chinese-based PCB (printed circuit board) prototype, PCB assembly, SMD Stencil and Flexible PCB manufacturer. They ship to more than 170 countries worldwide and process more than 2100 PCB orders a day. It feels like PCBWay gives an excellent price and customer service factor in one single serving. The quality of the PCB is awesome and its thickness is really great. What is also spectacular about PCBWay to me, as a maker and customer, is their service. From their friendly support staff to their intuitive, user-friendly website features, it all counts towards what makes PCBWay an ideal company and brand for any electronic hobbyists In this article, I will state that how can we order PCB from PCBWay with step by step guide.

Features of PCBWay

1. PCB prototyping and manufacturing

They are not only producing FR-4 and Aluminum boards, but also advanced PCB like Rogers, HDI, Flexible and Rigid-Flex boards, at a very reasonable price.

Visit the link for Instant Quote

Visit the link for Gerber file viewer

2. PCB assembly

SMT & THT assembly starts from only $30 with a free stencil and free worldwide shipping. The components can be sourced and provided by PCBWay, or by clients themselves.

3. Layout and design

Partnering with quality service providers to offer design services.

4. Open source community

Student sponsorship shared PCB projects and so on.

5. 3D Printing & CNC

On-demand Production and Rapid Prototyping in as Fast as 1 Day Leading the Digital Manufacturing Revolution.

Working Principle of Self Balancing Robot

In this self balancing robot project, once you are ready with the hardware, you can upload the code to your Arduino board. Make sure the connections are proper since we are using a 9V battery, extreme caution is needed. So double-check for short circuits and ensure that the terminals won’t come into contact even if your robot experiences some small impacts. Power up your module and open your serial monitor, if your Arduino could communicate with MPU6050 successfully and if everything is working as expected you should see the following screen. If the robot is perfectly balanced, the value of output will be 0. The input value is the current value from the MPU6050 sensor.

During the initial stages of PID, I recommend leaving your Arduino cable connected to the robot, so that you can easily monitor the values of input and output and also it will be easy to correct and upload your program for Kp, Ki and Kd values.

Hope this helps to build your own self balancing robot.

Arduino Code

For establishing this code of self balancing robot, we need two libraries. The library is developed by Br3ttb and Jrowberg respectively. Before proceeding download their libraries from the following link and add them to your Arduino lib directory.


MPU6050 Library

Next for the Arduino code for the self balancing robot

1 thought on “Arduino Self Balancing Robot Using MPU6050 Accelerometer”

Leave a Comment