Self Balancing Robot Using Arduino Nano and MPU 6050

by psp50 in Workshop > Science

3097 Views, 9 Favorites, 0 Comments

Self Balancing Robot Using Arduino Nano and MPU 6050

F445PJ9KVGOEMUZ.jpeg
FSOQGL8KVGOEMVM.jpeg

self balancing robots are unique among all other, just because of their ability to balance on a given fixed position.

Even is the robot is displaced from its position, it is programmed so that it again recovers its position. IN this tutorial we will make an simple Arduino Nano based self balancing robot. This robot is based on MPU-6050

motion detector. To make this project we will require following parts,

Supplies

Making the Frame

To make frame we have used card board frame you ac you 3D printed, or custom made which are easily available from internet.

while making frame try to keep the heavy stuff towards the bottom like battery and motor driver this helps to bring center of gravity towards base and helps robot to keep balance . also try to keep the overall height of frame low but not less than base length

Wiring Up the Circuit

Screenshot (5).png

Wiring is simple, the MPU 6050 measures the tilt and Arduino sets the motor speed to overcome tilt using the L298N motor driver.

Here we are using MPU-6050 because it is cheap and reliable sensor. Having accuracy and its ability to simultaneous measure all three axis rotation and motion makes it perfect for use in self balancing robots.L298N is also a low cost dual H-bridge motor driver perfect for use in here.

on the assembly the MPU-6050 is placed on top facing its Z axis towards earth. however you can place this sensor anywhere in the frame. also the orientation can be changed according to frame and design, for this you have to make changes in code.

as we are using L298N as motor driver and also as power supply for Arduino so place the power jumper, so that we can use +5v as power supply.

rest of the wiring is done according to diagram given.

Balancing Test and Tuning

image 9.png

self balancing robots of this type are basically inverted pendulum, it is similar to balance a stick on your finger. Here the rotation of wheel provide the counterbalancing force against fall. To balance this is robot you have to configure the PID values till the robot attains stable position and recovering ability.

to make this task simple code uses ready made library for Arduino PID. For adjusting PID according for your design you have to manually enter P, I, D values and check for stability by uploading code to arduino in the following section of the code in above shown image.

the method to do this is first set Ki, Kd both 0, then put values for Kp then upload the code. after several attempts the robot remains balanced for some time but roll over performing oscillations , this is the time when you have to set Kd value without disturbing Kp value. set Kd so that the minimum oscillations take place, after this adjust the Ki by manually just like other two.

moreover you can also set the setpoint values and offset for angles in above shown image. but it is not required in many cases and to set only when your gyroscope is having offsets.

after this trial and and error phase you will find suitable values for your robot. This process is bit tricky and sometimes it takes hours to find perfect value if you are beginner and new to control systems.

Uploading the Final Code and Powering

once the perfect values for PID are found, after setting in code upload it one last time.

now you can power the arduino nano from L298N. after reseting, hold in up straight position for a while. During this time MPU-6050 will calibrate. once done you are ready with your robot.

Conclusion

After connection all connections and uploading code the robot will be able to balance it self using an MPU sensor and Arduino Board.