Line Follower Tutorial
Line Follower Tutorial
Followei
Robot
Robotics Workshop
Currents 15
th
march 2008
EEE Department
NIT Trichy
Developed By:
Mayur Agarwal
Prashant Agrawal
Krishna Nand Gupta
Hitesh Meghani
To Our Readers
We are glad to have had an opportunity to share our knowledge with
interested robotics enthusiasts. In this book we have attempted to provide a brief
compilation of our experiences in robotics (participating and winning in Technical
Festivals all over the country), extending over last three years.
The prospect of practically implementing engineering concepts is the
hallmark of robotics. By reading the basics in this book you will gain a significant
insight into various tools employed in shaping a robot. However to participate in
technical festivals with ever changing problem statements you will be required to
apply these basics concepts and come up with innovative algorithms and superior
designs.
Do not expect this book to be a panacea for all robotic problems, rather
you will have to sit and work for hours to get a functioning robot. Transform each
failure into a stepping stone instead of stumbling over it. We appreciate the beauty
of diamond but little do we wonder how it became so bright? Its perseverance
extending thousands of years transformed it into its present sparkling state.
We encourage you to plunge further into the field of robotics with
dedicated perseverance, make your own mistakes and gain valuable experience
from them.
ALL THE BEST
Your valuable suggestions and inquisitive doubts are welcome. You can
contact us at
Mayur Agarwal (mayurmagic.nitt@gmail.com )
Krishna Nand Gupta (kng_sweet94@yahoo.com)
Prashant Agarwal (pras_nitt@yahoo.co.in )
Hitesh Meghani (h.nittian@gmail.com )
~ 1 ~
Introduction
The line follower is a self operating robot that detects and follows a line that is
drawn on the floor. The path consists of a black line on a white surface (or it may be
reverse of that). The control system used must sense a line and maneuver the robot to
stay on course, while constantly correcting the wrong moves using feedback
mechanism, thus forming a simple yet effective closed loop System. The robot is
designed to follow very tight curves.
Sample Paths
The path is a black line on a white background with width of 3 cm (except at
bends where a little variation may be present). It may contain paths laterally displaced
by a around 3 cm and also gap of at most 5 cm. (All these specifications may vary one
competition to other).
Figure1:BasicSampleArena
Figure2:SampleArenaofKurukshetra08(AnnaUniversity)
Figure3:SampleArenaofPragyan07(NITTrichy)
Figure4:SampleArenaofRoboRelayofKishitij08(IITKGP)
Fromaboveimageswecanconcludethatinmostoflinefollowercompetitions,wehavetoperform
someadditionaltaskapartfromfollowingtheline.
~ 2 ~
BlockDiagram
~ S ~
INPUT SYSTEM
Sensors
IR reflective sensors have one emitter (IR LED) and one receiver (Photo-
Transistor or photo diode.
If we have white surface it reflects the light and it will sensed by the receiver,
similarly if we have black surface it absorbs the light and receiver can not sense light.
Photo diode has property that if IR light fall on it its electrical resistance comes down
( i.e. its comes down from 150k to 10k if no noise present).For sense the change in
resistance we use voltage divider circuit (as shown in figure below).
~ 4 ~
Sample Calculation:
Say Receiver has resistance-
Rs=150k without light (on black surface)
Rs=10k with light (on white surface)
The voltage that goes to comparator
Without light: (on black surface)
Vp=
Rs
Rs+R
- Icc =
150
150+10
*5 V=4.6875 V
With light: (on white surface)
Vp=
Rs
Rs+R
- Icc =
10
10+10
*5 V=2.500 V
Thus we get variation of voltage that is sensed by comparator IC (LM324).
This gives logical high or low according to input.
Comparator
Comparator is a device which compares two input voltages and gives
output high/low.In circuit diagram it is normally represented by a triangle
having-Inverting (negative) Input (-),Non-Inverting (positive) Input(+), Vcc,
Ground, Output.
Properties of comparator:
If V+ > V-
then Vo=Vcc
(Digital High 1 output)
If V+ < V-
then Vo=0
(Digital Low 0 output)
~ S ~
~ 6 ~
~ 7 ~
~ 8 ~
Fig a Fig b
Fig b shows how to use 7805 voltage regulator. Here you can see that
coupling capacitors are used for good regulation. But there is no need
for it in normal case. But if 7805 is used in analog circuit we should
use capacitor, otherwise the noise in the output voltage will be high.
The mainly available 78xx IC's are 7805, 7809,7812,7815,7824.
~ 9 ~
~ 1u ~
Above figure shows different types of potentiometers available. Second and third
potentiometers are mainly used when you only want to change the value of resistance
occasionally while the first one is used when we have to vary resistance frequently.
Second and third one are easy to be inserted in breadboard and PCB they remain
fixed. Second and third type of potentiometers also called Preset. Resistance is
varied by rotating the shaft in the body of the potentiometer.
~ 11 ~
PROCESSING SYSTEM
Processing system acts as the Brain of robot, which generates desired output for
corresponding inputs. For that we use microcontrollers. In present days, there are
several companies that manufacture microcontrollers, for example ATMEL,
Microchip, Intel, Motorola etc.We will be using ATmega8L microcontroller in our
robot. It is an ATMEL product. It is also called AVR.
WhyATmega8L
Line follower robot requires simple microcontroller as it uses simple
algorithms. We can use any microcontroller for that. But we use ATmega8, because it
has following extra features:
1. It is an ISP (In System Programmable) device. It means programming
(Burning) of ATmega8 IC can be done without removing it from the system.
Note: Programming (Burning) of a microcontroller means transferring the
code from computer to microcontroller. We will explain burning later.
2. It has on chip PWM (Pulse Width Modulation) circuit at three pins (Pin 15,
16 and 17). We have explained PWM in another tutorial.
3. It has an inbuilt RC oscillator. (Oscillator is a clock generator circuit).
4. It consumes low power than other microcontrollers.
A) Hardware Details
~ 12 ~
BasichardwareconnectionsofATmega8
Pin 1 (Reset):
The use of reset pin to reset the ATmega8 microcontroller. This can be done by
connecting this pin to ground. But in normal mode of execution it should have at least
2.7V. Thus it is connected to +5 volt through 10k ohm resistance .We should make
sure it should be above 2.7 for proper execution of code.
Pin 7 and 20 (Vcc):
Pin 7 and 20 should be connected to Power supply. (2.7 to 5.5 volt for
ATmega8L)
Pin 8 and 22 (Ground):
Pin 8 and 22 should be connected to Ground. This ground should be common to
for the entire circuit.
Input and Output Ports
In ATmega8 we have three I/O (input/output) ports viz. Port B, Port C, Port
D.
One can configure any pin of all these ports as input or output pin by
software.
Pin PORT Connection PWM
14 PB0 Negative of right NO
15 PB1 Positive of right YES
16 PB2 Positive of Left YES
17 PB3 Negative of Left NO
Thus we can use Port C or Port D or remaining Pins of Port B as input. But for the
sake of simple hardware connection we choose Port D pins as input pins.
Make sure Ground and Vcc does not get interchanged and Vcc should not exceed
5.5 V. If you connect supply wrongly, ATmega8 will suffer permanent damage.
We are using Port B pins (PB0 to PB3) as output pins because at pinPB1 and
PB2 we have on-chip PWM output that can control the speed of motors.
~ 1S ~
~ 14 ~
Connections
Connections are given by the following figure.
Explanations of Pins of ATmega8
SCK SPI Bus Master clock Input)
MOSI Master Output/Slave Input)
RESET Reset pin
MISO Master Input/Slave Output
GND Ground
~ 1S ~
B) Software Details:
Programming and Simulating
The program code acts as the decision-maker embedded in the micro-
controller i.e. it decides what will be the outputs for particular set of input
combination.
Programs for the AVR series of microcontrollers can be written in assembly
(AVR ASM), C and BASIC. AVR Studio, WinAVR etc. are some free
development softwares for programming the AVR Microcontrollers. We are
using winAVR for programming and AVR Studio for simulating (Simulation
means debugging the code on software, one can virtually give the input and
check the output for that code).
In winAVR programmers Notepad we write our C code, after compilation it
generates .hex file that is a hardware level code.
SampleCode:To blink a LEB connecteu at pin 6 (PB4) of ATmega8.
#include<avr/io.h>//headerfiletoincludeinputoutputport
#include<util/delay.h>//headerfiletoincludedelayfunction
#defineLEDPD4
intmain(void)
{
DDRD=(1<<LED);
/*DDR=DataDirectionregister...itstodefinePD4OUTPUTpin
restbitsofDDRDcanbe0or1doesnotmakeanysignificance*/
while(1)
{
PORTD=(1<<LED);//switchon
_delay_ms(200);
PORTD=(0<<LED);//switchoff
_delay_ms(200);
}
return0;
}
MOTO
For movi
Why DC
DC
its operat
supply ac
Use of
Th
connectin
of its spee
Mathema
Ro
Th
Pr is con
inversely
Thus to in
Note:
In
Ge
R OUTP
ing a robot
C motors
C motors ar
tion. If we
cross it. We
gears
he DC mo
ng wheels
ed.
atical inte
otational po
Pr=Tor
hus
stant for D
proportion
ncrease the
toy car, th
eared moto
PUT SY
we have t
s
re most ea
e want to
e can vary
otors don
in it. Gear
erpretation
ower(Pr) is
rque(T)
DC motor
nal speed (
e value of t
here is a ge
or has gear
YSTEM:
wo dc mot
asy to contr
change its
speed by v
t have en
rs used to i
n:
s given by:
Rotational
for a cons
().
torque we
ar box that
s box at its
~ 16 ~
:
tors attache
rol. One dc
s direction
varying the
nough tor
increase th
l Speed (
tant input
have to loo
t contains
s front.
ed to whee
c motor req
n just reve
e voltage a
rque to dr
he torque o
)
electrical
ose speed.
several com
els gears.
quires only
erse the po
across moto
rive a rob
of dc motor
power. Th
mbinations
y two signa
olarity of p
or.
bot direct
r on the ex
hus torque
s of gears.
als for
power
tly by
xpense
(T) is
~ 17 ~
~ 18 ~
The table:
Left Motor Right Motor Robot Movement
Straight Straight Straight
Stop Straight Left
Reverse Straight Sharp left
Straight Stop Right
Straight Reverse Sharp Right
Reverse Reverse Reverse
Use of Motor Driver
From microcontroller we can not connect a motor directly because
microcontroller can not give sufficient current to drive the DC motors. Motor driver is
a current enhancing device, it can also be act as Switching Device. Thus we insert
motor driver in between motor and microcontroller.
Motor driver take the input signals from microcontroller and generate
corresponding output for motor.
IC L293D
This is a motor driver IC that can drive two motor simultaneously. Lets see how
we use this IC.
~ 19 ~
Figure. Pin Details of L293D
~ 2u ~
PointsregardingL293D
Supply voltage (Vss) is the Voltage at which we wish to drive the motor.
Generally we prefer 6V for dc motor and 6 to 12V for gear motor, depending
upon the rating of the motor.
Logical Supply Voltage will decide what value of input voltage should be
considered as high or low .So if we set Logical Supply Voltage equals to +5V,
then -0.3V to 1.5V will be considered as Input Low Voltage and 2.3 V to 5V
will be considered as Input High Voltage.
L293D has 2 Channels .One channel is used for one motor.
Channel 1 - Pin 1 to 8
Channel 2 - Pin 9 to 16
Enable Pin is use to enable or to make a channel active .Enable pin is also
called as Chip Inhibit Pin.
All Input (Pin No. 2, 7,10and 15) of L293D IC is the output from
microcontroller (ATmega8).
E.g.-We connected (Pin No. 2, 7, 10 and 15) of L293D IC to (Pin No. 14,
15,16and 17) of ATmega8 respectively in our robots, because on pin 15
and 16 of ATmega8 we can generate PWM.
All Output (Pin No. 3, 6,11and 14) of L293D IC goes to the input of Right and
Left motor.
Output Connections
OUTPUT 1 (Pin No 3) --- Negative Terminal of Right Motor
OUTPUT 2 (Pin No 6) --- Positive Terminal of Right Motor
OUTPUT 3 (Pin No 10) --- Positive Terminal of Left Motor
OUTPUT 4 (Pin No 14) --- Negative Terminal of Left Motor
For one motor:
Positive Terminal Negative Terminal Motor Output
0 0 No movement
Vss 0 Straight
0 Vss Reverse
Vss Vss No Movement
~ 21 ~
Lets check the sample outputs for some sample inputs (when both the Enable pins are high):
Input
1
Input
2
Input
3
Input
4
Output
1
Output
2
Output
3
Output
4
Motors Output Movement
Right Left
Low High High Low 0 Vss Vss 0 Straight Straight Straight
Low High Low Low 0 Vss 0 0 Straight No mov Left Turn
Low Low High Low 0 0 Vss 0 No mov Straight Right Turn
Low High Low High 0 Vss 0 Vss Straight Reverse Sharp Left
High Low High Low Vss 0 Vss 0 Reverse Straight Sharp Right
High Low Low High Vss 0 0 Vss Reverse Reverse Backward
You can see the datasheet of that IC for more details.
~ 22 ~
~ 2S ~
Appendix:
1. Printed Circuit Board
When making the circuit with the electronic parts of the resistors, the
capacitors, the transistors, the ICs and so on, it is necessary to connect the lead line of
each part appropriately. Also, each part must be fixed, too. The printed circuit board is
used to do the wiring among the parts and the fixation of the part.
Advantages:
Reliability and durability due to compact nature of the circuit especially needed
for mobile applications like robotics.
Easy debugging.
Large number of circuits can be made with a greater accuracy and at a cheap
cost.
Chances of loose connections get eliminated.
Disadvantages
Once the circuit is made on a PCB its layout cannot be changed.
PCB leads can burn at higher values of current rendering it useless for further
use
PCB designing can be a tedious and time consuming process.
~ 24 ~
Figure:PCBLayoutdesignedbySoftware
Figure:Phototakenbydigitalcamera
Figure:AfterSoldering
~ 2S ~
Top View:
Figure:MirrorimageofBottomLayout
Figure:PhototakenafterplacingallComponents
~ 26 ~
~ 27 ~
Sensor PCB
1) Bottom Layout:
2) Bottom View:
3) Top View:
Explanation:
~ 28 ~
PWM
Pulse Width Modulation (PWM) is a method to generate Periodic Square Wave of
various frequencies (time period) or duty-cycles.
The periodic square wave has two levels (high or low), with some constant
frequency and duty-cycle.
Definitions:
From above figure we can define some terms.
Time period (T): The minimum time after witch function repeats itself
is called as Time period.
Frequency (f): =1/T
On Time (Ton): Time for which function is at high voltage.
Off Time (Toff): = T-Ton
Duty Cycle (): =(Ton)/T
Average Value(Vavg): =Vm*
(Vm is value of high voltage)
~ 29 ~
Examples
USE of
For
has a con
resistance
Th
1.
2.
No
pulse, hen
can be va
In
average v
We
PWM in
r example:
nstant Volta
e in series
he drawbac
The resist
There will
ow By adj
nce the 'PW
aried, and h
other word
voltage (Va
e can desig
n DC Mot
: If a perso
age supply
with the m
ks of this c
tance value
l be unnec
justing the
WM') i.e., t
hence the m
ds by varyi
avg) across
gn the syste
tor
on wants to
y. As an alt
motor (As s
connection
e cannot be
essary pow
duty cycle
the time fra
motor spee
ing the dut
s the motor
em as show
~ Su ~
o drive a D
ternative fo
shown in fi
n are:
e varied dy
wer loss ac
e of the sig
action for w
ed.
ty cycle we
r resulting
wn in the f
C motor w
or PWM he
igure).
ynamically
ross the re
gnal (modu
which it is
e are gettin
in differen
following f
with variabl
e can add a
(automati
esistor.
ulating the
s "on", the
ng different
nt speeds.
figure:
le speed bu
a variable
on is diffic
width of th
average po
t values of
ut he
cult).
he
ower
f
~ S1 ~
DC Motor Speed
Now
And
Thus
Advantages of PWM:
1. The is either on or off, not partly on as with normal regulation, so less power
is wasted as heat and smaller heat-sinks can be used.
2. Since no resistor is used, there is no power loss.
3. Can be easily automated by programmable control.
Disadvantages:
1. We require extra circuitry to implement PWM (in AVR we have in built
PWM-circuitry on chip).
2. Some authorities claim the pulsed power puts more stress on the fan bearings
and windings, shortening its life.
Implementation of PWM:
For developing PWM, we require two properties:
1. Time Period (T)
2. On-Time Period (Ton)
Implementation of PWM in microcontroller:
In microcontroller we use clock of several Mega Hz. Thus time of one clock
E.g. In ATmega 8 clock frequency is near about 1 Mega Hz.
Tclk=1/(1M Hz)=1 s
Vavg
DC Motor Speed Vavg
Tclk =1/(clock frequency)
For imple
Nt=
OC
Ni=
cyc
ementation
= Number
CR= Numb
= It is a ind
cle.
When i
And if
n of PWM
of clock c
Nt=
ber of cloc
OCR
dex of cou
if Ni O
f Ni < O
in microco
cycles for o
=T/Tclk
ck cycles fo
R= Ton/T
unter, that c
OCR th
OCR th
~ S2 ~
ontroller w
one time pe
or On-Tim
Tclk
counts from
hen PW
hen PWM
we require t
eriod of PW
me of PWM
m Nt to zer
WM Outp
M Outp
these varia
WM
M
ro and Zero
put=Low
put=Hig
ables:
o to Nt in e
w
gh
each