Self Balancing Robot

Download as pdf or txt
Download as pdf or txt
You are on page 1of 40

SELF BALANCING ROBOT

A Project Report Submitted

by

MANISHA RAHAGDALE (2110121372525)


ARPAN CHOUDHARI (2110121372526)
PAVAN WAKHARE (2110121372529)
SNEHA INGOLE (2110121372531)

In Partial Fulfilment
of the Requirements for the award of the degree

BACHELOR OF TECHNOLOGY

DEPARTMENT OF ELECTRONICS AND


TELECOMMUNICATION ENGINEERING
GOVERMENT COLLEGE OF ENGINEERING YAVATMAL
Academic Year: 2022-23
CERTIFICATE

This is to certify that the thesis titled SELF BALANCING ROBOT, submitted by
Manisha Rahagdale(58), Arpan Choudhari(59), Pavan Wakhare(62) and Sneha
Ingole(64) , to the Government College of Engineering, Yavatmal, for the award of the
degree of Bachelor of Technology, is a bona fide record of the research work done by
him under our supervision.

Prof. Yogesh Chaudhari


Supervisor
Professor
Dept. of Electronics and Telecommu-
nication Engineering
GCOEY, 445001
Prof. Prachi Bhagat
Head of Department
Professor
Dept. of Electronics and Telecommu-
nication Engineering
GCOEY, 445001
Dr. P.M. Khodke
Principal
Dept. of Electronics and Telecommu-
nication Engineering
GCOEY, 445001

Place : Yavatmal
Date: ..../12/2022
ACKNOWLEDGEMENTS

It gives us immense pleasure on bringing out the Mini-Project report entitled “ SELF
BALANCING ROBOT”.We express our sincere gratitude to Prof. Yogesh Chaud-
hari, Project Guide and to Prof. P.H. Bhagat, Head of Department. We thank them
for extending the necessary help, providing facilities and time to time guidance and
motivation. Their suggestions always motivated us for putting the best efforts on our
studies during the progress of the project. We would like to specially thank entire staff
members of Electronics and Telecommunication Department for providing us all the
laboratory and library facilities during the project duration.

We would also like to thank Dr. P.M. Khodke, Principal, Government College of En-
gineering, Yavatmal and the people who directly or indirectly helped me in completing
this task successfully.

1
ABSTRACT

To make a robot which can balance itself on two wheels. There will be only one axle
connecting the two wheels and a platform will be mounted on that .There will be a
another platform above it. The platform will not remain stable itself.Our job will be to
balance the platform using distance sensors and to maintain it horizontal. At first we
have decided to just balance the robot on its two wheels .If the platform inclines then
microcontroller(in this case it is Arduino) will send signals to motors such that motors
would move forward or backward depending on the inclination direction and extent.So
if the platform tilts forward then motors will run forward and viceversa to keep the
platform horizontal.For this we will need to code the Arduino in order to perform job
according to this.

2
TABLE OF CONTENTS

ACKNOWLEDGEMENTS 2

ABSTRACT 3

LIST OF TABLES 6

LIST OF FIGURES 7

1 INTRODUCTION 8
1.1 Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 Concept of stability . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.3 Project Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

2 LITERATURE REVIEW 10
2.1 Origin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.2 Literature review . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3 COMPONENTS 14
3.1 Hardware development . . . . . . . . . . . . . . . . . . . . . . . . 14
3.1.1 Arduino UNO . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1.2 Bo Motors . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.1.3 Motor driver L298N . . . . . . . . . . . . . . . . . . . . . 16
3.1.4 IMU Sensor MPU-6050 . . . . . . . . . . . . . . . . . . . 17
3.1.5 Wheel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.2 Software used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

4 WORKING 21
4.1 Block Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.3 Calibration Of Mpu-6050: . . . . . . . . . . . . . . . . . . . . . . 24
4.4 PID Concept for Self Balancing Robot: . . . . . . . . . . . . . . . 24

3
4.5 Tuning Of PID Values : . . . . . . . . . . . . . . . . . . . . . . . . 25
4.6 Working of Self balancing Robot: . . . . . . . . . . . . . . . . . . 26
4.7 Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27

5 APPLICATION 36
5.1 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.2 Advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.3 Disadvantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.4 Bill of Components . . . . . . . . . . . . . . . . . . . . . . . . . . 37

6 CONCLUSION 38
6.1 Conclusion: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.2 Future Improvement . . . . . . . . . . . . . . . . . . . . . . . . . 38
6.3 References: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
LIST OF TABLES

Table no. Table Name Page


No.

Table 4.1 Pin Configuration of Arduino Uno to MPU 22


6050 and L298N

Table 5.1 Bill of Components 36

5
LIST OF FIGURES

Figure no. Figure Name Page


No.

Figure 2.1 Realization of Mini Segway Robot Using NI 10


MyRIO

