0% found this document useful (0 votes)
10 views

Embedded Project Reportee3002

The document describes a line follower robot project using a PID control system. An infrared sensor is used to follow a drawn line path and STM32F103C8 microcontroller codes the robot's movement. The robot aims to complete the path stably and efficiently by minimizing errors from the sensor readings through PID tuning.

Uploaded by

khalid Waleed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Embedded Project Reportee3002

The document describes a line follower robot project using a PID control system. An infrared sensor is used to follow a drawn line path and STM32F103C8 microcontroller codes the robot's movement. The robot aims to complete the path stably and efficiently by minimizing errors from the sensor readings through PID tuning.

Uploaded by

khalid Waleed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/378545759

Line Follower Robot with PID Control

Article · February 2024

CITATIONS READS

0 9

3 authors, including:

Mehmet İsa Daşkın Enis Özkan


Abdullah Gul University Abdullah Gul University
5 PUBLICATIONS 0 CITATIONS 2 PUBLICATIONS 0 CITATIONS

SEE PROFILE SEE PROFILE

All content following this page was uploaded by Mehmet İsa Daşkın on 28 February 2024.

The user has requested enhancement of the downloaded file.


Line Follower Robot with PID Control
EE3002 Embedded Control Systems Project
Department of Electrical-Electronics Engineering, Abdullah Gul University
Kayseri, Turkey

Enis Özkan Kayra Berk Cihan Mehmet İsa Daşkın


[email protected] [email protected] [email protected]

Abstract— The Line Follower Robot Using PID Control with


Register Level project was done using the STM32F103C8 coded
microcontroller, at the Register Level and coded in C language.
The purpose of the robot is to follow a very dark line drawn on
a light background. The drawn path has sharp turns of 90
degrees, circular parts, and sudden turns of 30 or 45 degrees in
different directions. In this way, it has become specific what
kind of algorithms the senor should have while reading. The
second main aim of the project is for the robot to complete the
drawn path (Figure 13) as soon as possible. The better the
implementation of the PID Controller, the more stable the robot
will be. This will ensure that the path is completed in a shorter
time. Many tests and observations were made for P, I and D
values, and the optimum values were reached by analyzing the
robot's movements. In addition, it is possible to say that robots
with different structures will have different P, I, D values due to
the effect of the robot's hardware design on its weight. Since 4S
BMS Li-Io Battery Pack is used in our project, it is possible to
say that it is twice as heavy as its counterparts. For this reason, Figure 1: Line Follower Robot
it has been observed that its stability decreases as it accelerates.
Additionally, an extra feature has been added for the coding II. BUILDING LINE FOLLOWER ROBOT
part. By considering the working principle of the sensors when
they are not reading lines, the engines stop on normal ground A. Mechanical Components
and when they start reading lines, they continue reading the The line-following robot vehicle used and developed in
road quickly again. As a result, a robot has been developed that
the project can be seen. Two 6V DC motors with 250 RPM
is stable in sharp turns, can stop in the absence of a line, and
continues reading the road as soon as it detects the line. were used as motors in the project. Motors have 6-7V DC
input voltage and 9V to the motor in the project. The fact that
Keywords— Line Follower Robot with PID Control, the motors are affordable and can reach high RPM values in
STM32F103C8 Microcontroller, C Programming Language, a short time with high input voltage was effective in choosing
Infrared Sensor, Path Following, Stability, Li-Io Battery, RPM, these motors. Controlling the motors has an important place
QTR-8RC Infrared Line Tracking Sensor, ST-LINK/V2, L298N in following the drawn line and responding correctly to
Motor Driver, Voltage Regulator, Mini Adjustable 3A Step-Down debugging the sensor. Motors have been added to the interior
Voltage Regulator LM2596, Sensor Distance, ST-Link V2, Li-ion of the line following robot for an aesthetic appearance. Two
Battery, BMS, PWM, Duty Cycle, Keil uVision5.
wheels are fixed to the skeleton system so that they can rotate
I. INTRODUCTION without skidding, and each is connected to its own engine.
The wheels were chosen to reduce slipping so that the vehicle
The aim of this designed project is to create a suitable
remains stable on the ground and does not skid during turns.
control algorithm for the robotic vehicle to complete the
predetermined track in as little time as possible. In this project, The electronic and mechanical components are fixed to two
an infrared sensor was used for the line-following robot to pieces of plastic frame parts. While designing the vehicle, the
follow the line on the specified track, and the movement of the QTR-8RC infrared line tracking sensor was desired to be
robot was adjusted according to this sensor. Another purpose close to the ground, so it was positioned with wide wooden
is to shut down the line-following robot to save power after 6 tongue sticks. As a result of the experiments, the mechanical
seconds when it cannot find a line. When the vehicle is placed components were combined in the skeletal system and the
on the road again, it will automatically activate and follow the design was completed (Figure 1).
road. A map algorithm has been developed for the designed
PID-controlled line-following robot to detect and follow the
B. Electronic Components
specified path. It is aimed to complete the track in a stable state
by minimizing the oscillation of the black line path created by 1) Microcontroller (STM32F103C8): Microcontroller is
debugging the errors of the data collected with the line the name given to integrated circuits that combine a
tracking sensor with the PID control system and without microprocessor, memory and i/o pins within the integrated
leaving the track. The control method with a proportional– circuit. It is generally used in embedded systems. It is low cost
integral–derivative controller control loop is called PID and low power consumption. ARM-based STM32F103C8T6
control. PID control constantly and regularly calculates the microcontroller development board, also known as Blue Pill,
error value and tries to return the system to the input value. was used in the project. With microcontroller, the sensor data
of the line following robot is read and the DC motor is driven
according to the collected data. The STM32F103C8T6
microcontroller uses an ARM32 Cortex-M3 CPU with RISC
core architecture. It has 37 general purpose digital/analog
i/o pins. These pins are used to interact with various sensors,
displays and other external devices. The selected
microcontroller board contains various integrated circuits
and communication interfaces. It supports communication
protocols such as SPI, I2C, UART to transmit and receive
data from microcontrollers. It also includes two 12-bit ADCs
built into the system and allows data from analog sensors to
be converted into digital form. The operating voltage of the
card varies between 2.7V and 3.6V. The STM32F103C8T6 Figure 4: L298N Pair Motor Driver Board with Voltage Regulator
microprocessor has a total of 20KB Static Random Access
Memory and 64KB memory.
3) Voltage Regulator: Mini Adjustable 3A Step-Down
Voltage Regulator LM2596 shown in Figure 5 was used to
prevent continuous change of PID values. The voltage
regulator used in the project has high efficiency, which keeps
energy losses to a minimum, and this voltage regulator is
used to create power supplies or to maintain a constant
voltage. However, it is important to review the technical
documentation provided by the respective manufacturer or
distributor in order to access and be able to use it correctly,
especially for a particular model. Up to 24 Watts of power
can be obtained from the regulator. The ideal value of the
output voltage in this project is 9V and stable condition was
Figure 2: STM32F103C8 Pin Schematic obtained.

