Self-balancing robot with MPU6050 accelerometer from Arduino

Self Balancing Robot Using Arduino

We will use Arduino to build a self-balancing robot for this robotics project. We can learn how to control the motors and the concept of balancing in this. It’s too easy to use.

When I started building this project, I realized how difficult it was to build. When building this project, there are a lot of things to think about, like which motors, wheels, chassis, battery position, and gyroscope sensor to use. I chose some simple components to make this project easy to build after researching all of the criteria.

The MPU6050 accelerometer is used in this project. It interfaces with the Arduino and sends analog signals on the x, y, and z axes to the Arduino. Self-balancing robot with MPU6050 accelerometer from Arduino.

How does a self-balancing robot work?

The Self-Balancing Robot is an automated two-wheeler that can keep its balance and prevent falling to the ground. This is similar to other typical self-balancing robots with two wheels, like the Segway. Using the movement of the wheels and body along the motor’s axis, it maintains balance.


Self Balancing Robot Using Arduino

Circuit Diagram

self balancing robot

Components Required

Parts for the Self-Aligning Robot Project


Because it is easy to use, I have used the Arduino Uno microcontroller here. You could also use an Arduino Nano or an Arduino Mini, but I’d still recommend sticking with the Arduino Uno because it doesn’t need a breadboard to set up connections and can easily fit into a small chassis.

arduino nano


A stepper motor will unquestionably be the most suitable motor for a self-balancing robot. However, I have used a DC geared motor to keep things simple. Yes, having a stepper motor is not required; These low-cost DC geared motors, which are yellow in color, are also compatible with the bot.

bo motors

Motor Driver

You can use either an L293D driver module or the L298N driver module if you’ve chosen DC geared motors. Their jobs are similar. L298N is more powerful than L293D, but in that case, we can use any of them. The difference is that L298N is stronger. The L298N motor driver was my choice.

motor driver


It was difficult for me to determine that the issue was with my wheels. Therefore, ensure that the floor you are using is well-gripped by your wheels. Pay close attention because your grip should never permit your wheels to skitter on the ground.

bo motor wheels


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

MPU6050 Module

Self Balancing Robot Parts Assembly


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


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


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


Next, connect the Arduino board to the chassis.


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

Connexon of the Circuit

Using Arduino, connecting this self-balancing robot is fairly simple. We only need to connect the motors using the Motor Driver Module and interface the MPU6050 accelerometer with the Arduino. The 9V battery powers the entire setup.

The 12V terminal and the Vin pin, respectively, provide the Arduino and L298N Motor Driver Module with direct power. The ATmega IC and MPU6050 will be powered by the Arduino board’s onboard regulator, which will change the input voltage from 9V to 5V. The DC motors can operate from 5V to 12V, but we will be connecting the battery’s 9V positive wire to the Motor Driver Module’s 12V input terminal. With this, 9V will be used to run the motors.

The MPU6050 and L298N Motor Driver Module are connected to Arduino in the following self-balancing robot connection chart. Self-balancing robot with MPU6050 accelerometer from 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

After testing all of the self-balancing robot’s features on a breadboard, I designed the PCB to make the circuit small and professional-looking. I build a small Arduino Nano for that PCB purpose. I will go over each step of designing and ordering a PCB for our project in detail.

Self Balancing Robot PCB

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

Order PCB From Zbotic

The PCB prototype board was ordered from the website Zbotic is a manufacturer of flexible PCBs, SMD stencils, prototypes for printed circuit boards (PCBs), and PCB assembly in China. They process more than 2100 PCB orders per day and ship to more than 170 nations worldwide. It appears that Zbotic provides excellent customer service and pricing in a single serving.

The PCB has a fantastic thickness and excellent quality. As a maker and customer, I find Zbotic service to be equally remarkable. This article will provide a step-by-step guide on how to place an order for a PCB from Zbotic, as well as details on the helpful support staff and user-friendly website features that contribute to what makes Zbotic the ideal business and brand for electronic hobbyists.


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. Self-balancing robot with MPU6050 accelerometer from Arduino.

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 Zbotic, 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

Once you have the necessary hardware for this self-balancing robot project, you can upload the code to your Arduino board. Since we are utilizing a 9V battery, extreme caution is required. Verify the connections. Therefore, in the event that your robot experiences a few minor impacts, double check for short circuits and guarantee that the terminals will not come into contact. Open your serial monitor and power on your module. If your Arduino was able to successfully communicate with the MPU6050 and everything is working as expected, you should see the screen below. The value of the output will be zero if the robot is perfectly balanced. The MPU6050 sensor’s current value is the input value.

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

I hope this will help you construct 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

Back to list

Leave a Reply

Your email address will not be published. Required fields are marked *