Figure 2.2 Double Self-balancing Robot 10

Figure 2.3 Self-balancing Robot With Remote Control 11

Figure 2.4 Self Balancing Robot 12

Figure 3.1 Arduino UNO 14

Figure 3.2 Bo Motors 15

Figure 3.3 L298 Motor Driver Module 16

Figure 3.4 MPU6050 sensor 17

Figure 3.5 Wheel 17

Figure 3.6 A View of Arduino IDE Software 19

Figure 4.1 Block Diagram for Self Balancing Robot using 20


Arduino

Figure 4.2 Circuit Diagram for Self Balancing Robot using 21


Arduino

Figure 4.3 System Representation of the Self Balancing 25


Robot using Arduino

Figure 4.4 Output Module of Self Balancing Robot 25

6
CHAPTER 1

INTRODUCTION

1.1 Motivation

In today’s era, whenever was talk about technological advancements and the resulted
automation in our lives, the first thing that comes in our minds is the recent develop-
ments in field of electronics and the better, faster, efficient and smart machines and
robots it has created. We desire for machines with smart thinking, self-sustaining and
decision making capabilities. We want better robots which can automate the entire work
chain in a company, which can replace a human workforce. Such is the desire for opti-
mized systems that today we prefer wheeled robot over two-legged humanoid robot for
having faster navigation capability, and among that we prefer two-wheeled robot over
three/four-wheeled robot for having compact design and faster movement speed.

Also, since the introduction of commercial Segway vehicles, two-wheeled selfbalanc-


ing robot has become a popular area of interest for researchers for its vast possibilities
to be used for

1] Means of accident free, environment friendly local transportation.

2] Self-balancing wheelchairs for disabled patients.

3] Compact and efficient robots to be used in hotels, warehouses, etc.

4] And many more areas of application.

All these offered challenges and the vast area of possible applications by a twowheeled
self-balancing robot were the major driving force behind me choosing this project.

7
1.2 Concept of stability

A two-wheeled robot is basically an inverted pendulum system, with its body acting
as an inverted pendulum (has natural tendency to fall down under gravity) pivoted on
wheels’ axis. In order to keep the robot stable, its center of mass should lie just above
the wheels’ axis. Since the robot is free to move in only forward and reverse directions,
the control system on robot should move the wheels in the same direction that of the
falling robot, so that an opposite torque can be applied on robot body which can oppose
the falling motion. In this way, the robot can keep balancing itself. The speed with
which the wheels should move will depend on various parameters like angle of tilt,
falling velocity, direction of motion (straight forward and backward linear motion, or,
rotational motion while taking turns), etc. This is where the effectiveness of control
systems come in picture. The more accurate and responsive control system is, more
will be the resulted stability of system.

1.3 Project Objective

Our aim is to design and fabricate a two-wheeled self-balancing robot with the help of
PID control system. An IMU sensor, which combines gyroscope and accelerometer,
will be used to continuously measure angle, direction and velocity of tilt of robot, and
will send this data to microcontroller, which in turn, through motor controller, will give
command to stepper motors to move in the same direction that of the tilt. It will exert
an opposite torque to the body of robot, which in turn will counter the falling action
and will stabilize the system by bringing back the center of gravity of robot just above
the wheels. The robot will be able to balance itself in the mean position while taking
turns, and even will be able to stabilize itself quickly when destabilized by an external
force/blow/jerk. Also, a Bluetooth device will be added to run the robot with help of
joystick.

The ultimate goal to achieve will be fabricating a low cost, compact, two-wheeled self-
balancing robot with PID controller which can balance itself with utmost precision and
responsiveness.

8
CHAPTER 2

LITERATURE REVIEW

2.1 Origin

From the beginning of development of robots, humans had been obsessed with hu-
manoid robots, which can look, walk, talk and function like an actual human being. But
a humanoid robot is very difficult to make because of its higher degree of freedom. So,
slowly the researchers have drifted from legged robots to wheeled robots because of
much lesser complexity offered by them due to their lesser degree of freedom. Among
these wheeled robots, 3 or 4 wheeled robots are easier to fabricate and operate because
of easier balancing; but they are bulkier than two-wheeled robots. Two wheeled robots
are much compact and faster, but they are difficult to balance because of their naturally
unstable state.
For many years, two-wheeled self-balancing robot has been a major area of interest for
researchers due to the opportunities and challenges it poses. They are trying to develop
different balancing techniques with the help of different methods, controllers, sensors
and filters to achieve a fast, responsive and stable system. The higher will be the relia-
bility of the system, higher will be chances to commercialize that technique.

2.2 Literature review

The autonomous balancing robot was made by Christian Sundin and Filip Thorstens-
son in 2012. This project was designed to build a two-wheeled upright robot. It uses
distance sensor in combination with a temperature sensor which makes it possible to
distinguish a living being from an object. The robot also has a bowl on top for carrying
a load. It was not possible to implement the LQG controller with a Kalman observer so
it was not able to make it move. The LQG controller failed when implemented due to
many reasons but one primary reason is Arduino was not enough fast to do calculations
for the LQG controller in the required loop time