Figure 3: STM32F103C8 Microcontroller


Figure 5: Mini Adjustable 3A Step-Down Voltage Regulator
In this project, ST-LINK was used for data transfer and LM2596
the necessary code was written in the Keil uVision5
application. 4 pins of the microcontroller were used for PWM
generation. Of the 10 pins used for the sensor, 8 were used to 4) Sensor (QTR-8 RC): In the project, the QTR-8 sensor
read data from the sensor and 2 were used for power supply. was used to ensure that the robot follows the black line
The microcontroller is fixed to the skeleton and the necessary smoothly (Figure 6). The sensor has 8 IR
connections to other components are completed. LED/phototransistor pairs at 1cm intervals. Each LED pair
is driven by a separate MOSFET transistor and only selected
2) Motor Driver(L298N): In the line-following robot LEDs can be activated. Each sensor on the board provides a
project, two L298N Pair Motor Driver Board with Voltage separate analog voltage output. Correct identification and
Regulators were used to drive the DC motors used to control pin configuration of the sensor's coding is very important.
the wheels. The motor driver is supplied with 12V DC Maintaining motor control is also an important issue that
voltage. The two-channel motor driver card provides 2A should be taken into consideration during the reading
current per channel and two separate motors can be process. In the project, all 8 pins of the sensor were selected
controlled independently of each other. In Figure 4, DC for writing and reading. Coding was done by connecting to
motors are connected to the relevant pins using the pins the GPIO pins of STM32. When the MOSFETs are exposed
labeled Output A and Output B. The input pins of the DC to infrared light, the capacitors are connected to ground and
motor control the forward and reverse movement of the motor after a few milliseconds, the GPIO pins switch to input mode.
with the combination of 01-10, and PWM signal values are If a particular sensor output is 0, this indicates that it is out
set on a combination of enable pins and input pins. The motor of line. When the sensor output is 1, it means that it sees the
driver is fixed in front of the line-following robot. line. This mechanism allows the line adjustment of the
microcontroller. The distance between the sensor and the
ground was set to 3 mm. It was observed that when set to 1cm,
the sensor did not read data and the sampling was done
incorrectly. For this reason, the distance between it and the
ground was kept as short as possible.
QTR-8RC sensor can be fed with 3.3V and 5V, since it is
fed with 3.3V in the project, bypass has been made with the
relevant pins.
In the coding section, two important delay codes were
added while making the sensor register settings. First of Figure 8: Li-ion Battery
these, after setting pins 0-7 high, a 12us delay command was
added for sensor response. Then pins 0-7 were set as input
with input and push/pull-resistor. Then, a 6 microsecond 4S 40A BMS Charging and Protection Module is
delay code was added for stable data transmission. used for battery protection. This module is used to receive
constant current from each battery, to prevent the batteries
from deteriorating, to ensure that the batteries are easily
charged, and to maintain current stability (Figure 9). The
batteries are evenly placed on the top tray.

