Ho Chi Minh City University of Technology and Education
Faculty for High Quality Training
Automation and Control Engineering Technology
Line Following Robot
STUDENT REPORT
Supervisor
Assoc.Prof Le My Ha
Submitted by
Le Tran Vu Hoang
Nguyen Quoc Vinh
La Gia Bao
Hoang Duong
Trinh Nguyen Anh Hao
January 6th, 2021
Contents
Abstract ii
List of Figures iii
List of Tables iv
Assignment of work v
1 Overview 1
1.1 Introducing of line following robot . . . . . . . . . . . . . 1
1.2 Objective of Study . . . . . . . . . . . . . . . . . . . . . 2
1.3 General operating principles . . . . . . . . . . . . . . . . 2
1.4 Application of line following robot . . . . . . . . . . . . . 2
2 Hardware design and software design 4
2.1 Hardware design . . . . . . . . . . . . . . . . . . . . . . 4
2.1.1 Idea frame . . . . . . . . . . . . . . . . . . . . . 4
2.1.2 Select electronic appliances . . . . . . . . . . . . . 5
2.1.3 Cost estimation . . . . . . . . . . . . . . . . . . . 10
2.1.4 Circuit Diagram . . . . . . . . . . . . . . . . . . 10
2.2 Software design . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.1 A algorithm idea . . . . . . . . . . . . . . . . . . 11
2.2.2 Working principle of Sensor . . . . . . . . . . . . 12
2.2.3 Working principle of Line following robot . . . . . 12
2.2.4 Code . . . . . . . . . . . . . . . . . . . . . . . . 13
3 Results 18
3.1 Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1
3.2 Running results and review . . . . . . . . . . . . . . . . . 19
3.2.1 Running results . . . . . . . . . . . . . . . . . . . 19
3.2.2 Review . . . . . . . . . . . . . . . . . . . . . . . 19
4 Discussion 20
4.1 Advantage . . . . . . . . . . . . . . . . . . . . . . . . . 20
4.2 Disadvantage . . . . . . . . . . . . . . . . . . . . . . . . 20
4.3 Future work . . . . . . . . . . . . . . . . . . . . . . . . 20
5 Reference 21
i
Abstract
In this project, we develop the line following robot. Module L298N is chosen as the main
controller.Arduino uno R3 is the brain which control the robot.We use Closed Loop control
and PID control for this project.Dynamic PID control algorithm has been proposed to improve
the navigation reliability of the wheeled mobile robot which uses differential drive locomotion
system. The experimental results show that the dynamic PID algorithm can be performed
under the system real-time requirements.
ii
List of Figures
2.1 Line following car . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2 Arduino Uno R3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Module L298N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.4 Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.5 Motor V1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.6 Wheel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.7 Li-po battery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.8 Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.9 Working principle of sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.10 Working principle of line following robot . . . . . . . . . . . . . . . . . . . . . 13
3.1 Our line following car . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
iii
List of Tables
2.1 Parameter of Arduino Uno R3 . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Parameter of module L298N . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.3 Parameter of sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.4 Parameter of motor V1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.5 Parameter of Wheel V1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.6 Parameter of li-po battery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.7 Details of Price of components . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.8 Table of Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
iv
Assignment of work
Member Private work Work in pairs Work together
Nguyen Quoc Vinh Write code Present, write report
La Gia Bao and complete it Discuss report
Le Tran Vu Hoang Design in Solidworks by using LaTex and
Trinh Nguyen Anh Hao Design PowerPoint assemble hardware
Hoang Duong Buying electronic appliance
v
Chapter 1
Overview
1.1 Introducing of line following robot
Automation is a combination of many fields such as mechanics, control, information tech-
nology and mechatronics. These fields come together into systems that automate and, more-
over, automate the entire manufacturing process. Automation companies play an increasingly
important and essential role to meet economic development goals, especially in today’s fast-
moving work process. It asks a highly qualified human resource to operate. In the world
today, there are many types of robots: Large-scale such as: Machine arms in production lines,
automatic production systems. In addition are robots capable of moving, doing dangerous
jobs to replace humans, robots to help the elderly, sales robots ... etc. In this project I do the
line of detection robots, compared to the above robots. Just a small, simple robot, but this
is the foundation for me to make air conditioners, more useful in the process of learning and
doing of me after this. A line follower robot is basically a robot designed to follow a line or
path already pre determined by the user. This line or path may be as simple as a physical black
straight line on the floor or complex line: circle, the round number eight,zigzag... In order to
detect these lines, we use sensor system, it can be individual sensors connected together or
expansive vision systems with many sensors .The choice of these schemes is the key to decide
the speed, the accuracy in line detection.
1
1.2 Objective of Study
We looked up reference on the internet. And they did complete this project better than us. We
tried to do a robot must be capable of following a line:
• The robot must be capable of following a line.
• It must be multitasking ,should be capable of taking various degrees of turns.
• The robot must also be capable of following a line even if it has breaks.
• It must allow calibration of the line’s darkness threshold
• The robot must be insensitive to environmental factors such as lighting and noise.
1.3 General operating principles
The robot moves in a predetermined trajectory thanks to a guide, the two-wheel system is
driven by two DC electric motors through a control circuit and a power circuit. Often the
guides will have a different color from the background color of the moving trajectory. In
order for the robot to move on the right orbit, it is necessary to have a sensor, which is re-
sponsible for distinguishing the guide line and the background color of the moving trajectory.
In order for the robot to move in the right trajectory, it is necessary to have a sensor, which
is responsible for distinguishing the guide line and the background color, bringing the corre-
sponding electrical signal to the control circuit. The control circuit is responsible for receiving
feedback from the sensor, thereby controlling the speed and direction of rotation of two DC
electric motors so that the car always sticks and moves according to the guide.[1]
1.4 Application of line following robot
It is applied in technology detection lines such as automatic movement during transportation.
From the industrial point of view, line following robot has been implemented in semi to fully
autonomous plants. In this environment, these robots functions as materials carrier to deliver
products from one manufacturing point to another where rail, conveyor and gantry solutions
2
are not possible. Apart from line following capabilities, these robots should also have the ca-
pability to navigate junctions and decide on which junction to turn and which junction ignore.
This would require the robot to have 90 degree turn and also junction counting capabilities.
To add on to the complexity of the problem, sensor positioning also plays a role in optimizing
the robots performance for the tasks mentioned earlier. Line-following robots with pick- and-
placement capabilities are commonly used in manufacturing plants. These move on a speci-
fied path to pick the components from specified locations and place them on desired locations.
The control principle is still inertia, but the robot path is detected
3
Chapter 2
Hardware design and software design
2.1 Hardware design
2.1.1 Idea frame
In this project, we had a lot of ideas such as buying frame or designing a new frame. Then
we decided to make a new frame. We used Solidworks to do that. The first, we thought about
using screw to connect electronic appliances but it took a lot of time. So we decided use glue
to connect them. Because it’s very convenient and simple. We have referenced but we used
module L298N and Arduino Uno R3 so we can’t stack it. We designed a long frame to put
on electronic appliances. During the process, we had a problem. We forgot about position of
the sensor. To repair it, we used Solidworks to design two plates mica. And then, we used
glue to connect sensor with frame. Because we used a long frame so two wheels were not
unbalanced, so we used multi-purpose wheel to balance.
Figure 2.1: Line following car
4
2.1.2 Select electronic appliances
Arduino
Nowadays, we have many Arduino such as Arduino Mega R3, Arduino nano V3, Arduino
Leonardo,. . . but in this project we choose Arduino Uno R3.Uno is a great option. It has
many feature which we need for this project.
Table 2.1: Parameter of Arduino Uno R3
Microcontrollers ATmega328
Operating volt-age 5v
Operating frequency 16 MHz
Consumption stream 30mA
Recommended input voltage 7-12V - DC
Input voltage limit 6-20V - DC
Digital I/O pin number 14 (6 pins PWM)
Analog pin number 6 (10bit resolution)
Maximum current per I/O pin 30mA
Maximum out-put current (5V) 500mA
Maximum out-put current (3.3V) 50mA
Flash memory 32KB (ATmega328) with 0,5kb used by the bootloader
SRAM 2KB (ATmega328)
EEPROM 1KB (ATmega328)
This is a picture which we used Solidworks to draw model Arduino Uno R3
Figure 2.2: Arduino Uno R3
5
Module L298N
Module L298N can control 2 DC motors or 1 stepper motor. Because we used two wheels so
we need 4 holes located at 4 corners and L298N provided it for us. It is very convenient for
us. And we know there is an anti-heat heatsink for the IC, helping the IC to control the peak
current of 2A The L298N IC is attached to the on-board diodes to help protect the micropro-
cessor against the induced currents from starting or turning off the engine. It is very useful
Table 2.2: Parameter of module L298N
Driver L298N integration of two H-bridge circuits
Control voltage +5V ∼+12V
Maximum current per H bridge 2A
The voltage of the control signal +5V ∼7V
Line of control signals 0 ∼36Ma
Power dissipation 20W (when temperature T = 75 ° C)
Storage temperatures -25 ° C ∼+130
This is a picture which we used Solidworks to draw model L298N
Figure 2.3: Module L298N
6
Sensor
We decided used 5 sensors. We began with TCRT5000 but it is difficult because one TCRT5000
has one sensor. Then we used The 5-leds bar line detector. It is very convenient. It is designed
to detect black and white lines. On the sensor bar there are 5 infrared sensors pointing to the
ground to detect the line.
Table 2.3: Parameter of sensor
Operating voltage 3.3V ∼5V
Detection distance 0.5mm ∼40mm
Size 128 x 45 x 12mm
Sensor 5 line detection sensors
This is a picture which we used Solidworks to draw model sensor
Figure 2.4: Sensor
7
Motor
We discussed between motor V1 and motor GA25 12V620RPM. Motor GA25 12V620RPM
make from metal so it is better than motor V1 but it is more expensive than motor V1. We
reference on the internet and motor V1 is not bad. It is very suitable for this project. So we
decided to use motor V1 because this line following car is simple.
Table 2.4: Parameter of motor V1
Operating voltage 3 - 9VDC
Electrical current consumption 110 ∼140mA
Transmission ratio 1:48
When 3VDC 125 rotations / minute
When 5VDC 208 rotations / minute
Moment 0.8 KG.CM
This is a picture which we used Solidworks to draw model Motor
Figure 2.5: Motor V1
Wheel
In this project, we used 2 types: wheel V1 and multi-purpose wheel. Because our design
needs from 3 wheels to 4 wheels to balance so we used 3 wheels. If we used 4 wheels V1, it
would be difficult to code. Using 3 wheels is easy. It is the same as 2 wheels.
Table 2.5: Parameter of Wheel V1
Diameter of wheel 66mm
Tire thickness 6.5mm
Width wheels 27mm
Axle of vehicle 5mm
Width vacant of axle 3.66m
8
These are two picture which we used Solidworks to draw model wheel
(a) Wheel V1 (b) Multi-purpose wheel
Figure 2.6: Wheel
Battery
According assistant Mr. Cuong, Li – po battery ( lithium polymer battery ) is very good. They
are light weight and have improved safety. It can refresh so we just buy one time. We used 2
batteries for this project.
Table 2.6: Parameter of li-po battery
Voltage 3.7V
Capacity 500mAh
Size 50 x 30 x 3.5mm
This is a picture which we used Solidworks to draw model battery
Figure 2.7: Li-po battery
9
2.1.3 Cost estimation
The details of price of components used in project is given below
Table 2.7: Details of Price of components
S.N Particulars Quantum Rate per item (VND) Total (VND)
1 Arduino Uno R3 1 100.000 100.000
2 Module L298N 1 27.000 27.000
3 Sensor 1 52.000 52.000
4 Wheel V1 2 7.000 14.000
5 Multi-purpose wheel 1 15.000 15.000
6 Motor V1 2 10.000 20.000
7 Li-po battery 2 40.000 80.000
8 Wires 20 300 6000
9 Frame 1 25.000 25.000
Total 393.000
2.1.4 Circuit Diagram
We reference on the internet and then we assembled electronic appliances completely. This is
our circuit diagram.
Table 2.8: Table of Circuit Diagram
Arduino L298N Sensor
6 ENA
7 IN1
8 IN2
9 IN3
10 IN4
11 ENB
A0 S1
A1 S2
A2 S3
A3 S4
A4 S5
VCC VCC
GND GND
10
2.2 Software design
2.2.1 A algorithm idea
When the vehicle is operating, the sensor will collect information and convert it into an elec-
trical signal to the microcontroller. The received value will be compared with the preset value.
Based on the value of the sensor sent, determine the relative deviation between the orbit of the
robot and the desired trajectory, then compare that deviation into levels. Based on the devia-
tion levels, adjust the speed of the left and right wheels to return the robot to the fund religion.
Specifically, to turn left the robot’s right wheel speed is one value faster than the left one
correspond to the deviation levels (need to test many times), and vice versa. This method is
simple, but the robot runs unstable, sometimes very fast, sometimes slowly, Stability is highly
dependent on the robot’s motor and mechanical construction. To overcome this drawback, by
applying a position controller PID mind robot
Figure 2.8: Block diagram
11
2.2.2 Working principle of Sensor
One sensor head will emit infrared rays. If there are no obstacles, the infrared will continue.
The other end is the receiver that won’t get anything, it will return -1. In the case of an
obstacle, the infrared rays are reflected back, the receiver will obtain and return the value
0. In the case of a dark surface, the infrared rays will absorb all the returned infrared rays.
enough so the receiver returns 1.
(a) Principle sensor (b) Value sensor
Figure 2.9: Working principle of sensor
2.2.3 Working principle of Line following robot
If line is centered in front of robot, line following robot goes forward. When the center sensor
is high and the remaining sensor is low the center sensor is will always be on the line and as
line is black in color.
If line is right of center, the robot turns right. When the right sensor is high, the remaining
sensor is low and the center sensor is will always be on the line and as line is black in color.
If no line is detected, circle unit is found
12
If line is left of center, beside of the robot, it turns left. When the left sensor is high and the
remaining sensor is low the center sensor is will always be on the line and as line is black in
color.
Figure 2.10: Working principle of line following robot
2.2.4 Code
float Kp = 40, Ki = 0, Kd =160;
float error = 0, P = 0 , I = 0 , D = 0, PID_value = 0;
float previous_error = 0;
int sensor[6] = {0, 0, 0, 0, 0};
int gia_tri_ban_dau = 150;
int PID_phai, PID_trai;
#define In1 7
#define In2 8
#define In3 9
#define In4 10
#define ENA 6
13
#define ENB 11
void read_sensor_values(void); // doc gia tri cam bien
void calculate_pid(void); // tinh PID
void motor_control(void); // kiem soat dong co
void dung();
void chay_thang();
void setup()
pinMode (ENA, OUTPUT);
pinMode (ENB, OUTPUT);
pinMode (In1, OUTPUT);
pinMode (In2, OUTPUT);
pinMode (In3, OUTPUT);
pinMode (In4, OUTPUT);
Serial.begin(9600);
void loop()
read_sensor_values();
14
calculate_pid();
motor_control();
void read_sensor_values()
{ sensor[1] = digitalRead(A0);
sensor[2] = digitalRead(A1);
sensor[3] = digitalRead(A2);
sensor[4] = digitalRead(A3);
sensor[5] = digitalRead(A4);
if (( sensor[1] == 0) && (sensor[2] == 0)
&& (sensor[3] == 0) && (sensor[4] == 0) && (sensor[5] == 1)) // trai
error = -4;
else if (( sensor[1] == 0) && (sensor[2] == 0)
&& (sensor[3] == 0) &&
(sensor[4] == 1) && (sensor[5] == 1))
error = -3;
else if (( sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 1)
&& (sensor[4] == 1)
&& (sensor[5] == 1))
error = -2;
else if (( sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 1)
15
&& (sensor[4] == 1) && (sensor[5] == 0))
error = -1;
else if (( sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 1) &&
(sensor[4] == 0) && (sensor[5] == 0)) // giua line
error = 0;
else if (( sensor[1] == 0) && (sensor[2] == 1)
&& (sensor[3] == 1) && (sensor[4] == 0)
&& (sensor[5] == 0)) error = 1;
else if (( sensor[1] == 1) && (sensor[2] == 1)
&& (sensor[3] == 1) && (sensor[4] == 0) && (sensor[5] == 0))
error = 2;
else if (( sensor[1] == 1) && (sensor[2] == 1)
&& (sensor[3] == 0) && (sensor[4] == 0) && (sensor[5] == 0))
error = 3;
else if (( sensor[1] == 1) && (sensor[2] == 0)
&& (sensor[3] == 0) && (sensor[4] == 0) && (sensor[5] == 0))
error = 4;
void calculate_pid()
P = error;
I = I + error; // sai so truoc do cong sai so hien tai
D = error - previous_error; // sai so hien tai tru sai so truoc do
PID_value = (Kp * P) + (Ki * I) + (Kd * D);
previous_error = error;
16
}
void motor_control()
digitalWrite(In1, LOW);
digitalWrite(In2, HIGH);
digitalWrite(In3, LOW);
digitalWrite(In4, HIGH);
PID_phai = gia_tri_ban_dau + PID_value;
PID_trai = gia_tri_ban_dau - PID_value;
PID_phai = constrain(gia_tri_ban_dau - PID_value, 0, 170);
PID_trai = constrain(gia_tri_ban_dau + PID_value, 0, 170);
analogWrite(ENA, PID_phai);
analogWrite(ENB, PID_trai);
17
Chapter 3
Results
3.1 Robot
Although there are many controversies and disagreements, we did completely this project.
Robot completed on schedule. Rugged and safe hardware during heavy travel. The circuit
inspection part still had errors, but was promptly corrected. During the project, we had 2 trou-
bles. Firstly,when finished assembling the parts together and loading the code. The car was
on, but the wheels were not working. Secondly, Vehicle was not stable, has much fluctuation.
But we fixed it. The idea of making a hybrid robot car was inspired by the team from F1
racing. And we did it complete. Many groups in class buy frame in the store but we designed
it. We can control speed by using code.
Figure 3.1: Our line following car
18
3.2 Running results and review
3.2.1 Running results
We used black electrical tape to test the robot.The result is that divine into two parts.Before
using the PID control, the car moved unstable and sometimes ran out of the line. When
we tested on the circle road, the car can’t follow line.Then we tested on the straight road,
it ran but it didn’t run straightly. After using PID control the robot runs on the black road,
runs according to the required algorithm, completes the task well. Demonstrates the fully
automatic ability of the robot tracing model. It runs better than before. It can run straightly
on the straight road. If we didn’t use PID control, the car still follow line but it is very slow.
It is not good for race.
3.2.2 Review
Complicated circuit design, assembly, and repair process takes a lot of time. We had many
troubles. Many times, we didn’t know we wrong until the car didn’t operate. And we didn’t
know why we wrong? And thanks to tutor Mr. Cuong, we fixed it. We used PID control for
the code. Adjusting PID parameters still takes a long time due to manual change of numbers
(test many times). We tried to understand nature of PID control but we couldn’t understand.
So we don’t reach desired values. Because of reason so the car is not perfect. And our design
is not beautiful. Our code is not good.The car ran badly on the circle road.
19
Chapter 4
Discussion
4.1 Advantage
We learned a lot of things when we did completely this project. We knew how to use Solid-
works to simulate electronic appliances, use LaTeX to write report, use program Arduino IDE
to code and skill teamwork. About the car, we know how to assemble it. We know about write
basic code Arduino. My frame of car is different many groups.The car has followed the line.
This is the first time, we have had a model which we did by hand. And special, we know how
to real teamwork.
4.2 Disadvantage
Our design is not really beautiful. The car is still unstable, still slightly shaking. The speed of
the car is not fast. During the assembly process, there are still many errors leading to many
changes compared to the intended. Teamwork still has many problems, leading to poor work.
4.3 Future work
In the future, we will make frame better than it. We will improve code to make the robot
smarter, follow line better, more stable and run fast. We will try to add more function when
the robot is stability. Following line is very important. We can develop it to make highly
application robots. And we will improve skills about code and teamwork.
20
Chapter 5
Reference
Bibliography
[1] Chu Quang Thao - Trinh Tai Tuan - Phan Cao Khanh, Report about line following robot
with PID control, in: Institute of Military Technology, 4, Slideshare- Education, 2015
[2] Bac Tho Ho, Instruction about line following robot with PID, Part
2, 2018, in Youtube: https://www.youtube.com/watch?
fbclid=IwAR2CsVMciYk6WYGPg-7myLxzFQSRB5O2CKpT0_
uyMbeVEWqj92b856suEDE&v=l3uJ-5UvjE4&feature=youtu.be
[3] Sujeet Kumar Jha - Saurab Dulal - Manish Karn - Ahmed Raja Khan, Report line fol-
lowing Robot, in: KATHMANDU UNIVERSITY, 2016
[4] ANUSHA, How to make Arduino line followe robot, in: Elec-
tronics Hub,20/5/2017, https://www.electronicshub.org/
arduino-line-follower-robot/
[5] Do Choi STEM, 32 Xe do line - Khoa hcc Xe robot lap trinh arduino, in: Youtube,
31/12/2019, https://www.youtube.com/watch?v=hcpMSw-y81g&t=194s
[6] Khin Khin Saw - Lae Yin Mon, Design and Construction of Line Following Robot us-
ing Arduino, in: International Journal of Trend in Scientific Research and Development
(IJTSRD), 940-941, 2019
[7] https://icdayroi.com/
21