9
Fig 2.1. Realization of Mini Segway Robot Using NI MyRIO

Y. X. Mak created Realization of Mini Segway Robot Using NI MyRIO in 2015.This


project was designed to build a two-wheeled upright robot. It uses myRIO as a hardware
platform. The reference generator is not working ideally, but the accuracy compared to
the supplied joystick signal is sufficient. The stabilization controller and the steering
controller is working as expected. While the final system is not tested through a proper
methodology, the controller is able to make the robot stabilize itself and sufficiently
able to follow the reference input given.

Fig 2.2. Double Self-balancing Robot

10
Muhammad Faizan Hasnain Raza and Ahmed Raza designed Double Self-balancing
Robot in 2016. For the first bot, they took acrylic sheets for creating the base of the
first bot, and on that base, they placed a lithium-ion battery on it. they placed one more
sheet also with the help of a separator for making the roof of the first bot. So that their
second bot can be placed on that roof of the first one. It was illustrated that the DSB
robot that is capable of balancing one robot onto another and can follow the desired
trajectory is realized. These robots can make a balanced and controlled body in the first
part and after making the fusion they will produce one single controlled by balancing
one robot onto another.

Abdul Gafar created Self-Balancing Robot in 2017. This project presents an attempt
on developing an autonomous self-balancing robot. A key element in maintaining the
robot in the upright position is estimation of the tilt angle. For this, the Kalman Filter
has been implemented and tested to fuse data from a gyroscope and an accelerometer.
The robot not balancing is certainly a large limitation of the project. The focus was
control and data fusion, hardware selection was rushed and an aside which caused the
need to have to change battery position and the wheels. Furthermore, the motors were
found to have significant backlash

Fig 2.3. Self-balancing Robot With Remote Control

11
Vinita Kumari designed Fabrication And Testing Of Self-balancing Robot With
Remote Control in 2019.The aim is to design and fabricate a two-wheeled self-balancing
robot with the help of PID control system. Also, a Bluetooth device will be added to run
the robot with help of joystick. The robot is giving proper response to the instructions
given by the remote control. The maximum zone (-25 degree to +38 degree tilt angle) in
which the robot is able to balance itself without any external help, is analyzed properly.

Fig 2.4. Self Balancing Robot

Mr. G. Chandrasekar, Lenin S. A., Rahul S., Sanjay C.andReshma R created Self
Balancing Robot in 2021. This project was designed to build a two-wheeled upright
robot. . It would be a fully automatic system that will vary its direction and position
using open source micro-controller Arduino NANO and MPU6050 the balancing of
robot, motor drive with quite high rpm and sensors. It can used to detect the object
more quick and respond fast unlike general self balancing robot this is next step of
modification and can able to move and avoid the obstacle and move forward as well as
backward, and follow the object by clicking the button and also be controlled by remote
or mobile

12
CHAPTER 3

COMPONENTS

3.1 Hardware development

The hardware system designing is the building block of any project.To design a robot
we need a microcontroller that acts as the brain of the robot where the required code
can be written to control all the electronics components of the robot so that they can
work in a synchronized way to achieve the goal. To fulfill microcontroller’s need here
we selected one Arduino uno board for the robot, now to for balancing purpose we
need to find the angle of tilt, displacement and velocity of the robot. For this task we
need an IMU sensor, so we have selected MPU6050 as IMU sensor which takes these
readings from the device.

Since it is a two wheeled robot, so obviously we will need two well griped wheels
and to make rotate these wheels, motors will be needed. Here we have taken two bo
motors because it is very precise and helpful in balancing activities. Now to control the
direction and speed of motor we need a motor driver that can guide the motors about
the direction and speed of movement. . Since we have taken bo motors so we will need
motor driver L298N

To supply power to the robot circuitry we need a power source and I have selected
a rechargeable Li-ion battery for this purpose because it is cost efficient and we can be
free from again and again replacement of the battery.

13
3.1.1 Arduino UNO

The main microcontroller used to balance the robot is Arduino UNO. It can be con-
sidered as the brain of the SBR. There are many microcontrollers like PIC series, AVR
series, 8051, raspberry, etc. available in the market, but We have selected the Arduino
because it is comes with a complete package which includes 5V regulator, an oscillator,
a microcontroller, serial communication interface, LED, a burner and headers for the
connection, which makes it very easy in use and very simple to assemble components
with it. It is an open source prototyping platform i.e. the board can be easily modified
and optimized for better functionality. It easily scales between different members of
the family. Its software has many available libraries and functions which makes it easy
to do its coding even for beginners.The Arduino UNO is mainly based on AVR micro-
controller Atmega328 and it comes with 6 analog input pins, USB interface and 14 I/O
digital ports out of which 6 pins can be used for PWM output. These I/O digital pins
can be used to connect it with external electronics circuits. In the SBR it is connected
with the IMU sensor to get the tilt angle information and after processing the data it
communicates with the motor drivers with the instructions of speed and direction of the
motor adjustments.

