You are on page 1of 37

Islamic University ‫الجامعة اإلسالمية‬

Faculty of Engineering
‫كليه الهندسة‬
Department of Mechanical
Engineering ‫قسم الهندسة الميكانيكية‬

ME 3721
Term 442- second trimester 2022
Mechatronics Project Report Part II
Submitted to
Dr. FItrian imaduddin

Project Title
Design and Evaluation of the Digital
Line Follower (BOURAQ 1.2 #)
Team Members
AMMAR MOHAMMED 392025023
IBRAHIM MOHAMMED 392024273
ABDULRAHMAN M AHMED 392024853

Section No: 2106


Date: 2/17/2023
Abstract
P a g e 1 | 37
The line follower robot is a mobile machine that is capable of detecting and subsequently
following a pre-defined line drawn on a surface. Typically, the line is visible and has a high
contrast color, such as a black line on a white surface. This is accomplished through the use of
optical sensors (LDR) installed under the robot. These sensors detect the line, and the resulting
signal is transmitted to the L293 through a signal conditioning process. The motor driver then
interprets these signals and issues the appropriate commands to the robot's drive system, allowing
it to follow the predetermined path.

One such robot, the BOURAQ1.2, was designed and tested for a line follower robot competition
organized by Dr. Fitrain. During the design and implementation of the BOURAQ1.2, a number of
technical and mechanical issues were encountered. This report outlines the process of designing,
implementing, and testing the BOURAQ1.2. Additionally, the technical and mechanical issues
that were encountered during this process are thoroughly investigated and addressed.

P a g e 2 | 37
Table of Contents
1. Introduction ............................................................................................................................................. 5

1.1. Background and Historic perspective ................................................................................................ 5

1.2. Concept and principles of line follower robot ................................................................................... 5

2. Designing of the robot BOURAQ 1.2 .................................................................................................... 7

2.1. LDR (light-dependent-resistor)-Photoresistor-sensor ........................................................................ 7

2.2. Signal conditioning ............................................................................................................................ 8

2.2.1. The signal conditioning (resistance to voltage) in the line follower track ..................................................9
2.2.2. The functioning of the Signal conditioning along with the LDR ................................................................ 9
2.3. Actuater (Motor) specification ......................................................................................................... 11

2.4. Chassis along with other components .............................................................................................. 11

2.5. The digital microcontroller (Arduino) ............................................................................................. 14

2.6. Motor driver (L293-D) ..................................................................................................................... 15

2.7. The integrated system (LDR sensor, with Microcontroller, and motor driver) ............................... 20

2.8. The circuit diagram of the integrated system ................................................................................... 21

3. The Algorithm and the programing code ........................................................................................... 22

3.1. The programing code and its explanation: ....................................................................................... 24

4. Analyzing the performance of the robot ............................................................................................. 30

4.1. Performance Evaluation ................................................................................................................. 30

4.2. The strengths and weakness of BOURAQ 1.2 ................................................................................. 31

4.3. Analyzing the causes of failure ........................................................................................................ 32

5. Budget .................................................................................................................................................... 34

6. Conclusion ............................................................................................................................................. 36

References .................................................................................................................................................. 37

ABNNDIX .................................................................................................................................................. 37

P a g e 3 | 37
List of Figures

Figure 1 Light-dependent-resistor................................................................................................... 7
Figure 2 Optical phenomenon of LDR sensors............................................................................... 7
Figure 3 The sample voltage circuit................................................................................................ 9
Figure 4 The four LDR’s positions. ................................................................................................ 9
Figure 5 Robot Smart Car DC motor DIY [5]. ............................................................................. 11
Figure 6 The wood chassis with no components above. ............................................................... 12
Figure 7 The upper face of the chassis, along Arduino Uno. ....................................................... 12
Figure 8 The insulating LDRs and LEDs. .................................................................................... 13
Figure 9 The small front bumper. ................................................................................................. 13
Figure10 Arduino UNO ............................................................................................................... 14
Figure11 l293D pins [4]. ............................................................................................................... 16
Figure12 Working principle of L293D [5]. .................................................................................. 17
Figure13 H bridge [5]. ................................................................................................................. 18
Figure 14 The four LDRs positions. ............................................................................................. 22
Figure 15 The serial monitor......................................................................................................... 26
Figure 16 The simulation using Tinker cad. ................................................................................. 29
Figure 17 BOURAQ 1.2 completing the first corner. ................................................................... 30
Figure 18 BOURAQ 1.2 deviate from the path. ........................................................................... 30
Figure 19 Taking the readings for the appropriate thresholds. ..................................................... 32
Figure 20 Some defectives on the track. ....................................................................................... 32

P a g e 4 | 37
1. Introduction
1.1. Background and Historic perspective
A line follower robot is a type of autonomous robot that is designed to follow a particular
line. It is equipped with sensors that detect the line and make the necessary adjustments to keep
the robot on track. The robot can be built using various types of sensors, including infrared,
reflective, or color sensors, and can be controlled using a microcontroller such as an Arduino and
a motor driver such as L293.

Line follower robots have been used in a variety of applications, including industrial automation,
surveillance, and entertainment.

The history of line follower robots can be traced back to the early 1950s when the first electronic
autonomous robots were developed. Over the years, line follower robots have evolved to become
more sophisticated, with the introduction of new sensors and control systems. Today, they are an
important tool in a wide range of applications, and with advances in technology and programming,
the possibilities for line follower robots are virtually limitless.

1.2. Concept and principles of line follower robot


Line follower robot It is a robot (car) that moves on a line that has a distinctive color different from the rest
of the surface's color, and it continues to follow it until the end of the path drawn for it. And if it deviates
from the path, it tries to return to it again. It uses some sensors so that it can distinguish the color of the line
from the rest of the surface’s colors. A sensor that are used by the principle of light reflection known as
Photoresistors (LDR) was used in our project to sense the light's intensity. It is a normal resistance, but it
is affected by light. If the light becomes intense, the resistance decreases, and the passage of current
becomes easier and vice versa.

A white LED is placed next to the LDR at the bottom of the car. If the line is white, the light will be
completely reflected on the LDR, and the resistance of the LDR will become as low as possible. If the line
is black, most of the light will be absorbed and a small part of it will be reflected, and then the resistance
of the LDR will decrease by a large percentage. The same applies to the colors between white and black.
As noted, each color has a certain effect on the resistance value of the LDR, and that is according to the
extent of light reflection on the color surface. The optical sensors (LDR) will be placed as resistance in a
circuit called Voltage divider, which consists of two resistors connected in series, one of which will be the
optical resistance (LDR) and the other will be a known constant resistance. And since there is a constant

P a g e 5 | 37
resistance, then the voltage generated from the wire will remain constant until a difference in colors occurs,
then the value of the optical resistance (LDR) will change, and then the voltage output from the Voltage
divider will also change.

We have developed our previous project, and we have added a microcontroller(Arduino) and a motor
driver(L293D) in order to raise the efficiency of the robot's work and expand its movement directions so
that it is not limited to moving forward only, but also moves backwards, and it can turn left and right.

The Arduino and L293D motor driver are important components in a line follower robot. The Arduino
serves as the brain of the robot, controlling its movement and processing information from its sensors. The
L293D motor driver, on the other hand, controls the motors of the robot, allowing it to move forward, turn,
and make other necessary adjustments to follow a line.

Specifically, the Arduino processes information and signals coming from the sensors, which can be infrared
or reflective sensors, and uses this information to control the motors through the L293D motor driver. The
L293D motor driver provides the necessary power to the motors and allows the Arduino to control their
direction and speed.

Without the Arduino, the robot would not be able to process information from the sensors, and without the
L293D motor driver, the robot would not be able to move effectively. Together, the Arduino and L293D
motor driver enable the line follower robot to follow a line with precision and accuracy.

The combination of Arduino and L293 allows for precise control over the motor speed and direction,
enabling the robot to navigate along a black line accurately. The code used to program the robot can be
customized to adjust the sensitivity of the sensors and the speed of the motors, allowing for more flexibility
in the robot's functionality .

Overall, the line follower robot is an excellent example of how advanced technologies like Arduino and
L293 can be utilized to create useful and practical machines. With further advancements in technology, it
is expected that line follower robots will continue to evolve and be applied in various industries to improve
efficiency.

Motors to
provide
Motor driver controlled
(L293D)
microcontroller
(Arduino)
Signal
condision
Sensor (LDR)
for line
detection

P a g e 6 | 37
2. Designing of the robot BOURAQ 1.2
2.1. LDR (light-dependent-resistor)-Photoresistor-sensor
Light-dependent-resistor also known as photo-resistor, which is a type of resistor that works on the
photoconductivity principle, means that its resistance changes according to the intensity of light,
it decreases with the increases of the light intensity and vice versa as shown in Fig 3 below [1].

Figure 1 Light-dependent-resistor

It represents an optical phenomenon as shown in Fig 2 below:

Figure 2 Optical phenomenon of LDR sensors

P a g e 7 | 37
2.2. Signal conditioning
A signal conditioning takes an analog signal from a process sensor and converts it into a signal
that is compatible with process monitoring and control devices, it’s a manipulation of a signal in a
way that prepares it to the next stage of processing.

Signal conditioning translate the signals coming from the sensor or the transducer due to any
disturbance in the environment (physical phenomena) and then convert it into a standard one that
can be used. The standard signal can be represented as Voltage or Current and most of the time
and the preferred one is Voltage [2].

Standard Analog Signal


Voltage (V) 0-5 0-10 1-5
Current (mA) 4-20

The values of the physical variables are translated into equivalent electrical signals via sensor and
the results is a change in the output voltage. This outputs voltage maybe not significantly
measured, or it doesn’t give meaningful value, and here it comes the turn of the signal conditioning
by converting this signal into a meaningful and standard signal via one of these common types of
signal conditioning:

1- Resistance to Voltage
• Voltage divider.
• Wheatstone bridge.
2- Voltage amplifier.
• Inverting.
• Non-inverting.

P a g e 8 | 37
2.2.1. The signal conditioning (resistance to voltage) in the line follower track
In the line follower, the LDR’s needs to have another resistance in series so that we can control
the voltage difference between them (Vout), and basically this combination of a voltage source (Vin)
with two resistances in series is known as the voltage divider as shown in Fig 3 below.

Figure 3 The sample voltage circuit.

Mainly, there are three factors affecting the Vout in the above voltage divider:
1- The position of the LDR is it R1 or R2.
2-The intensity of light since it will change the resistance value of the LDR.
3-The amount of the input voltage and the value of the constant resistance.

2.2.2. The functioning of the Signal conditioning along with the LDR
The four LDR’s which we are aiming to install in BOURAQ1.2 robot as shown in Fig4 below, are
basically changing their resistances values depending on the light reflected on their surfaces. And
since we need a voltage information to send it to the Arduino ADC pins instead of resistance
information, we have to convert this resistance changing to voltage changing for each one of the
four LRDs through a proper voltage divider.

Figure 4 The four LDR’s positions.

P a g e 9 | 37
𝑅2
Using the voltage divider, we know that: 𝑉𝑜𝑢𝑡 = 𝑅1+𝑅2 ∗ 𝑉𝑖𝑛 ,where is Vin=9V (battery source),

and the LDR resistance can be either R1 or R2.

Assuming that the constant resistant is 10 Kohm and the value of the LDR resistance is 20 Kohm
in the Dark and 0.30 Kohm in the Light (we measure it using multimeter). Now we left up with
two scenarios either R1 is the LDR or R2 is the LDR:

𝟏𝟎
If R1 is the LDR, then 𝑽𝒐𝒖𝒕 = 𝑹𝟏+𝟏𝟎 ∗ 𝟗𝑽, therefore:

1- As the LDR sense dark the R1 value is increasing, and hence the Vout is decreasing.

10
𝑉𝑜𝑢𝑡 = 20+10 ∗ 9𝑉 = 3 V .

2- As the LDR sense light the R1 value is decreasing, and hence the Vout is increasing.

10
𝑉𝑜𝑢𝑡 = ∗ 9𝑉 = 8.73 V .
0.3 + 10
𝑹𝟐
If R2 is the LDR, then 𝑽𝒐𝒖𝒕 = 𝟏𝟎+𝑹𝟐 ∗ 𝟗𝑽 , therefore:

1- As the LDR sense dark the R2 value is increasing, and hence the Vout is increasing
20
𝑉𝑜𝑢𝑡 = 10+20 ∗ 9𝑉 = 6 V .

2- As the LDR sense light the R2 value is decreasing, and hence the Vout is decreasing.

0.3
𝑉𝑜𝑢𝑡 = ∗ 9𝑉 = 0.262 V .
10 + 0.3

And in conclusion, we want to select the voltage threshold to determine whether the LDR sees
Dark or Light surface.

3+8.73
For first scenario: 𝑉𝑡ℎ𝑟𝑒𝑠ℎ = 2
= 5.865 V . (Above 5.865 we can consider LDR sees

light and below it dark)


6+0.262
𝐹𝑜𝑟 𝑠𝑒𝑐𝑜𝑛𝑑 𝑠𝑐𝑒𝑛𝑎𝑟𝑖𝑜: 𝑉𝑡ℎ𝑟𝑒𝑠ℎ = = 3.131 V .(Above 3.131 we can consider LDR
2

sees dark and below it light)

And based on the voltage threshold value we can determine which surface the LDR is exposed to.

P a g e 10 | 37
2.3. Actuater (Motor) specification
We reused the same motors we bought for part I, which is motor type known as Robot
Smart Car DC motor DIY, basically it was made for applications similar to our application.
Required 3-6 V voltage input so any 9V battery is more than enough to run the motor in best
performance, good load speed, and the output torque is more than enough to withstand the total
load applied on the chassis considering the weight of the whole chassis with the component
attached to it, the friction and the normal force.

Figure 5 Robot Smart Car DC motor DIY [5].


Robot Smart Car DC motor DIY [3].
Voltage 3-6V DC
No Load Speed 3V-125 rev/min 5V-200 rev/min 6V-230 rev/min.
Load Speed 3V-95 rev/min5V 5V-160 rev/min 6V-230 rev/min
Output Torque 3V-0.8kg.cm 5V-1.0kg.cm 6V-1.1kg.cm
Rotate Speed 125rpm/min.

2.4. Chassis along with other components


The same chassis which we used in part I we reuse it in part II with some additional parts
such as the Arduino and a small front bumper. The chassis manufactured using Low-thickness
wood was chosen to manufacture the chassis for due to its hardness and light weight (Strength to
weight ratio). A laser cutting machine can be used to cut it. Likewise, two long holes were cut in
the right and left, as shown below in Fig6, to allow the wires of the two motors to be connected to
the breadboard. For the tires, we used three tires, one on the right and another on the left attached
to each motor, so that they could move in both the forward and backward directions.

P a g e 11 | 37
A third tire has the property of moving 360 degrees was placed in the front in order to give balance
to the chassis, as well as facilitate the smooth movement of the car when it turns right or left.

Figure 6 The wood chassis with no components above.

In terms of the energy source, we placed it on the upper face of the chassis, along Arduino Uno
using a strong double tab. The two motors are placed in parallel with each other. A breadboard
was placed in the top middle of the chassis in order to facilitate the connection of all parts of the
car, including the two motor, sensors, and lights as shown below in Fig 7.

Figure 7 The upper face of the chassis, along Arduino Uno.

P a g e 12 | 37
Finally, we used a small front bumper to facilitate the process of fixing and insulating the four
LDRs and the four LEDs. In such a way that will hold them fixed and tight to avoid any unwanted
movement of the LDRs and the LEDs as shown in Fig 8 &Fig 9 below.

Figure 9 The small front bumper.

Figure 8 The insulating LDRs and LEDs.

P a g e 13 | 37
2.5. The digital microcontroller (Arduino)
The Arduino Uno is a specific type of Arduino board that uses an ATmega328p microprocessor
and is offered as an open-source board. The Arduino Uno has a set of input and output pins that are analog
and digital and are used to link the board to other parts. Six of the fourteen I/O pins installed inboard are
analog input pins, for a total of fourteen pins. The board contains a USB port that may be used to deliver
power to it. The board is employed in electronics projects and in the circuit design process.

The Arduino UNO as shown below Fig10 is a kind of microcontroller that has an ATmega328 controller.
Beginners like the Arduino UNO board when using it for an electronics project.

solely use the Arduino UNO board as an Arduino board. The Arduino board is the one that is used the most
frequently. The board has 14 digital input/output pins, 6 of which are analog input pins, along with an ICSP
header, a power jack, a USB connection, a reset button, and other parts. To make the Arduino UNO board
functional and used in the project, all these parts are added to it. The board may be directly charged using
the DC supply to the board or via a USB connector.

Arduino UNO10 Figure

P a g e 14 | 37
An Arduino can be used to control a line follower robot by reading sensor data and sending commands to
the robot's motors based on that data. Here's a basic overview of the functions involved:

• Sensor Reading: The line follower robot uses sensors to detect the black line on the ground.
Typically, infrared sensors are used. The Arduino is connected to the sensors and reads the data
they provide.
• Processing Sensor Data: Once the sensor data is collected, the Arduino needs to process it to
determine the position of the line relative to the robot. The Arduino can use various algorithms to
do this, such as PID control or a simple threshold-based approach.
• Motor Control: Based on the sensor data, the Arduino sends commands to the robot's motors to
keep it on the line. For example, if the robot is veering to the left, the Arduino might send a
command to the right motor to speed up and correct the course.
• Looping: The Arduino performs these functions in a loop, constantly reading sensor data,
processing it, and sending motor commands. This loop runs until the robot reaches the end of the
line or is manually stopped.

There are many ways to implement a line follower robot using an Arduino, but the above functions provide
a general overview of the main components involved.

2.6. Motor driver (L293-D)


An integrated circuit called the L293D motor Driver IC is typically used to control the
motors in an autonomous system. It can drive two motors concurrently. With the help of this motor
driver IC, we can control the direction and speed of a DC motor.

A dual H-bridge motor driver IC is called L293D. The simplest circuit for managing a motor with
a low current rating is an H-bridge. One H-bridge may provide bidirectional DC motor driving. A
current-enhancing IC is L293D. It can also function as a switch.

P a g e 15 | 37
The L293D is a 16-pin integrated circuit with eight motors as shown below Fig 11 control pins on
each side of the board. For each motor, there are two input pins, two output pins, and one enable
pin. With voltages ranging from 4.5 V to 36 V, the L293D IC is intended to deliver bidirectional
driving currents of up to 600 mA. It is made to drive inductive loads in positive-supply
applications, including relays, solenoids, DC & bipolar stepping motors, as well as other high-
current/high-voltage loads [4].

Figure11 l293D pins [4].

Working principle of L293D Motor Driver IC.

This L293D motor driver IC is very easy to use. The IC operates on the half-H-Bridge concept;
we won't go into detail about what this term means here; for now, just be aware that a half-H-
Bridge is a system that can run motors both clockwise and counterclockwise. As was previously
said, this IC can operate two motors in either direction simultaneously. The circuit to do this is
illustrated as shown below Fig12. As in the table below, a description of each pin and the way to
connect it [5].

P a g e 16 | 37
Figure12 Working principle of L293D [5].

Pin Pin Description


number Name

1 Enable This pin enables the input pin Input 1(2) and Input 2(7)
1,2

2 Input 1 Directly controls the Output 1 pin. Controlled by digital circuits

3 Output 1 Connected to one end of Motor 1

4 Ground Ground pins are connected to ground of circuit (0V)

5 Ground Ground pins are connected to ground of circuit (0V)

6 Output 2 Connected to another end of Motor 1

7 Input 2 Directly controls the Output 2 pin. Controlled by digital circuits

8 Vcc2 Connected to Voltage pin for running motors (4.5V to 36V)


(Vs)

9 Enable This pin enables the input pin Input 3(10) and Input 4(15)
3,4
10 Input 3 Directly controls the Output 3 pin. Controlled by digital circuits

P a g e 17 | 37
11 Output 3 Connected to one end of Motor 2

12 Ground Ground pins are connected to ground of circuit (0V)

13 Ground Ground pins are connected to ground of circuit (0V)

14 Output 4 Connected to another end of Motor 2

15 Input 4 Directly controls the Output 4 pin. Controlled by digital circuits

16 Vcc2 Connected to +5V to enable IC function


(Vss)

electrical circuit known as a H bridge as shown below Fig13 enables the application of a voltage
across a load in either direction. To enable DC motors to operate forward and backward, H-bridge
circuits are commonly employed in robotics and many other applications. The majority of these
motor control circuits are utilized in power electronic converters, including DC-DC, DC-AC, and
AC-AC converters. In particular, a motor controller with two H-bridges is always used to drive a
bipolar stepper motor [5].

Figure13 H bridge [5].

P a g e 18 | 37
Four switches, S1, S2, S3, and S4, are used to construct an H-bridge. The motor will get a +ve
voltage when the S1 and S4 switches are both closed. This voltage is reversed, enabling the motor
to operate in the other direction, by opening switches S1 and S4 and shutting switches S2 and S3.

In most cases, the H-bridge motor driver circuit is utilized to both break and reverse the direction
of the motor. As a result of the motor terminals being shorted, when the motor abruptly stops. If
the motor has been disconnected from the circuit, can let run freely until it stops. The four switches
that make up the aforementioned circuit are listed in the table below along with their various
actions.

P a g e 19 | 37
2.7. The integrated system (LDR sensor, with Microcontroller, and motor driver)

P a g e 20 | 37
2.8. The circuit diagram of the integrated system (LDR sensor, with Microcontroller, and
motor driver)

P a g e 21 | 37
3. The Algorithm and the programing code
BOURAQ #1.2 is a fully automatic line-follower robot. Which has an algorithm that helps
him detect the desired path, using a C++ programing language, a digital controller, a motor driver,
and the four LDRs to detect the color (analog signal). LDR A (1), LDR B(2) , LDR C(3) , and
LDR D(4) as shown in Fig14 below are used to detect any changes in the color path and then send
the analog signal to the digital controller (Arduino), and based on the given information from the
LDRs, Arduino will send the command to the motor driver to control the direction of rotation of
the two DC motors and their speed.

Figure 14 The four LDRs positions.

• Basically, LDR A(1) , and LDR D(4) initially should see white surface where LDR B(2) ,
and LDR C(3) should see black surface.
• When LDR B(2) , and LDR C(3) are both about to leave the black surface in straight path
LDR A(1) , and LDR D(4) should enter the black surface.

Since LDR A(1) , and LDR D(4) will see white most of the time therefore,

• If LDR A(1) , and LDR D(4) sees white AND ( LDR B(2) , and LDR C(3) are both
seeing black) , then both motors will move forward.
• If LDR A(1) , and LDR D(4) sees white AND ( LDR B(2) sees white , and LDR C(3)
sees black ) , then left motor ( motor 1) will move forward , and right motor ( motor 2)
will move backward.
• If LDR A(1) , and LDR D(4) sees white AND ( LDR B(2) sees black , and LDR C(3)
sees white ) , then left motor ( motor 1) will move backward , and right motor ( motor 2)
will move forward.
• If all LRDs sees white, then both motors will move backward.

P a g e 22 | 37
And in case one of the LDR A(1) , or LDR D(4) sees black:

• If LDR A(1) sees black , and LDR D(4) sees white , then for 2 sec left motor ( motor 1)
will move backward , and right motor ( motor 2) will move forward.
• If LDR A(1) sees white , and LDR D(4) sees black , then for 2 sec left motor ( motor 1)
will move forward , and right motor ( motor 2) will move backward.

• Else both motors will stop.

The following flowchart will help us to understand the logic before we start writing the code:

P a g e 23 | 37
3.1. The programing code and its explanation:
// Declaring Motor 1 connections in the L293D motor driver with the Arduino pins
where is motor1in1 and motor1in2 can be any pin, but en1 must be PWM pin with ~
sign.

const int en1 = 3;


const int motor1in1 = 6;
const int motor1in2 = 9;

// Declaring Motor 2 connections in the L293D motor driver with the Arduino pins
where is motor2in1 and motor2in2 can be any pin, but en2 must be PWM pin with ~
sign.

const int en2 = 5;


const int motor2in1 = 10;
const int motor2in2 = 11;

// Declaring the LDRs connections in the Arduino where is all of them in the ADC
(analog-to-digital converter) pins, these pins will take the value of the output
voltage that is coming from the voltage divider and convert it into bit from 0-
1023.
const int sensorA = A0;
const int sensorB = A1;
const int sensorC = A2;
const int sensorD = A3;

// Declaring the Potentiometer connections in the Arduino and it is in the ADC


(analog-to-digital converter) pin, this pin will take the value of the output
voltage after the effect of variable resistor and then convert it into bit from 0-
1023.
const int sensorR = A4;

// Initial state for the voltage threshold of the four LDRs, the output voltage
from the voltage divider which is coming to the Arduino through the ADC pins (0-
1023 bit). These voltages threshold is the average between the dark mode and the
light mode for each LDR which we got it using the serial monitor, and they can be
different depending on the light intensity and position of each LDR. And the
following value is the values that we used during the competition which is matching
to the circumstances and light intensity of the competition place.

int ThreshA = 420;


int ThreshB = 345;
int ThreshC = 295;
int ThreshD = 445;

P a g e 24 | 37
// void setup function: it usually contains statements that set the pin modes on
the Arduino to OUTPUT and INPUT.
void setup() {

// Set all the motor control pins to outputs

pinMode(en1, OUTPUT); // en1 with a PWM output pin to the motor driver
enable1&2, can vary between 0 to 255 bit and it is used to control the speed of
the motor using the potentiometer.
pinMode(en2, OUTPUT); // en2 with a PWM output pin to the motor driver
enable3&4, can vary between 0 to 255 bit and it is used to control the speed of
the motor using the potentiometer.

// All the below pins are normal output pins with only two option HIGH >1 or LOW
>0, it is used to control the two inputs of each motor driver to control the
direction of rotation (polarity).
pinMode(motor1in1, OUTPUT);
pinMode(motor1in2, OUTPUT);
pinMode(motor2in1, OUTPUT);
pinMode(motor2in2, OUTPUT);

// Turn off motors - Initial state


digitalWrite(motor1in1, LOW);
digitalWrite(motor1in2, LOW);
digitalWrite(motor2in1, LOW);
digitalWrite(motor2in2, LOW);

// To stablishes serial communication between your Arduino board and another


device, and in our case the devices are the four LDRs.
Serial.begin(9400);
}

// void loop() : is a function that executes indefinitely until you power off the
Arduino.
void loop() {

// Using the ADC pins in the Arduino to keep storing the value that is coming from
the four LDRs through the voltage dividers outputs and store it in the following
variables lightLevelA, lightLevelB , lightLevelC,and lightLevelD.
int lightLevelA = analogRead(sensorA);
int lightLevelB = analogRead(sensorB);
int lightLevelC = analogRead(sensorC);
int lightLevelD = analogRead(sensorD);

P a g e 25 | 37
//Using the serial monitor to represent the values that is coming from the LDRs
voltage divider through the Arduino ADC pins in the form of 0-1023 but LA:for LDRA
, LB:for LDRB, LC:for LDRC , and LD: for LDRD.And \t will help us to make space
between the value , while \n will help us to print second line each time the four
reading appears as shown in the Fig 15 below. And based on these reading we
initialized the state of the voltage threshold for each LDR.

Serial.print("\t LA: ");


Serial.print(lightLevelA);
Serial.print("\t LB: ");
Serial.print(lightLevelB);
Serial.print("\t LC: ");
Serial.print(lightLevelC);
Serial.print("\t LD: ");
Serial.print(lightLevelD);
Serial.print("\n");

Figure 15 The serial monitor.

// If LDR A, and LDR D both sees white.

if (lightLevelA < ThreshA && lightLevelD < ThreshD)


{ // And LDR B, and LDR Care both seeing black.
if (lightLevelB > ThreshB && lightLevelC > ThreshC)
{
Forward(); //Execute the following function.
}
// And LDR B sees white, and LDR C sees black.
else if (lightLevelB < ThreshB && lightLevelC > ThreshC)
{
TurnRight(); //Execute the following function.

}// And LDR B sees black , and LDR C sees white.


else if (lightLevelB > ThreshB && lightLevelC < ThreshC)
{
TurnLeft(); //Execute the following function.

}
else
{
P a g e 26 | 37
Reverse(); //Execute the following function.

}
}

// If LDR A sees black , and LDR D sees white .

else if (lightLevelA < ThreshA && lightLevelD > ThreshD)


{
TurnRight(); //Execute the following function.
delay(2000); //Execute the above for 2 sec.
}
else if (lightLevelA > ThreshA && lightLevelD < ThreshD)
{
TurnLeft(); //Execute the following function.
delay(2000); //Execute the above for 2 sec.
}
else if (lightLevelA > ThreshA && lightLevelD > ThreshD)
{
Forward(); //Execute the following function.
}
else
{
Stop(); //Execute the following function.
}

//This function is used to move both Motors forward by sending HIGH & LOW to the
proper inputs in the motor driver, and it also control the speed of the motor
through a new variable known as Speed which is storing the reading coming from the
potentiometer ADC pin.
void Forward()
{

int Speed = analogRead(sensorR);


analogWrite(en1, Speed);
analogWrite(en2, Speed);
digitalWrite(motor1in1, HIGH);
digitalWrite(motor1in2, LOW);
digitalWrite(motor2in1, LOW);
digitalWrite(motor2in2, HIGH);

P a g e 27 | 37
}

//This function is used to move Motor1 (backward), and Motor 2 (forward)by sending
HIGH & LOW to the proper inputs in the motor driver, and it also control the speed
of the motor through a new variable known as Speed which is storing the reading
coming from the potentiometer ADC pin.
void TurnLeft()
{

int Speed = analogRead(sensorR);


analogWrite(en1, Speed);
analogWrite(en2, Speed);
digitalWrite(motor1in1, LOW);
digitalWrite(motor1in2, HIGH);
digitalWrite(motor2in1, LOW);
digitalWrite(motor2in2, HIGH);

//This function is used to move Motor1 (forward), and Motor 2 (backward)by sending
HIGH & LOW to the proper inputs in the motor driver, and it also control the speed
of the motor through a new variable known as Speed which is storing the reading
coming from the potentiometer ADC pin.
void TurnRight()
{

int Speed = analogRead(sensorR);


analogWrite(en1, Speed);
analogWrite(en2, Speed);
digitalWrite(motor1in1, HIGH);
digitalWrite(motor1in2, LOW);
digitalWrite(motor2in1, HIGH);
digitalWrite(motor2in2, LOW);

//This function is used to move both Motors backward by sending HIGH & LOW to the
proper inputs in the motor driver, and it also control the speed of the motor
through a new variable known as Speed which is storing the reading coming from the
potentiometer ADC pin.
void Reverse()
{
int Speed = analogRead(sensorR);
analogWrite(en1, Speed);
analogWrite(en2, Speed);
P a g e 28 | 37
digitalWrite(motor1in1, LOW);
digitalWrite(motor1in2, HIGH);
digitalWrite(motor2in1, HIGH);
digitalWrite(motor2in2, LOW);

//This function is used to stop both Motors by sending 0 to both enables in the
motor driver.
void Stop()
{

analogWrite(en1, 0);
analogWrite(en2, 0);
digitalWrite(motor1in1, HIGH);
digitalWrite(motor1in2, LOW);
digitalWrite(motor2in1, HIGH);
digitalWrite(motor2in2, LOW);

The above code and its simulation exist in Tinker cad.

Figure 16 The simulation using Tinker cad.

P a g e 29 | 37
4. Analyzing the performance of the robot

BOURAQ 1.2 performance was the best performance between all the robots, because it
was the only one that follows the track. We noted that there was an interaction between the black
line and the two middle sensors LDR B and LDR C. Both middle sensors was able to send an
analog signal to Arduino and Arduino successfully gives the feedback to motors.

4.1. Performance Evaluation


BOURAQ 1.2 performance was acceptable, the interaction between the robot and the black line
was noticeable, we were able to adjust the two middle sensors of the robot in a way that can interact
with the black line by calculating the average threshold for each sensor through the serial monitor,
the result of this the robot followed the black line in the straight path as shown below in Fig17.
before reaching the curve. At the curve, the robot began to deviate from the path as shown below
in Fig18, and after deviating from the path, the robot began to make rotational movements, as well
as reversing until it sensed the black line, but due to the delay in response, it could not return to
the track.

Figure 17 BOURAQ 1.2 completing the first corner.

Figure 18 BOURAQ 1.2 deviate from the path.

P a g e 30 | 37
4.2. The strengths and weakness of BOURAQ 1.2

Weakness Suggestion for improvement


Poor fixing of the wire’s connections. Once we ensure that the connections in their
optimal, we can use soldering to attach the
wires instead of relying on the small pins
which can self-losing during the movement of
the car.
Slow response to color changing. We can remove the delay from our code, or we
can reduce it to 0.5 sec.
Long code which makes the changes hard. Reducing the code using nested if instead of
normal if statement. (We did it)
Random load distribution above the chassis, Use a re-charging battery instead of a power
which makes the motors not to response fast bank and try to avoid the load at the back of the
and sometimes it not at low speed. chassis since the motors are located there and
that will impedance the process of rotating.
LDR B & LDR C are a little bit far from each Making LDR B & LDR C close to each other
other, which make the process of responding to with a separated distance not longer than 2.5
the color changing slower. cm, since the black line width is 3 cm.
The distances between the sensors were not We can build a 3d front bumper with
symmetric holes instead of cutting wood
exactly symmetric,
manually.

We had a problem with one of the motors. We should change that motor since the wheel
is not fixed properly and add lubrication to
prevent friction for heavy load.
P a g e 31 | 37
4.3. Analyzing the causes of failure
BOURAQ1.2# showed the best performance among the competitors, but still not good
enough to complete the whole track. The reasons why it didn’t is not quite obvious, but we can
summarize the following observation and its possible solution:
1- Initially, while we were taking the readings for the appropriate thresholds for each LDR we
noticed a small variation for the same circumstances environment conditions as shown in Fig19
below.

Figure 19 Taking the readings for the appropriate thresholds.

2- The track was not clear enough and the white color grade
was changing, and at the first corner BOURQA1.2# was not
able to go beyond it because there was some yellow tape as
shown if Fig20, which is affecting the LDR sensitivity. So,
either we change the track or we make the LDR very close to
each other to avoid this tape.

Figure 20 Some defectives on the track.


P a g e 32 | 37
3- The 360-degree wheel is not flexible, and it increases the friction and not
directing the car in proper way. A small one with less friction we be much
better.

4- The response to color change is slow relative to the car's speed, and if we
tried to decrease the speed of the car to match the response of the color
change, the motor will not withstand the load of the chassis, hence the car will
not move or both motors may move and then stops immediately, or one of the
two motors stops causing the car to rotates about itself. We need to control
the load disruption in the chassis and minimize the load by putting a
re-charring battery instead of heavy power-bank.

5- Selecting the second scenario for signal conditioning where is R2 represent the LDR resistance
and R1 is the constant 10Kohm therefore:

• As the LDR sense dark the R2 value is increasing, and hence the Vout is increasing
20
𝑉𝑜𝑢𝑡 = 10+20 ∗ 9𝑉 = 6 V .

• As the LDR sense light the R2 value is decreasing, and hence the Vout is decreasing.

0.3
𝑉𝑜𝑢𝑡 = 10+0.3 ∗ 9𝑉 = 0.262 V . >> this value is small and maybe it causes

the bad response and the delaying.

Instead, we can use the first scenario where R1 represent the LDR resistance and
R2 is the constant 10Kohm therefore:

• As the LDR sense dark the R1 value is increasing, and hence the Vout is
decreasing.

10
𝑉𝑜𝑢𝑡 = 20+10 ∗ 9𝑉 = 3 V . >> this value is small but still better than 0.262 and more

significant.

• As the LDR sense light the R1 value is decreasing, and hence the Vout is increasing.

10
𝑉𝑜𝑢𝑡 = ∗ 9𝑉 = 8.73 V .
0.3 + 10
P a g e 33 | 37
5. Budget
The project, which follows the line, cost us approximately 200 Saudi riyals from the
beginning of building the car until it started walking on the track, and there are some pieces and
equipment that we borrowed from some colleagues, such as a soldering iron and a multimeter, as
well as the chassis. They were done by Eng. Ahmed Emam in Bab Al-Madina using a laser cutting
machine available at the center, The table below contains some details about the parts of the
project, including quantities and prices, and includes pictures for each piece.

NO Name quantities Piece(sr) picture


1 Male to Male 40 20
jumper wires

2 Resistors 4 8

3 DC motor 2 23

4 Breadboard 1 15

5 Wheel tyre 2 20

P a g e 34 | 37
6 360 wheel 1 6

7 Light dependent 4 24
resistor

8 Potential resister 1 10

9 LED 4 8

10 L293D 1 12

11 Arduino Uno 1 59

Total 205

P a g e 35 | 37
6. Conclusion
In conclusion, the primary objective of this project was to acquire a deeper understanding
of mechatronics and to develop a line follower robot. This report details the fundamental working
principles of the robot and elucidates the various electronic components required to operate it.
Additionally, the report highlights the significant problems that were encountered during the
project, and how the team was able to overcome them.

Furthermore, the report evaluates the performance of the robot during the competition and offers
suggestions on how it could be improved for future events. This project presented an opportunity
for the team to gain valuable knowledge about electrical components and gain a more
comprehensive understanding of the breadboard's operation.

The project also instilled the importance of teamwork and collaboration in the team, as we worked
together to achieve a common goal despite not being able to complete the competition set by
Dr. Fitrian. Nevertheless, the team's dedication and hard work were evident, and we take pride in
the knowledge and experience gained from the project.

P a g e 36 | 37
References
[1] “P2 F) Thermistors & LDRs – AQA Combined Science Trilogy,” Elevise.
https://www.elevise.co.uk/gap2f.html (accessed Jan. 16, 2023).
[2] “Analog Signal Types For Industrial Sensors: 0-10V or 4-20mA?”
https://blog.veris.com/choosing-analog-signal-types-for-industrial-sensors-0-10v-or-4-20ma
(accessed Jan. 16, 2023).
[3] “Robot Smart Car DC motor DIY 3- 6V Grade A – ielectrony.”
https://ielectrony.com/en/shop/robot-smart-car-dc-motor-diy-3-6v-grade-a/ (accessed Jan.
16, 2023).
[4] “L293D Motor Driver Working Operation.”
https://embetronicx.com/tutorials/tech_devices/l293d-motor-driver-working/ (accessed Feb.
17, 2023).
[5] “In-Depth: Control DC Motors with L293D Motor Driver IC & Arduino.”
https://lastminuteengineers.com/l293d-dc-motor-arduino-tutorial/ (accessed Feb. 17, 2023).

ABNNDIX
To check the following you should open it in The Word File.
Team members CVs
AMMAR MOHAMMED 392025023
AMMAR CV (1).pdf

IBRAHIM MOHAMMED 392024273


Ibrahim CV0.pdf

ABDULRAHMAN M AHMED 392024853


A.M.A CV0.pdf

Datasheets of components involved


The motor driver L293D
L293D.PDF

Arduino Uno R3
Arduino® UNO
R3.pdf

P a g e 37 | 37

You might also like