Figure 6: QTR-8RC Reflectance Sensor Array

5) ST-LINK/V2 – STMicroelectronics: ST-Link V2 has


been used to program and debug STM32 microcontrollers.
The STM32 microcontroller can be accessed using a single-
wire interface module. It offers an effective solution to
developers by streamlining programming and debugging
processes. ST-Link V2 is known as a reliable tool in STM32-
based projects and is preferred by a wide rang
6) e of users. That's why ST-Link V2 was used in the
project.

Figure 9: BMS Charging and Protection Module

III. CIRCUIT DIAGRAM OF LINE-FOLLOWER ROBOT

Figure 7: ST-Link V2

7) Battery: 4 x 3.7V 1800mAh 18650 Li-ion


Rechargeable Batteries (Figure 8) were used to power the
robot. The reason for using Li-ion batteries is that the current
is desired to be strong. Li-ion battery is a rechargeable
battery technology that has come to prominence due to their
capacity to store electrical energy. It offers advantages such
as long battery life, low self-discharge rate and
rechargeability. However, care must be taken in overheating Figure 10: Circuit Diagram
situations due to the risk of explosion. Production costs are
high. The circuit diagram of the project is seen in Figure 10. The
power supply used in the line following robot produces 16V
current. Since this current is too much for the motors, the
voltage of the power supply is reduced to 9V with the
regulator circuit. Since it is desired to prevent the contact of
the cables, 2 switches were used to prevent the circuit current
at undesirable times. In order to drive the motors properly,
ENA and ENB pins are short-circuited. The remaining pins
are attached to the appropriate motors. Pins 1 to 8 on the
sensor are installed respectively from PA0 to PA7 pins of the
STM32 board. Additionally, the sensor is powered with 3.3V.
For this reason, the bypass pins are short-circuited.
IV. SOFTWARE PART WORKING PRINCIPLE
PWM and Motor Control: PWM and Motor Control: The
L298N Motor Driver works by generating PWM signals via
STM32 timer channels (TIM2 and TIM3). PWM allows 𝐾𝑝 ⋅ 𝑒(𝑡)
precise control of the direction and speed of the robot
following the line using duty cycle logic. In the project, 4
different PWM Frequency 72MHz, ARR (period) 1000ms 𝑡

were selected: forward movement of the right motor, reverse