Fig 3.1. Arduino Uno

14
3.1.2 Bo Motors

Bo motor which is used as an actuator in the self-balancing robot. There are different
motors like DC geared motor, servo motor, etc. are available for use in the market but I
preferred to use bo motor for this project.Bo motor (Battery Operated) is a lightweight
DC geared motor that produces high torque and rpm at low voltages.

Fig 3.2. Bo Motors

3.1.3 Motor driver L298N

This L298N Motor Driver Module is a high power motor driver module for driving
DC and Stepper Motors. This module consists of an L298 motor driver IC and a 78M05
5V regulator. L298N Module can control up to 4 DC motors, or 2 DC motors with direc-
tional and speed control. The L298N Motor Driver module consists of an L298 Motor
Driver IC, 78M05 Voltage Regulator, resistors, capacitor, Power LED, 5V jumper in
an integrated circuit.78M05 Voltage regulator will be enabled only when the jumper is
placed. When the power supply is less than or equal to 12V, then the internal circuitry
will be powered by the voltage regulator and the 5V pin can be used as an output pin
to power the microcontroller. The jumper should not be placed when the power supply
is greater than 12V and separate 5V should be given through 5V terminal to power the
internal circuitry.

15
Fig 3.3. L298N Motor Driver Module

3.1.4 IMU Sensor MPU-6050

IMU (Inertia Measurement Unit) sensor is an electronics device which is used to


measure velocity, acceleration, orientation, displacement and other motion features.
There are a number of IMU sensors like ITG 3200 gyroscope, ADXL 345 accelerom-
eter etc. available in the market but I have selected to use MPU6050 it consists of
both gyroscope and accelerometer on a single chip. The MPU-6050 is the most accu-
rate, cheaper and reliable IMU sensor. It is MEMS (Micro ElectroMechanical System),
which consists of 3-axis gyroscope, 3-axis accelerometer and DMP (Digital Motion
Processor) embedded inside a single chip. MPU6050 consists a 16-bit ADC hardware,
due to which it is able to capture x, y and z axes motion at the same time with high
accuracy. It operates on I2C communication protocol to interface with an Arduino.

The MPU6050 sensor also contains a 1024 byte FIFO buffer, where sensor values can
be placed and read by the Arduino. This buffer is used in combination with the interrupt
signal so that Arduino knows when to read data from the sensor module.There is an INT
(interrupt pin) in the MPU6050 module which provides interrupt or instructions to the
Arduino only when the sensor values changes.

16
Fig 3.4. MPU6050 sensor

3.1.5 Wheel

The selection of wheels is the important part in development of a proper balanced robot.
The wheels should have a good grip over a floor which we are using so that it can
efficiently stand with the weight of robot and can reduce the chance of falling down of
the robot. I have used two wheels of 6.5cm diameter (with tyre its diameter is 7cm).
There is a rubber tyre on the outer circumference of wheel which helps it to get good
grip. It was preferred to use moderate size wheel in order to get satisfactory center of
mass of the robot and also to properly notice the robot’s balancing movement. It is very
important that wheels should not skit the floor, otherwise it will be very hard to reach
balanced condition of the robot.

Fig 3.5. Wheel

17
3.2 Software used

Arduino IDE (Integrated Development Environment) is an official Arduino software


which is mainly used for writing, compiling and uploading the sketch or code into
the Arduino modules. It is an open source software and easily available for various
operating systems like Windows, MAC, Linux. It runs on the Java platform which
comes with many inbuilt commands and functions that play an important role in editing,
compiling and debugging the code in the environment. Arduino IDE supports both C
and C++ languages and the main code written in this software is known as a sketch.
IDE generates a HEX File from the sketch and transfer and upload it into the controller
of the Arduino board. The IDE mainly consists of two basic parts: Editor which is used
for writing the required code and Compiler which is used for compiling and uploading
the sketch into the given Arduino device.

The Arduino IDE environment can be mainly divided into three sections:

1. Menu bar

2. Text editor

3. Output pane

Menu bar has five different options i.e. file, edit, sketch, tools and help, and six buttons
which are verify, upload, open, new, serial monitor and save. These are used in creating
a new file, writing, editing, saving, verifying, compiling and uploading a sketch. Text
editor is used to write required sketch and output pane displays the compilation status
of the running code i.e. the errors occurred in the sketch and the memory used by the
program. It is necessary to fix those errors before burning the hex file into the given Ar-
duino device. There are many preinstalled libraries provided by Arduino IDE software
which adds much extra functionality into the Arduino device. The commands used in
the sketch writing in IDE environment are case sensitive.

