You are on page 1of 22

HCMC UNIVERSITY OF TECHNOLOGY AND

EDUCATION
FACULTY OF HIGH-QUALITY TRAINING

TOPIC:

AUTONOMOUS TWO-WHEEL
BALANCING ROBOT BY USING PID
Major: Advanced Automatic Control System
Lecturer: Nguyen Minh Tam

Student’s name Student’s ID


Trinh Nguyen Anh Hao 20151273
Nguyen Le Nhu Trong 20151298
Contents
Abstract......................................................................................................................3
CHAPTER I...............................................................................................................4
INTRODUCTION......................................................................................................4
I. Literature Review.............................................................................................4
II. Problem Statement.....................................................................................4
III. What is a self-balancing two-wheel robot?................................................5
IV. Project Objectives......................................................................................5
V. Project Scopes............................................................................................5
CHAPTER 2..............................................................................................................7
BACKGROUND.......................................................................................................7
I. MPU-6050 – Accelerometer and Gyroscope Module......................................7
1. Function of MPU-6050..............................................................................7
2. QUATERNION, YAW, PITCH, ROLL...................................................8
II. Arduino Nano V3.0 ATmega328P– Microcontroller board....................10
III. L298N – DC Motor Control....................................................................14
IV. Dual Axis TT Gear Motor.......................................................................16
Chapter 3:.................................................................................................................18
HARDWARE DESIGN...........................................................................................18
I. Wiring Diagram..............................................................................................18
II. Mechanical design....................................................................................18
CHAPTER 4 CONCLUSION AND FUTURE ORIENTATION...........................21
I. Conclusion......................................................................................................21
II. Future Orientation....................................................................................21
Reference..................................................................................................................22

1
Abstract
The project develops a two-wheeled autonomous self-balancing robot that can
maintain balance in predetermined locations. Arduino, the MPU6050 board, and
the L293D DC motor control are required for the experiment. The PID controller is
responsible for determining and maintaining the robot's position. After being put
through a series of tests in which its Kp, Ki, and Kd values were varied, the robot
has been given the ability to maintain its balance without the assistance of a human
being. Consequently, balancing is declared and demonstrated as proof for this
nonlinear and unstable system. By making adjustments to the output, the PID
controller reduces the error amount to its minimum possible level. MU6050 reads
the robot's current tilt and communicates that data to the PID algorithm, which
performs calculations to drive the motor and maintain the robot's upright position.

KEYWORD: Two-wheel robot, PID controller, Self-balancing.

2
CHAPTER I

INTRODUCTION
I. Literature Review
The concept of an autonomous balancing robot combines the self-balancing capacity of two
human legs with the maneuverability of an automobile. This paper will gather ideas on the
balance of humanoid robots, how to coordinate, and the optimal data processing from sensors.
However, Segway's products are not inexpensive because of the pricey sensors that have been
integrated and processed with great precision and dependability. Therefore, we will determine
how to combine single, less expensive sensors, and process their signals to store clean and
accurate signals.

The paradigm is a vehicle with two parallel vertical axes. We will utilize sensors to compute the
angle of inclination of the vehicle's body, the rotational velocity of the vehicle floor around the
wheel axle, and the vertical velocity of the vehicle. With these sensors, the car can maintain its
equilibrium and move autonomously. With this design, the paradigm's center will always be in
the supporting region to maintain balance when traversing basic and challenging terrain. The
representation in figure 1.1 is a real-world example of an autonomous balancing robot.

Figure 1.1: The real-life autonomous balancing robot

II. Problem Statement


The convenience and versatility of autonomous robots have led to increased demand for these
machines in the modern day. However, because every component in each robot is not
inexpensive, the method by which each device is combined is an extremely significant
consideration. In control theory, the inverted pendulum is a typical problem that needs to be
3
solved. In most cases, the pendulum is attached to a cart, and the movement of the cart is used to
control the pendulum's balance.

The purpose of this project was to construct a small robot that is capable of balancing itself
without the assistance of a person. For humans to more easily see a robot, it is designed to fit on a
table that is a more modest size.

III. What is a self-balancing two-wheel robot?

Figure 1.2: Describe the principle of balancing


[1] Maintaining balance and stability for three- or four-wheeled vehicles is dependent on the
wheels' capacity to maintain their center inside the base surface. For other two-wheeled vehicles
with a bicycle-like construction, maintaining balance when not moving at all is difficult, as the
robot's balance relies on the pendulum-like gyration of the two-wheels while they are in motion.
Also, for two-wheeled autonomously balancing robots, the robot's center must be at the wheel's
center for the robot to maintain balance. We can envision somebody balancing the chopstick on
their fingertip.
In actuality, the center of gravity of the entire scooter cannot be determined, and it may not be
possible to shift the wheel quickly enough to maintain it below the complete center of gravity.
The idea of balance is illustrated in Figure 1.2. When the steering wheel is gently leaned forward,
the robot will go forward, and when it is turned backward, it will move in reverse. This analysis
is logical.
IV. Project Objectives
The primary objective was to design and build a robot that will autonomously balance on two
wheels. Once the start button is pressed, the robot can move and balance on its own. The robot
should be portable and small enough to fit in the limited area given at an exhibition or in a
laboratory.

