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. They have a wide range of applications, from entertainment to industrial automation.

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.

Types of self-balancing robots

There are several types of self balancing robots.

  • One-wheeled balancing robots: These robots use a single wheel to balance. They generally have a compact design than two-wheeled robots.
  • Two-wheeled balancing robots: These are the most common type of self-balancing robots, and they use inverted pendulum technology to maintain their balance.
  • Three-wheeled balancing robots: These robots have three wheels and use the same techniques as two-wheeled robots to maintain their balance. They are more stable than two-wheeled robots but have a complex design.

Project

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

Arduino

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 does need not any breadboard for connection setup, so it can easily fit in a small chassis.

Motors

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

Wheels

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

Accelerometer

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

mpu6050 sensor

Steps to Assembly Self Balancing Robot Parts

Step 1: Assemble the Robot Chassis

The first step is to assemble the robot chassis using a premade robot kit or by building it from scratch. The chassis should be lightweight and sturdy with enough space to hold all the components.

Step 2: Connect the Motors to the Motor Driver

self balancing robot l298n motor driver

The next step is to connect the motors to the motor driver module. You need to connect both the positive and negative terminals of the dc motors to the motor driver module.

Step 3: Connect the Motor Driver to the Arduino

self balancing robot arduino uno

Connect the motor driver with the Arduino with the help of the circuit diagram given above. You need to connect the input pins of the motor driver to the digital pins of the Arduino.

Step 4: Connect the MPU6050 Accelerometer Sensor to the Arduino

self balancing robot mpu6050

The next step is to connect the MPU6050 accelerometer sensor to the Arduino. You need to connect the SDA and SCL pins of the MPU6050 to the corresponding pins of the Arduino which is shown on the circuit diagram.

Circuit Connection of Self Balancing Robot

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 a 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 are 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 it a professional look, I 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

Order PCB From PCBWay

I ordered the PCB prototype board from the www.pcbway.com 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 hobbyist.

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 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.

Applications of Self Balancing Robot

Self-balancing robots have a wide range of applications, including:

  • Entertainment: Self balancing robots are popular as toys and entertainment products, and they are often used in technical exhibitions and shows.
  • Industrial Automation: Nowadays self balancing robots are used in industrial automation for transporting goods, monitoring inventory, and performing other tasks.
  • Personal Transportation: Self balancing robots can be used as personal transportation, and they are replacing traditional bicycles and electric scooters in recent times.

Arduino Source Code for Self Balancing Robot

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.

Arduino-PID-Library

MPU6050 Library

Next the Arduino code for the self balancing robot

Conclusion

Self balancing robot is an amazing robotic technology that has a wide range of applications. From entertainment to industrial applications, these robots have the potential to revolutionize many industries. We hope that this project has given you a comprehensive guide to self balancing robots and their working principle.

FAQs

How does self balancing robot work?

Self balancing robot uses an accelerometer sensor to measure the robot’s angle and position, and a control system to adjust the motors and maintain its balance. The control system uses feedback loops to continuously adjust the robot’s position and keep it working.

What are the practical applications of self balancing robots?

Self balancing robots have a variety of practical applications, like education, research, entertainment, and transportation. They can be used for tasks such as carrying small loads, navigating difficult terrain, and performing precise movements.

Can I build my own self balancing robot?

Yes, there are many resources available for building your own self balancing robot, including online tutorials, kits, and open-source software.

Are self balancing robots expensive?

The cost of a self balancing robot can vary depending on its complexity and features. Some basic models can be built for a few dollars, while more advanced models can cost thousands of dollars.

2 thoughts on “Arduino Self Balancing Robot Using MPU6050 Accelerometer”

Leave a Comment