movement of the left motor, and forward movement of the
𝐾𝑖 ⋅ ∫ 𝑒(𝜏) ⋅ 𝑑𝜏
0
𝛴
left motor. PWM signals are used to adjust the speed and
direction of two DC motors, and the duty cycle of the signal 𝑑
determines how much power should be supplied to the DC 𝐾𝑑 ⋅ ⋅ 𝑒(𝑡)
𝑑𝑡
motors. Duty cycle is an important factor in PWM, and a 50%
duty cycle provides half the power to the motors. The duty
cycle varies according to the value from the PID.
Figure 12: PID System Block Diagram
𝑡
𝑑
𝑈(𝑡) = 𝐾𝑝 ⋅ 𝑒(𝑡) + 𝐾𝑖 ⋅ ∫ 𝑒(𝜏) ⋅ 𝑑𝜏 + 𝐾𝑑 ⋅ ⋅ 𝑒(𝑡) 𝟏
𝑑𝑡
0
1. Proportional Controller: Proportionally multiplying the
error value found using proportional gain gives the
proportional controller value.
𝑢(𝑠)
𝑢(𝑡) = 𝐾𝑝 ⋅ 𝑒(𝑡) 𝑜𝑟 ; = 𝐾𝑝
𝑒(𝑠)
If the value of Kp is too high, the system instability will
also be very unstable. However, a small proportional gain
causes a small output response. Therefore, the
microcontroller controls the system less sensitively. A low
value ensures that the control work is very small when the
Figure 11: Duty Cycle
system responds to disturbances.
V. PID CONTROLLER DESIGN
2. Integral Controller: The effect of the integral term is
Proportional-Integral-Derivative (PID) control is the most proportional to both the magnitude of the error and the
common control algorithm used in industry. The duration of the error. In a PID controller, the integral is the
characteristics of the PID controller depend on its strong
sum of instantaneous errors over time. The accumulated
performance in various operating conditions and its simple
error is multiplied by the integral gain (Ki) and added to the
functionalities that allow competent people to operate them
simply. As the name suggests, a PID algorithm consists of controller output. The integral term is given by:
𝑡
three parts: proportional, integral and derivative. These are
varied to achieve the optimum response of the system. Figure 𝑢(𝑡) = 𝐾𝑝 ⋅ 𝑒(𝑡) + 𝐾𝑖 ∫ 𝑒(𝜏)𝑑 𝜏
12 shows the mathematical and block diagram representation 0
of PID control. The system output, called Process Value, is 𝑢(𝑠) 1
= (𝐾𝑝 + )
read by a sensor. In this project, it is done with the QTR8A 𝑒(𝑠) 𝜏𝑖 𝑠
sensor. System output is compared to the set point, also called
the reference value. Here the difference between Input Value 3. Derivative Controller: The derivative term plays a critical
and Real Output Value is error. The system equation (Eq. 1) role in the PID control algorithm. It ensures system stability
is obtained by using the found error value in P, I and D and predicts future errors. It is calculated by multiplying the
operations. rate of error change by the derivative gain (Kd). A high
derivative gain reacts quickly to changes in error rate, but an
overly large amount might create instability and overreaction.
As a result, it should be carefully selected. The derivative term
increases system stability by anticipating potential faults.
However, precautions should be taken against noise, such as
filtering or using the derivative instead of error in the
measurement.
𝑑 sensor and the ground. At first, it was positioned at 1cm and
𝑢(𝑡) = 𝐾𝑑 ⋅ 𝑒(𝑡)
𝑑𝑡 it was seen that the sensor did not detect the data accurately
and stably. Therefore, the distance between the sensor and the
ground has been reduced to 3mm. In addition, the flowchart
VI. RESULTS and programming logic of the coding written in Keil
uVision5 are shown in Figure 14.
The example path used for the line-following robot
designed in the project is shown in Figure 13. With straight
lines, curves, and sharp turns of 90 and 45 degrees, it is
important that the vehicle moves flawlessly in all conditions.
The robot's completion of the course will vary according to
the battery charge, PID values and the accuracy of the code
written. In order for the robot to complete the road correctly,
different trials were made in each different road situation, and
it was aimed to correct the difficulties experienced by the
robot and to progress flawlessly. Considering the center of
mass of the robot, a code was tried with this value. Coding
was done with Keil uVision5 application. There were
problems with the speed of the line-following robot because
it was too heavy due to the batteries, and its speed was tried
to be optimized with PID values. As a result, it has been
observed that the robot completes the course flawlessly, even
in sharp bends. The vehicle stopped when it could not find a
road within 6 seconds at the end of the road, and started again
when it was left on the road again. It has been observed that
in cases where it finds the path within 6 seconds, it continues Figure 14: Flow Chart of the Coding Part
to move correctly.

VIII. CONCLUSION
In this project, a PID-controlled line-following robot was
designed using QTR-8RC sensor, STM32F103C8
microcontroller, L298N motor driver. Control was provided
with the code written with the Keil uVision5 program and it
was tried to ensure that the robot completed the course
without any problems. The wheels were controlled by PWM
signal with the code written. Throughout the project, the
importance of the center of mass of the line-following robot
has been demonstrated. Electronic and mechanical
components were fixed to the skeleton system. With the
microcontroller, PID control coding was adapted to the
system with various trials and the deviation and oscillation
behavior was minimized with the correct Kp, Ki, Kd values.
The effect of the components on the system was investigated
Figure 13: Tracking Line and the system was tried to be perfected. The importance of
the robot's correct and timely response according to the
samples it collects from the sensor was emphasized.
VII. DISCUSSION
Due to the heavy weight of the line following robot due to REFERENCES
the batteries, the vehicle could not complete the course at the [1] https://robotresearchlab.com/2019/02/16/pid-line-follower-tuning/
expected speed, there were difficulties in controlling the [2] https://core.ac.uk/download/pdf/53189911.pdf
stability of the vehicle, and the completion time of the track [3] Line estimation for a line-following mobile robot | Request PDF
was 10 seconds. Dirt on the test track and wheels, unlike its (researchgate.net)
weight, has also been found to have a negative effect on [4] Line estimation for a line-following mobile robot | Request PDF
stability and completion time. The 45-degree turns were the (researchgate.net)
most challenging part of the project. For the sensor not to [5] 53189911.pdf (core.ac.uk)
miss the line and not to go out of the way, a system was used [6] (PDF) Pid Controlled Line Follower Robot Design on Indoor 3D
Networks | İsmail Rakıp Karaş - Academia.edu
in which the right and left end sensors of the sensor were
[7] (PDF) PID Controller Optimization for Low-cost Line Follower
used. Another problem was the distance between the QTR-8 Robots (researchgate.net)

View publication stats

You might also like