V. Project Scopes

In the earliest stages, the two-wheeled, self-balancing robot needs human assistance so it can
function properly. In addition, there are no detection sensors, which means that it cannot identify

4
subjects in front of it. It is not possible to put this product to use in a commercial or industrial
setting, hence it should only be utilized for individual research in a home setting

5
CHAPTER 2

BACKGROUND

I. MPU-6050 – Accelerometer and Gyroscope Module

Figure 2.1: MPU6050 Module(Left), MPU6050 Pinout(Right)


1. Function of MPU-6050
MPU-6050 is essentially a sensor for devices that process motion. It was developed to be a
wearable sensor with minimal cost and great performance. It performs nine-axis algorithms and
simultaneously records motion in the X, Y, and Z axes. In addition, the MPU-6050 contains a
Digital Motion Processor (DMP) capable of resolving any complicated computations. MPU-6050
is an excellent option for controlling the movements of a Drone or Self-Balancing Robot owing
to its compatibility with Arduino.
Table 1: Function Description of MPU-6050

Pin# Pin Name Description


01 Vcc This pin is used for Supply Voltage. Its input voltage is from +3 to +5V
02 GND This pin is used for ground
03 SCL This pin is used for clock pulse for I2C compunction
04 SDA This pin is used for transferring data through I2C communication.
05 Auxiliary Serial This pin is used for other interfaced other I2C modules with MPU-6050
Data (XDA)
06 Auxiliary Serial It can be used for other interfaced other I2C module
Clock (XCL)
07 AD0 If more than one MPU6050 is used a single MCU, then this pin can be used to
vary the address.
6
08 Interrupt(INT) This pin is used to indicate that data is available for MCU.

2. QUATERNION, YAW, PITCH, ROLL