18
Fig 3.6. A View of Arduino IDE Software

19
CHAPTER 4

WORKING

4.1 Block Diagram

Fig 4.1. Block Diagram for Self Balancing Robot using Arduino

4.2 Circuit Diagram

The connections for this Arduino based Self balancing Robot is pretty simple. This is a
self balancing robot using Arduino and MPU6050 so we need to interface the MPU6050
with Arduino and connect the motors though the Motor driver module. The whole set-
up is powered by the 7.4V li-ion battery. The circuit diagram for the same is shown
below.

20
Fig 4.2. Circuit Diagram for Self Balancing Robot using Arduino

The Arduino and the L298N Motor driver module is directly powered through the Vin
pin and the 12V terminal respectively. The on-board regulator on the Arduino board
will convert the input 7.4V 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
7.4V positive wire from battery to 12V input terminal of motor driver module. This will
make the motors operate with 7.4V. The following table will list how the MPU6050 and
L298N motor driver module is connected with Arduino.

21
Table No 4.1: Pin Configuration of Arduino Uno to MPU 6050 and L298N

Sr.No Component Pin Arduino Pin

MPU6050

1. Vcc +5V
2. Ground Gnd
3. SCL A5
4. SDA A4
5. SINT D2

L298N

1. IN1 D6
2. IN2 D9
3. IN3 D10
4. IN4 D11

The MPU6050 communicates with Arduino through I2C interface, so we use the SPI
pins A4 and A5 of Arduino. The BO motors are connected to PWM pins D6,D9 D10
and D11 respectively. We need to connect them to PWM pins because we will be
controlling the speed of the DC motor by varying the duty cycle of the PWM signals.

22
4.3 Calibration Of Mpu-6050:

It is done for obtaining the offset values when the robot is in erect position. The robot is
set parallel to ground plane. This position of the robot is called balancing position. The
set of offset values are then taken such as Ax, Ay, Az and Gx, Gy, Gz (accelerometer and
gyroscope reference axis values).These values are kept as reference values. Whenever
an external disturbing forces comes into play, new set of offset values with respect to
reference axis will be formed. A feedback mechanism is provided which compares
the new set of values with initial reference values. Thus the position of robot from
balancing position is determined. The angle of tilt can be corrected by controlling dc
gear motors/Bo Motors thereby maintaining balance.

4.4 PID Concept for Self Balancing Robot:

1. PID stands for :

P : Proportional

I : Integral

D: Derivative

2. Proportional:This is also called as proportional gain and denoted by "Kp".The


proportional gain Kp is directly proportional to error. A small change in Kp would
automatically be reflected in the error values. Small values of Kp would be insufficient,
since the controller might not be able to minimise the error and quickly respond to the
changes affecting the system. Large values of Kp cause the system to be unstable and
result in weird oscillations.You can look at the image above for the formula of "Kp".

3. Integral: This is also called as integral gain and is denoted by "Ki".The integral
gain Ki accounts for the past values of the error and integrates them over time to pro-
duce the Ki term. i.e., the integral term lets the controller to take up all the errors that
are accumulating over time and creates the next Ki value depending on the previous
errors.A larger Ki value results in higher growth of the accumulated error.You can look
at the image above for the formula of "Ki".

23
4. Derivative This is also called as Derivative gain and is denoted by "Kd"..The
derivative gain Kd estimates the future trend of the error based on the current rate of
change of error. i.e., it controls the error by analysing the rate of change of error. This
helps to dampen the system, thus improving stability. The change in the system will
be rapidly evident with smaller change in Ki.You can look at the image above for the
formula of "Kd".

5. Error : it is the difference between the desired position and obtained position of
the Robot. It is given by:

Error(E) = Desired Position - Actual Position

4.5 Tuning Of PID Values :

There are many ways by which Kp, Ki and Kd values of the system is tuned one of
which is manual tuning through which stability can be easily achieved. Initially the Kp,
Ki and Kd values are set to zero. Then Kp value is increased from zero till a point where
the system starts to oscillate from its mean position.

As the Kp value is increased, it was seen that response of the system increase grad-
ually. Keeping the Kp value a constant the Ki value is then increased till a point where
it is seen from the system that a small inclination towards a direction tends to accelerate
the vehicle towards that direction. When the Kp and Ki values are properly obtained,
then the Kd value is increased. The Kd value is increased such that rapid acceleration
is reduced considerably.

Proper KD value results in lesser overshoots and oscillations. After obtaining the rough
Kp, Ki and Kd values a fine tuning is done. The above steps are repeated a number of
times to obtain the best combination of gain value.

24
Fig 4.3. System Representation of the Self Balancing Robot using Arduino

4.6 Working of Self balancing Robot:

