Arduino - Balance - Balancing Robot | How to Make?





Introduction: Arduino - Balance - Balancing Robot | How to Make?

In this tutorial we will learn how to make Arduino balancing (balance) robot that balances itself. First you can look at the video tutorial above.

Step 1: Required Hardware

Arduino Board (Uno) --

MPU-6050 GY521 Acc+Gyro --

DC Gear Motor Set --

L298N Motor Driver --

Switch Button --

M3 Hex Threaded Spacer Screw Nut Set --

Acrylic Perspex Sheet --

3.7v 18650 Rechargeable Li-ion+Charger --

9V Battery --

Jumper Wires --

Hot Glue Gun --

Black Friday Sale --

Black Friday Sale Electronic Special --

Step 2: Assembly of the Robot

  • Drill four corners of 3 Acrylic Sheets. (Image 1 and 2)
  • Between each acrylic sheet will be about 8 cantimeters / 3.15 inch. (Image 3)
  • Robot Dimensions (approx.) 15cm x 10 cm x 20cm. (Image 4)
  • The DC motor and the wheels will be placed at the center (midline) of the robot. (Image 5)
  • L298N Motor Driver will be placed in the first floor center (midline) of the robot. (Image 6)
  • The Arduino board will be placed in the second floor of the robot.
  • The MPU6050 module will be placed on the top floor of the robot. (Image 7)

Step 3: Connections

  • Test the MPU6050 and make sure it works! Connect the MPU6050 tot the Arduino first and test the connection using the codes in the below tutorial. The daha should be displayed on the serial monitor.

Instructables Tutorial - MPU6050 GY521 6 Axis Accelerometer+Gyro

YouTube Tutorial - MPU6050 GY521 6 Axis Accelerometer + Gyro

  • The L298N module can provide the +5V needed by the Arduino as long as its input voltage is +7 V or greater. However, I chose to have separate power source for the motor.

Step 4: How Does Balancing Work?

  • To keep the robot balanced, the motors must counteract the fall of the robot.
  • This action requires a feedback and a correcting element.
  • The feedback element is the MPU6050, which gives both acceleration and rotation in all three axis which is used by the Arduino to know the current orientation of the robot.
  • The correcting element is the motor and wheel combination.

  • The self-balancing robot is essentially an inverted pendulum.
  • It can be balanced better if the center of mass is higher relative to the wheel axles.
  • This is why I’ve placed the battery pack on top.
  • The height of the robot, however, was chosen based on the availability of materials.

Step 5: Source Code and Libraries

The code developed for the balance robot is too complicated. But there is no need to worry. We will only change some data.

We need four external libraries to make self-balancing robot work.

  • The PID library makes it easy to calculate the P, I, and D values.
  • The LMotorController library is used for driving the two motors with the L298N module.
  • The I2Cdev library and MPU6050_6_Axis_MotionApps20 library are for reading data from the MPU6050.

Download Libraries

PID --

LMotorController --

I2Cdev --

MPU6050 --

Get the Source Code -

What is PID?

  • In control theory, keeping some variable (in this case, the position of the robot) steady needs a special controller called a PID.
  • P for proportional, I for integral, and D for derivative. Each of these parameters has “gains” normally called Kp, Ki, and Kd.
  • PID provides correction between the desired value (or input) and the actual value (or output). The difference between the input and the output is called “error”.
  • The PID controller reduces the error to the smallest value possible by continually adjusting the output.
  • In our Arduino self-balancing robot, the input (which is the desired tilt, in degrees) is set by software.
  • The MPU6050 reads the current tilt of the robot and feeds it to the PID algorithm which performs calculations to control the motor and keep the robot in the upright position.

PID requires that the gains Kp, Ki, and Kd values be “tuned” to optimal values.

We will adjust the PID values manually instead.

  1. Make Kp, Ki, and Kd equal to zero.
  2. Adjust Kp. Too little Kp will make the robot fall over (not enough correction). Too much Kp will make the robot go back and forth wildly. A good enough Kp will make the robot slightly go back and forth (or oscillate a little).
  3. Once the Kp is set, adjust Kd. A good Kd value will lessen the oscillations until the robot is almost steady. Also, the right amount of Kd will keep the robot standing even if pushed.
  4. Lastly, set the Ki. The robot will oscillate when turned on even if the Kp and Kd are set but will stabilize in time. The correct Ki value will shorten the time it takes for the robot to stabilize.

Suggestion for better results!

I recommend that you create a similar robot frame using the materials used in this project to make the source code for the Balance Robot work stably and efficiently.

Step 6: For Support

  • You can subscribe to the my YouTube channel for more tutorials and projects.
  • Also you can subscribe for support. Thank you.

Visit to my YouTube Channel -



  • Science of Cooking

    Science of Cooking
  • Pocket-Sized Contest

    Pocket-Sized Contest
  • Paper Contest 2018

    Paper Contest 2018

We have a be nice policy.
Please be positive and constructive.


2 Questions


Hi, Mr. MertArduino,

How can I adjust the Acc+Gyro-Chip? Because I got the problem that the robot doesn't try to balance in the horizontal but a bit awry, so I have to make the gyro "find the middle". Tank you in advance.


Figured it out :D

Hi, Mr.MertArduino. I am Naresh. I have a few doubts about this project. so please help me out.
I don't know how to add the libraries. when I visited the links [PDI,LMotor controller,...] I couldn't find out anything except some cpp and .h files.If that's the correct file, please instruct me how to add them.
I also have a second doubt. How to control the robot ? Please tell whether the main program will be enough to control the robot.


I have a small project "robot balance" with arduino , I need for help in code of PID calcultor

A great start for these projects! I subscribed on youtube. Here is a link to a frame and body I designed for this type of robot -