a. Quaternion
[2] The term "quaternion" refers to the tool used in the spatial rotation process. In this section, we
will talk about its application in spatial rotation from a schematic standpoint.
Quaternion is defined as a complex number that has three imaginary components:
q = w + xi + yj + zk (1)
Do not consider a quaternion as a four-dimensional object. The imaginary components I j, and k
can be seen as three unit vectors along the x, y, and z axes. Moreover, a quaternion may be
rewritten as follows:
q=w+v (2)
where v is a three-dimensional vector and w is a scalar quantity that denotes magnitude
(constant).
Applied to spatial rotation. Assume that we have a vector with rotation-axis u vector u must be a
unit vector, its mean u2 x + u2 y +u2 z=1) and rotation θ (positive when rotating in the same
direction as the vector, according to the principle of holding the right hand), we will have a
rotating quaternion as follows [2]:
1 1 1 1
q = cos( θ) + usin( θ) = cos( θ) + (u x i+u y j+u z k ¿ sin( θ) (3)
2 2 2 2

For example, if I have a point P in space whose coordinates (a, b, c) are determined in space by
vector p = ai + bj + ck then the rotation of point P according to q is defined as:

p’ = qpq−1 (4)

where p’ is a P’s vector coordinates after rotating. And q−1 is inverse of q. Specifically, we have
the equation.
1 1 1 1−i− j−k
q ¿1= =cos θ−usin θ= (5)
q 2 2 2
In this case, the inverse equals the amount of conjugation resulting from the absolute value of the
quaternions in rotation equal to 1 [2].
b. Pitch movement

Pitch is a form of movement that refers to the movement of an aircraft's nose in either the upward
or downward direction. The movement of the plane's nose around its horizontal axis is referred to
as the pitch [2]. According to figure 2.2, it is now possible for us to have a better understanding
of how Pitch moves.

7
Figure 2.2. The pitch’s movement.

c. Roll movement
A roll is a form of motion that occurs when an airplane throws one of its wings while
simultaneously flinging the other. For instance, if the airplane is rolling to the left, the left wing
will sink, while the right wing would fling outward. The roll movement occurs around the
fuselage's vertical axis [2]. The motion of movement indicated in Fig 2.3 is quite easy for us to
visualize.

Figure 2.3. The Roll’s movement.

d. Yaw movement

8
Figure 2.4 illustrates the movement of the yaw, which occurs when the front of an airplane
rotates to the right or left. The movement of the yaw occurs along an axis that is vertical to the
fuselage and perpendicular to it [2].

Figure 2.4 The Yaw’s movement.

II. Arduino Nano V3.0 ATmega328P– Microcontroller board

Figure 2.5. Arduino nano

9
a. Arduino nano datasheet
Table 2: Arduino Nano Datasheet

Arduino Nano Specifications


Number of analog I/O pins 8
Structure AVR
Pulse rate 16 MHz
I/O consumption current 40mA
Digital I/O pins 22
EEPROM Memory 1 KB
Flash memory 32 KB of which 2 KB used by Bootloader
Input voltage (7-12) Volts
Microcontroller ATmega328P
Operating voltage 5V
Board size 18 x 45 mm
Sources of consumption 19mA

PWM output
6

SRAM 2KB

Weighed
7 gms

10
Figure 2.6 Detailed diagrams of Arduino nano

b. ATmega328P – microcontroller
[3] Arduino nano is compatible with three 8-bit AVR microcontroller families: ATmega8,
ATmega168, and ATmega328P. This brain is capable of doing simple tasks like operating a
flashing LED light, processing the signal for a remote-controlled car, constructing a temperature-
humidity monitoring station, and presenting the data on an LCD screen, etc.

11
Figure 2.7. Microcontroller ATmega328

c. I/O Pins

Figure 2.8 Pin diagram of the ATmega328P microcontroller

12
III. L298N – DC Motor Control

Figure 2.9 L298N Motor Driver Module Pinout


The L298 DC motor driver circuit is capable of driving 2 DC motors with a maximum current of
2A per motor, a protective diode IC, and a power IC 7805 to help supply 5VDC power to other
modules (only use this 5V if the power supply is less than 12VDC). The L298 DC motor control
circuit is user-friendly, inexpensive, and simple to install, making it the best option in its price
range.

a. L298N Module Pin Configuration.

Table 3: L298N configuration

Pin Name Description


IN1 & IN2 Motor A input pins. It’s used to control the spinning direction of Motor A
IN3 & IN4 Motor B input pins. It’s used to control the spinning direction of Motor B
ENA Enables PWM signal for Motor A
ENB Enables PWM signal for Motor B
OUT1 & OUT2 Output pins of Motor A
OUT3 & OUT4 Output pins of Motor B
12V 12V input from DC power Source.
5V Supplies power for the switching logic circuitry inside L298N IC
GND Ground Pin

13
b. L298N Module

L298N Motor Driver contains L298 Motor Driver IC, 78M05 Voltage Regulator, Resistors,
Capacitor, Power LED, and 5V jumper in an integrated circuit.

Figure 2.10: L298N Motor Driver components

The 78M05 Voltage Regulator will only be activated when the jumper is in place. When the
power source is less than or equal to 12V, the voltage regulator will power the internal circuitry,
and the 5V pin can be utilized to power the microcontroller. When the power source is more than
12V, the jumper should not be installed, and separate 5V should be supplied through the 5V
connector to power the internal circuitry.

14
Figure 2.11 Internal circuit diagram of L298N Motor

IV. Dual Axis TT Gear Motor.

Figure 2.12 Dual Axis TT Gear Motor.

15
DC brush motors are housed within this plastic gear motor. It can function with voltages ranging
from 3 to 6 VDC, and the rotational speed will change based on the voltage. This particular
engine type is the one that is most frequently employed for designing model robots, control
frames, boats, etc. for students to study, do research, and create.

Table 4. Specification of Dual Axis TT Gear Motor

Rotational Speed 200 rpm/6V, 90 rpm/3V


Voltage 3-6 Vdc
Rated Torque 2kgf.cm at 6 Vdc
No-load current 250 mA/6V, 150 mA/3V
Ratio 1:48
Current load 70 mA/3V

16
Chapter 3:

HARDWARE DESIGN
I. Wiring Diagram

Figure 3.1 Wiring Diagram.

II. Mechanical design


Before beginning Arduino programming for the robot, the robot's model must be finalized.
The 2-story circular frames were connected by four copper pillars with two wheels, which
were hooked to L298N – DC Motor Control on the first floor. Second, the accelerometer
MPU-6050 will be placed in an unobstructed location so that the robot may be readily
balanced. Thirdly, the Arduino Nano will be connected to the sensor for easier wiring. The
Input Voltage will then be connected in the center to make balancing the robot simpler. The
finished robot will be seen in Figures 3.2 and 3.3.

17
Figure 3.2 Top view of the robot.

18
Figure 3.3 Side view of the robot

19
CHAPTER 4
CONCLUSION AND FUTURE
ORIENTATION
I. Conclusion

The robot is not yet completely balanced well enough to be utilized. The robot was
not yet completely stable and required some assistance from a human.

II. Future Orientation

In the future, I plan to make an effort to enhance both the frame and my
understanding of the sensor, coding, and other related topics.

For instances:

- Line detector robot

- Remote control automobile

20
Reference
[1] Đỗ Triều Dương (2014): Design two-wheel self-balancing robot system. Available at:
http://tailieudientu.lrc.tnu.edu.vn/Upload/Collection/brief/brief_44464_48459_201120147
5559dotrieuduong.pdf (Accesses: 1st June, 2014)

[2] Bùi Quang Minh (2014): Quaternion and Space Rotation Method. Available at:
https://minhcly.wordpress.com/2014/01/30/quarternion-va-phep-quay-khong-gian-phan-
1/ (Accessed: 30th January, 2014)

[3]:Unknown (2020): L298N Motor Driver Module: Available at:


th
https://components101.com/modules/l293n-motor-driver-module ( Accessed: 13 April
2020)
[4]Unknown (2017): Two-wheel self-balancing robot. Available at:
http://arduino.vn/result/5473-robot-hai-banh-tu-can-bang-2-wheel-self-balancing-robot
(Accessed: 21st December 2017)

21

You might also like