1]As soon as power is supplied to the Robot the mpu 6050 supplies the values of AX,
AY, AZ, GX, GY, GZ to arduino.
2]Arduino computes "Kp", "Ki" and "Kd" with the formulas mentioned above and
calculates the absolute error between the desired position and position obtained.
3]Depending upon the "Error" Robot moves forward or backward which results in bal-
ancing of the Robot.

Fig 4.4. Output Module of Self Balancing Robot

25
4.7 Code

# i n c l u d e " I2Cdev . h "


# i n c l u d e <PID_v1 . h>
# i n c l u d e " MPU6050_6Axis_MotionApps20 . h "

MPU6050 mpu ;

/ / MPU c o n t r o l / s t a t u s v a r s

b o o l dmpReady = f a l s e ;
/ / s e t t r u e i f DMP i n i t was s u c c e s s f u l

uint8_t mpuIntStatus ;
/ / h o l d s a c t u a l i n t e r r u p t s t a t u s b y t e from MPU

uint8_t devStatus ;
/ / r e t u r n s t a t u s a f t e r each device o p e r a t i o n
(0 = success , !0 = e r r o r )

uint16_t packetSize ;
/ / e x p e c t e d DMP p a c k e t s i z e
( d e f a u l t i s 42 b y t e s )

uint16_t fifoCount ;
/ / c o u n t o f a l l b y t e s c u r r e n t l y i n FIFO

uint8_t fifoBuffer [64];


/ / FIFO s t o r a g e b u f f e r

// o r i e n t a t i o n / motion v a r s

26
Quaternion q ;
/ / [w, x , y , z ]
quaternion container

VectorFloat gravity ;
// [x , y , z]
gravity vector

f l o a t ypr [ 3 ] ;
/ / [ yaw , p i t c h , r o l l ]
yaw / p i t c h / r o l l c o n t a i n e r and g r a v i t y v e c t o r

/ * * * * * * * * * Tune t h e s e 4 v a l u e s f o r y o u r BOT * * * * * * * * * /
d o u b l e s e t p o i n t = 1 7 6 ; / / s e t t h e v a l u e when t h e b o t
i s p e r p e n d i c u l a r to ground using s e r i a l monitor .

d o u b l e Kp = 1 0 0 ;
d o u b l e Kd = 0 . 8 ;
d o u b l e Ki = 1 4 0 . ;

/ * * * * * * End o f v a l u e s s e t t i n g * * * * * * * * * /

double input , output ;


PID p i d (& i n p u t , &o u t p u t , &s e t p o i n t , Kp , Ki , Kd , DIRECT ) ;
v o l a t i l e bool mpuInterrupt = f a l s e ;
/ / i n d i c a t e s w h e t h e r MPU i n t e r r u p t p i n h a s gone h i g h

v o i d dmpDataReady ( )

{
mpuInterrupt = true ;
}

27
void setup ( ) {
S e r i a l . begin (115200);
// i n i t i a l i z e device

S e r i a l . p r i n t l n ( F ( " I n i t i a l i z i n g I2C d e v i c e s . . . " ) ) ;


mpu . i n i t i a l i z e ( ) ;

/ / verify connection

Serial . p r i n t l n (F(" Testing device connections . . . " ) ) ;


S e r i a l . p r i n t l n ( mpu . t e s t C o n n e c t i o n ( ) ?
F ( " MPU6050 c o n n e c t i o n s u c c e s s f u l " ) :
F ( " MPU6050 c o n n e c t i o n f a i l e d " ) ) ;

/ / l o a d and c o n f i g u r e t h e DMP

d e v S t a t u s = mpu . d m p I n i t i a l i z e ( ) ;

/ / s u p p l y y o u r own g y r o o f f s e t s h e r e , s c a l e d
f o r min s e n s i t i v i t y

mpu . s e t X G y r o O f f s e t ( 2 2 0 ) ;
mpu . s e t Y G y r o O f f s e t ( 7 6 ) ;
mpu . s e t Z G y r o O f f s e t ( − 8 5 ) ;
mpu . s e t Z A c c e l O f f s e t ( 1 6 8 8 ) ;
/ / make s u r e i t worked ( r e t u r n s 0 i f s o )

i f ( d e v S t a t u s == 0 )

{
/ / t u r n on t h e DMP, now t h a t i t ’ s r e a d y

S e r i a l . p r i n t l n ( F ( " E n a b l i n g DMP . . . " ) ) ;

28
mpu . setDMPEnabled ( t r u e ) ;
/ / e n a b l e Arduino i n t e r r u p t d e t e c t i o n

S e r i a l . p r i n t l n (F (" Enabling i n t e r r u p t d e t e c t i o n
( Arduino e x t e r n a l i n t e r r u p t 0)..."));

a t t a c h I n t e r r u p t ( 0 , dmpDataReady , RISING ) ;

m p u I n t S t a t u s = mpu . g e t I n t S t a t u s ( ) ;

/ / s e t o u r DMP Ready f l a g s o t h e main l o o p ( )


f u n c t i o n knows i t ’ s okay t o u s e i t

Serial . println
( F ( "DMP r e a d y ! W a i t i n g f o r f i r s t interrupt . . . " ) ) ;

dmpReady = t r u e ;
/ / g e t e x p e c t e d DMP p a c k e t s i z e f o r l a t e r c o m p a r i s o n

p a c k e t S i z e = mpu . d m p G e t F I F O P a c k e t S i z e ( ) ;

/ / s e t u p PID

p i d . SetMode (AUTOMATIC ) ;
p i d . S e t Sa m p l eT i m e ( 1 0 ) ;
pid . S e t O u t p u t L i m i t s ( −255 , 2 5 5 ) ;

else

29
/ / ERROR!
/ / 1 = i n i t i a l memory l o a d f a i l e d
/ / 2 = DMP c o n f i g u r a t i o n u p d a t e s f a i l e d
/ / ( i f i t ’ s g o i n g t o b r e a k , u s u a l l y t h e c o d e w i l l be 1 )

S e r i a l . p r i n t ( F ( "DMP I n i t i a l i z a t i o n f a i l e d ( code " ) ) ;


Serial . print ( devStatus ) ;
Serial . println (F ( " ) " ) ) ;
}

/ / I n i t i a l i s e t h e Motor o u t p u p i n s

pinMode ( 6 , OUTPUT ) ;
pinMode ( 9 , OUTPUT ) ;
pinMode ( 1 0 , OUTPUT ) ;
pinMode ( 1 1 , OUTPUT ) ;

/ / By d e f a u l t t u r n o f f b o t h t h e m o t o r s

a n a l o g W r i t e ( 6 ,LOW) ;
a n a l o g W r i t e ( 9 ,LOW) ;
a n a l o g W r i t e ( 1 0 ,LOW) ;
a n a l o g W r i t e ( 1 1 ,LOW) ;
}

void loop ( ) {

// i f programming f a i l e d , don ’ t t r y t o do a n y t h i n g

i f ( ! dmpReady ) r e t u r n ;

/ / w a i t f o r MPU i n t e r r u p t o r e x t r a p a c k e t ( s ) a v a i l a b l e

30
w h i l e ( ! m p u I n t e r r u p t && f i f o C o u n t < p a c k e t S i z e )

{
/ / no mpu d a t a − p e r f o r m i n g PID c a l c u l a t i o n s
and o u t p u t t o m o t o r s

p i d . Compute ( ) ;

/ / P r i n t t h e v a l u e o f I n p u t and O u t p u t on s e r i a l
m o n i t o r t o c h e c k how i t i s w o r k i n g .

S e r i a l . p r i n t ( i npu t ) ; S e r i a l . p r i n t (" = >");


Serial . println ( output ) ;

i f ( i n p u t >150 && i n p u t < 2 0 0 ) { / / I f t h e Bot i s f a l l i n g


i f ( output >0) / / F a l l i n g towards f r o n t
Forward ( ) ; / / Rotate the wheels forward
e l s e i f ( ou tp u t <0) / / F a l l i n g towards back
Reverse ( ) ; / / R o t a t e t h e wheels backward
}

e l s e / / I f Bot n o t f a l l i n g
Stop ( ) ; / / Hold t h e w h e e l s s t i l l
}

/ / r e s e t i n t e r r u p t f l a g and g e t INT_STATUS b y t e

mpuInterrupt = false ;
m p u I n t S t a t u s = mpu . g e t I n t S t a t u s ( ) ;

/ / g e t c u r r e n t FIFO c o u n t

31
f i f o C o u n t = mpu . g e t F I F O C o u n t ( ) ;

/ / check f o r overflow
( t h i s s h o u l d never happen u n l e s s our code i s too i n e f f i c i e n t )

i f ( ( m p u I n t S t a t u s & 0 x10 ) | | f i f o C o u n t == 1 0 2 4 )

{
/ / r e s e t s o we c a n c o n t i n u e c l e a n l y

mpu . r e s e t F I F O ( ) ;

S e r i a l . p r i n t l n ( F ( " FIFO o v e r f l o w ! " ) ) ;

/ / o t h e r w i s e , c h e c k f o r DMP d a t a r e a d y i n t e r r u p t
( t h i s s h o u l d happen f r e q u e n t l y )
}

e l s e i f ( m p u I n t S t a t u s & 0 x02 )

{
/ / wait for c o r r e c t a v a i l a b l e data length ,
s h o u l d be a VERY s h o r t w a i t

while ( fifoCount < packetSize )


f i f o C o u n t = mpu . g e t F I F O C o u n t ( ) ;

/ / r e a d a p a c k e t from FIFO

mpu . g e t F I F O B y t e s ( f i f o B u f f e r , p a c k e t S i z e ) ;

/ / t r a c k FIFO c o u n t h e r e i n c a s e t h e r e

32
is > 1 packet available
/ / ( t h i s l e t s u s i m m e d i a t e l y r e a d more
w i t h o u t w a i t i n g f o r an i n t e r r u p t )

f i f o C o u n t −= p a c k e t S i z e ;
mpu . d m p G e t Q u a t e r n i o n (&q , f i f o B u f f e r ) ;
/ / get value for q
mpu . d m p G e t G r a v i t y (& g r a v i t y , &q ) ;
/ / get value for gravity
mpu . d mp Ge t Ya wP i tc hR ol l ( ypr , &q , &g r a v i t y ) ;
/ / get value f o r ypr
i n p u t = y p r [ 1 ] * 1 8 0 / M_PI + 1 8 0 ;
}
}

v o i d F o r w a r d ( ) / / Code t o r o t a t e t h e w h e e l f o r w a r d

{
analogWrite (6 , output ) ;
analogWrite (9 ,0);
analogWrite (10 , output ) ;
analogWrite (11 ,0);
Serial . print ("F "); / / Debugging i n f o r m a t i o n
}

v o i d R e v e r s e ( ) / / Code t o r o t a t e t h e w h e e l Backward

{
analogWrite (6 ,0);
analogWrite (9 , output * −1);
analogWrite (10 ,0);
analogWrite (11 , output * −1);
S e r i a l . p r i n t ("R " ) ;

33
}

v o i d S t o p ( ) / / Code t o s t o p b o t h t h e w h e e l s

{
analogWrite (6 ,0);
analogWrite (9 ,0);
analogWrite (10 ,0);
analogWrite (11 ,0);
Serial . print ("S ");
}

34
CHAPTER 5

APPLICATION

5.1 Application

1. Self-balancing unicycle, a self-powered unicycle that balances itself in three dimen-


sions.

2. Monocycle Is The World’s First Self Balancing Bike: The Monocycle is a perfect
city bike that can be used for short distance travels and can be parked in the least avail-
able of spaces. Moreover, the bicycle comes with a strong electric motor to support the
riders, so they need not push too hard to speed up the bike.

3. Electric self-balance bike scooter/with Remote switch/balance bike: it’s a self bal-
ancing electric bike which balance itself on its two wheels.

5.2 Advantages

1. Self balancing system could balance in limited conditions without much complex
circuits.
2. The time taken to attain the stable position is done within less time and accuracy
after the load is being placed.
3. High accuracy
4. Low operating cost
5. Easy to use
6. Environment friendly

35
5.3 Disadvantages

1. To calculate Kp, Kd and Ki values are much more complex


2. To find the mathematical equation for model body is complex and hard

5.4 Bill of Components

Table No 5.1: Bill of Components

Component list

Sr.No Component Specification Price[Rs]

1. Arduino Uno ATmega328p 800


2. Bo Motors [2 nos] — 180
3. IMU Sensor MPU-6050 — 240
4. L298N Motor Driver Module — 180
5. Wheel [2 nos] — 90
6. Batteries [2 nos] — 160
7. Socket — 35

8. Total cost 1685

36
CHAPTER 6

CONCLUSION

6.1 Conclusion:

This project was successful in achieving its aim to balance a two-wheeled self balancing
robot. The control strategy called proportional integral derivative [PID] controller to
control the trajectory of the robot which calculates an error value.

6.2 Future Improvement

The stabilization provided by the reaction wheel is limited be the torque provided by
the reaction wheel motor. Subsequent plan is to use a rotating disc and its gyroscopic
precession for balancing. This would provide a more stable design capable of providing
higher restoring torque .In such a case particular attention should be paid to any rotary
axes, their alignment, and how they are fixed to the model, to the position and alignment
of brackets, and to the mounting and fastening of any flexible couplings. In addition to
this, fuzzy logic controller can also be implemented to provide flexibility and accuracy
in control.

37
6.3 References:
• essay.utwente.nlhttps://essay.utwente.nl › ...PDFRealization of Mini Segway Robot
Using NI MyRIO odr.chalmers.se

• https://odr.chalmers.se › bitst...PDFAutonomous balancing robot

• https://www.researchgate.net/publication/346644851 DOUBLE SELF-BALANCING


ROBOT idr.mnit.ac.in

• http://idr.mnit.ac.in › handlePDFFABRICATION AND TESTING OF SELF-BALANCING


ROBOT WITHCore.ac.uk

• https://core.ac.uk › pdfPDFSELF BALANCING ROBOT essay.utwente.nl

• http://idr.mnit.ac.in › handlePDFFABRICATION AND TESTING OF SELF-BALANCING


ROBOT WITH

• https://create.arduino.cc/projecthub/Varun2905/self-balancing-robot-525011

• https://circuitdigest.com/microcontroller-projects/arduino-based-self-balancing-robot

38

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy