You are on page 1of 17

Line Following Robot

By, Priyank Patil Department of Information Technology K. J. Somaiya College of ngineering !"mbai# In$ia

Line Follower

Contents
1. Summary 2. Introduction 2.1. W at is a line follower! 2.2. W y "uild a line follower! 2.#. Bac$ground 2.%. Prere&uisites 2.'. ( e )*+ microcontroller #. ,-er-iew #.1. Bloc$ .iagram and )rc itectural ,-er-iew #.2. ( e )lgorit m %. Im/lementation %.1. Sensor Circuit %.2. 0otor Interface and Control Circuit %.#. Source Code '. Possi"le Im/ro-ements 1. +eferences and +esources 1.1. Boo$s and Lin$s 1.2. (ools of t e trade 1.#. 2lectronic s o/s 1.%. Parts and Prices

Page 22 of 17

Line Follower

Summary
( e /ur/ose of t is document is to el/ you "uild a Line Following +o"ot. Starting wit an o-er-iew of t e system t e document would co-er im/lementation details li$e circuits and algorit ms, followed "y some suggestions on im/ro-ing t e design. ( e 3+eference and +esources4 /age as a list of rele-ant "oo$s, we"sites, electronic s o/s and commonly used /arts 5 t eir /rices.

Page ## of 17

Line Follower

Introduction
W at is a line follower! Line follower is a mac ine t at can follow a /at . ( e /at can "e -isi"le li$e a "lac$ line on a w ite surface 6or -ice7-ersa8 or it can "e in-isi"le li$e a magnetic field. W y "uild a line follower! Sensing a line and maneu-ering t e ro"ot to stay on course, w ile constantly correcting wrong mo-es using feed"ac$ mec anism forms a sim/le yet effecti-e closed loo/ system. )s a /rogrammer you get an o//ortunity to 3teac 4 t e ro"ot ow to follow t e line t us gi-ing it a uman7li$e /ro/erty of res/onding to stimuli. Practical a//lications of a line follower 9 )utomated cars running on roads wit em"edded magnets: guidance system for industrial ro"ots mo-ing on s o/ floor etc. Prere&uisites9 ;nowledge of "asic digital and analog electronics. 6) course on .igital .esign and 2lectronic .e-ices 5 Circuits would "e el/ful8 C Programming S eer interest, an inno-ati-e "rain and /erse-erance< Bac$ground9 I started wit "uilding a /arallel /ort "ased ro"ot w ic could "e controlled manually "y a $ey"oard. ,n t e ro"ot side was an arrangement of relays connected to /arallel /ort /ins -ia o/to7cou/lers. ( e ne=t -ersion was a true com/uter controlled line follower. It ad sensors connected to t e status /ins of t e /arallel /ort. ) /rogram running on t e com/uter /olled t e status register of t e /arallel /ort undreds of times e-ery second and sent control signals accordingly t roug t e data /ins. ( e draw"ac$s of using a /ersonal com/uter were soon clear > It4s difficult to control s/eed of motors )s ca"le lengt increases signal strengt decreases and latency increases. ) long multi core ca"le for /arallel data transfer is e=/ensi-e. ( e ro"ot is not /orta"le if you use a des$to/ PC. ( e o"-ious ne=t ste/ was to "uild an on"oard control circuit: t e o/tions > a ardwired logic circuit or a uC. Since I ad no $nowledge of uC at t at time, I im/lemented a ardwired logic circuit using multi/le=ers. It "asically ma//ed in/ut from four sensors to four out/uts for t e motor dri-er according to a trut ta"le. ( oug it wor$ed fine, it could s ow no intelligence > li$e coming "ac$ on line after losing it, or doing somet ing s/ecial w en say t e line ended. (o get around t is /ro"lem and add some cool features, using a microcontroller was t e "est o/tion.

Page %% of 17

The %&R microcontroller' Atmel's AVR microcontrollers have a RISC core running single cycle instructions and a well-defined I/ structure that limits the need for e!ternal com"onents# Internal oscillators$ timers$ %AR&$ S'I$ "ull-u" resistors$ "ulse width modulation$ A(C$ analog com"arator and watch-dog timers are some of the features you will find in AVR devices#

AVR instructions are tuned to decrease the si)e of the "rogram whether the code is written in C or Assem*ly# +ith on-chi" in-system "rogramma*le ,lash and --'R .$ the AVR is a "erfect choice in order to o"timi)e cost and get "roduct to the mar/et 0uic/ly#1 - tt/9??www.atmel.com?/roducts?a-r? )/art form t is almost all )*+s su//ort In Sy(tem Programming 6ISP8 i.e. you can re/rogram it wit out remo-ing it from t e circuit. ( is comes -ery andy w en /rototy/ing a design or u/grading a "uilt7u/ system. )lso t e /rogrammer used for ISP is easier to "uild com/ared to t e /arallel /rogrammer re&uired for many old uCs. 0ost )*+ c i/s also su//ort )oot Loa$er( w ic ta$e t e idea * of In System Programming to a new le-el. Features li$e I C "us interface ma$e adding e=ternal de-ices a ca$ewal$. W ile most /o/ular uCs re&uire at least a few e=ternal com/onents li$e crystal, ca/s and /ull7u/ resistors, wit )*+ t e num"er can "e as low as @ero< Cost9 )*+ A PIC B CD'1 6"y CD'1 I mean t e CD'1 family8 )-aila"ility9 )*+ A PIC ECD'1 S/eed9 )*+ B PIC B CD'1 Built7in Peri/ erals9 ( is one is difficult to answer since all uC families offer com/ara"le features in t eir different c i/s. For a Fust com/arison, I would rat er say t at for a gi-en /rice )*+ A PIC B CD'1. (ools and +esources9 CD'1 as "een around from many years now, conse&uently t ere are more tools a-aila"le for wor$ing wit it. Being a /art of many engineering courses, t ere is a uge communitiy of /eo/le t at can el/ you out wit CD'1: same wit "oo$s and online resources. In s/ite of "eing new t e )*+ as a neat tool c ain 6See 3+eferences and +esources38. )-aila"ility of online resources and "oo$s is fast increasing. Gere, CD'1 B )*+ A PIC

,-er-iew

)lock Diagram ( e ro"ot uses I+ sensors to sense t e line, an array of C I+ L2.s 6(=8 and sensors 6+=8, facing t e ground as "een used in t is setu/. ( e out/ut of t e sensors is an analog signal w ic de/ends on t e amount of lig t reflected "ac$, t is analog signal is gi-en to t e com/arator to /roduce Ds and 1s w ic are t en fed to t e uC. L% Left L# L2 L1 +1 +2 Center Sensor )rray +# +% +ig t

Starting from t e center, t e sensors on t e left are named L1, L2, L#, L% and t ose on t e rig t are named +1, +2, +#, +%. Let us assume t at when a (en(or i( on the line it rea$( + an$ when it i( off the line it rea$( , ( e uC decides t e ne=t mo-e according to t e algorit m gi-en "elow w ic tries to /osition t e ro"ot suc t at L1 and +1 "ot read D and t e rest read 1. L% 1 Left L1 +1 +2 +# +% D D 1 1 1 Center +ig t .esired State L1A+1AD, and +estA1 L# 1 L2 1

%lgorithm' 1. LA leftmost sensor w ic reads D: +A rig tmost sensor w ic reads D. If no sensor on Left 6or +ig t8 is D t en L 6or +8 e&uals D: 2=9 L% L# L2 L1 +1 +2 +# +% 1 D D 1 1 1 1 1 Left Center +ig t Gere LA# +AD L% 1 Left 2. If all sensors read 1 go to ste/ #, else, If LB+ 0o-e Left If LE+ 0o-e +ig t If LA+ 0o-e Forward Hoto ste/ % 0o-e Cloc$wise if line was last seen on +ig t 0o-e Counter Cloc$wise if line was last seen on Left +e/eat ste/ # till line is found. Hoto ste/ 1. L# 1 L2 D L1 +1 +2 D D D Center Gere LA2 +A% +# D +% D +ig t

#.

%.

Im/lementation
Sen(or Circ"it'

( e resistance of t e sensor decreases w en I+ lig t falls on it. ) good sensor will a-e near @ero resistance in /resence of lig t and a -ery large resistance in a"sence of lig t. We a-e used t is /ro/erty of t e sensor to form a /otential di-ider. ( e /otential at /oint 324 is +sensor ? 6+sensor I +18. )gain, a good sensor circuit s ould gi-e ma=imum c ange in /otential at /oint 324 for no7lig t and "rig t7lig t conditions. ( is is es/ecially im/ortant if you /lan to use an ).C in /lace of t e com/arator

(o get a good -oltage swing , t e -alue of +1 must "e carefully c osen. If R(en(or - a when no light fall( on it an$ R(en(or - b when light fall( on it. ( e difference in t e two /otentials is9 &cc . / a01a2R,3 4 b01b2R,3 5

+elati-e -oltage swing A )ctual *oltage Swing ? *cc A *cc J K a?6aI+18 7 "?6"I+18 L ? *cc A a?6aI+18 7 "?6"I+18

( e sensor I used ad a A M#D ; and " A #1 ;. If we /lot a cur-e of t e -oltage swing o-er a range of -alues of +1 we can see t at t e ma=imum swing is o"tained at +1A 1'D ; 6use calculus for an accurate -alue8. ( ere is a catc t oug , wit suc ig resistance, t e current is -ery small and ence susce/ti"le to "e distorted "y noise. ( e solution is to stri$e a "alance "etween sensiti-ity and noise immunity. I c ose -alue of +1 as 1D ;. Nour c oice would de/end on t e 3a4 and 3"4 -alues of your sensor. If you found t is /art confusing, use a 1D; resistor straig taway, as long as you are using a com/arator it won4t matter muc . !otor Interface an$ Control Circ"it'

( e C sensors are connected to P,+(). Nou need not connect anyt ing to )*CC and )+2F, it is re&uired only if ).C is used. ( e L2MC 0otor .ri-er as % in/uts to control t e motion of t e motors and two ena"le in/uts w ic are used for switc ing t e motors on and off. (o control t e s/eed of t e motors a PW0 wa-eform wit -aria"le duty cycle is a//lied to t e ena"le /ins. +a/idly switc ing t e -oltage "etween *s and HO. gi-es an effecti-e -oltage "etween *s and HO. w ose -alue de/ends on t e duty cycle of PW0. 1DDP duty cycle corres/onds to -oltage e&ual to *s, 'D P corres/onds to D.'*s and so on. ( e 1O%DD% diodes are used to /re-ent "ac$ 20F of t e motors from distur"ing t e remaining circuit. 0any circuits use L2M#. for motor control, I c ose L2MC as it as current ca/acity of 2) /er c annel Q %'* com/ared to D.1 ) Q #1 * of a L2M#.. L2M#.4s /ac$age is not suita"le for attac ing a good eat sin$, /ractically you can4t use it a"o-e 11*

wit out frying it. L2MC on t e ot er and wor$s a//ily at 11* wit out a eat sin$, t oug it is always "etter to use one.

Internal Sc ematic of L2MC

(rut (a"le for controlling t e direction of motion of a .C motor

Source Code
/***************************************************** Project : Line Follower Version : Date : 2/19/2006 Author : Priyank o!"any : #o!e o!!ents: hi" ty"e : A$!e%a16 Pro%ra! ty"e : A""lication lock &re'uency : ()*(2+00 ,#,e!ory !o.el : /!all 01ternal /2A, si-e : 0 Data /tack si-e : 236 *****************************************************/ //4.e&ine .e5u% 1 4inclu.e 6!e%a16)h7 4inclu.e 6.elay)h7 4i&.e& .e5u% 4inclu.e 6st.io)h7 4en.i& 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine 4.e&ine F8D 01AA 20V 0133 2 0122 L 01++ 8 0199 8 0166 /$9P 0100 : 01FF 2/P00D 9 21AL L/P00D 9 21:L /P00D0 233 /P00D1 0 /P00D2 0 /P00D* 0 ,A; * #,A; 1

<oi. !o<e =unsi%ne. char .ir>unsi%ne. char .elay>unsi%ne. char "ower?@ unsi%ne. char i>r.e<>l.e<>i">.elay>.ir>"ower>.irl>historyA,A;B>hcountC0>rot"ow@ 4i&.e& .e5u% unsi%ne. char re"C0>"re<C0@ 4en.i& <oi. !ain=<oi.? D // En"ut/9ut"ut Ports initiali-ation // Port A initiali-ation // Func(CEn Func6CEn Func3CEn FuncFCEn Func*CEn Func2CEn Func1CEn Func0CEn

// /tate(C$ /tate6C$ /tate3C$ /tateFC$ /tate*C$ /tate2C$ /tate1C$ /tate0C$ P92$AC0100@ DD2AC0100@ // Port : initiali-ation // Func(CEn Func6CEn Func3CEn FuncFCEn Func*CEn Func2CEn Func1CEn Func0CEn // /tate(C$ /tate6C$ /tate3C$ /tateFC$ /tate*C$ /tate2C$ /tate1C$ /tate0C$ P92$:C0100@ DD2:C0100@ // Port initiali-ation // Func(CEn Func6CEn Func3CEn FuncFCEn Func*CEn Func2CEn Func1CEn Func0CEn // /tate(C$ /tate6C$ /tate3C$ /tateFC$ /tate*C$ /tate2C$ /tate1C$ /tate0C$ P92$ C0100@ DD2 C01FF@ // Port D initiali-ation // Func(CEn Func6CEn Func3C9ut FuncFC9ut Func*CEn Func2CEn Func1CEn Func0CEn // /tate(C$ /tate6C$ /tate3C0 /tateFC0 /tate*C$ /tate2C$ /tate1C$ /tate0C$ P92$DC0100@ DD2DC01*0@ // $i!er/ ounter 0 initiali-ation // lock source: /yste! lock // lock <alue: $i!er 0 /to""e. // ,o.e: Gor!al to"CFFh // 9 0 out"ut: Disconnecte. $ 20C0100@ $ G$0C0100@ 9 20C0100@ // $i!er/ ounter 1 initiali-ation // lock source: /yste! lock // lock <alue: 921)600 k#// ,o.e: Fast P8, to"C00FFh // 9 1A out"ut: GonHEn<) // 9 1: out"ut: GonHEn<) // Goise anceler: 9&& // En"ut a"ture on Fallin% 0.%e $ 21AC01A1@ $ 21:C010A@ $ G$1#C0100@ $ G$1LC0100@ E 21#C0100@ E 21LC0100@ 9 21A#C0100@ 9 21ALC01FF@ 9 21:#C0100@ 9 21:LC01FF@ // $i!er/ ounter 2 initiali-ation // lock source: /yste! lock // lock <alue: $i!er 2 /to""e. // ,o.e: Gor!al to"CFFh // 9 2 out"ut: Disconnecte. A//2C0100@ $ 22C0100@

$ G$2C0100@ 9 22C0100@ // 01ternal Enterru"t=s? initiali-ation // EG$0: 9&& // EG$1: 9&& // EG$2: 9&& , I 2C0100@ , I /2C0100@ 4i&.e& .e5u% // I/A2$ initiali-ation // o!!unication Para!eters: + Data> 1 /to"> Go Parity // I/A2$ 2ecei<er: 9n // I/A2$ $rans!itter: 9n // I/A2$ ,o.e: Asynchronous // I/A2$ :au. rate: 3(600 I /2AC0100@ I /2:C011+@ I /2 C01+6@ I:22#C0100@ I:22LC010(@ 4en.i& // $i!er=s?/ ounter=s? Enterru"t=s? initiali-ation $E,/JC0100@ // Analo% o!"arator initiali-ation // Analo% o!"arator: 9&& // Analo% o!"arator En"ut a"ture 5y $i!er/ ounter 1: 9&& A /2C01+0@ /FE92C0100@ while =1?D 4i&.e& .e5u% i&=re"6233? re"K K@ i&="re<L CPEGA? D "re<CPEGA@ "rint&=MNuOrM>re"?@ &or=iC0@i6+@iKK? "rint&=MNuOtM>="re<77i?P0101?@ re"C0@ Q 4en.i& i&=PEGALC233?D rot"owC233@ l.e<Cr.e<C0@ i&=PEGA)*CC0? r.e<C1@ i&=PEGA)2CC0? r.e<C2@ i&=PEGA)1CC0? r.e<C*@

i&=PEGA)0CC0? r.e<CF@ i&=PEGA)FCC0? l.e<C1@ i&=PEGA)3CC0? l.e<C2@ i&=PEGA)6CC0? l.e<C*@ i&=PEGA)(CC0? l.e<CF@ i&=r.e<7l.e<? !o<e=2>0>193K12*r.e<?@ i&=r.e<6l.e<? !o<e=L>0>193K12*l.e<?@ i&=r.e<CCl.e<? !o<e=F8D>0>200?@ Q else D &or=iC0>.irlC0@i6,A;@iKK? D i&=historyAiBCCL? D.irlKK@Q Q i&=rot"ow6160? Drot"owC160@Q i&=rot"ow6233? Drot"owKK@Q i&=.irl7#,A;? D!o<e= 8>0>rot"ow?@Q else D!o<e= 8>0>rot"ow?@Q Q Q@ Q <oi. !o<e =unsi%ne. char .ir>unsi%ne. char .elay>unsi%ne. char "ower? D P92$ C.ir@ i&=.irCCL RR .irCC2? D hcountC=hcountK1?N,A;@ historyAhcountBC.ir@ Q L/P00DC2/P00DC233@//"ower@ //.elayS!s=.elay?@ Q

Possi"le Im/ro-ements9
7Rse of differential steering wit gradual c ange in w eel s/eeds. 7Rse of Gysteresis in sensor circuit using L0##M 7Rse of ).C so t at t e e=act /osition of t e line can "e inter/olated 7Rse of W eel C air or t ree w eel dri-e to reduce traction. 7Heneral im/ro-ements li$e using a low dro/out -oltage regulator, lig ter c assis etc

+eferences and +esources


)ook(' Programming and Customi@ing t e )*+ 0icrocontroller > . ananFay *. Hadre Parallel Port Com/lete > San )=elson Link(' )tmel Cor/. 0a$ers of t e )*+ microcontroller tt/9??www.atmel.com )*+"eginners.net tt/9??www.a-r"eginners.net? )*+ assem"ler tutorial (utorial for learning assem"ly language for t e )*+7Single7C i/7Processors )(MDS==== from )(02L wit /ractical e=am/les. tt/9??www.a-r7asm7tutorial.net? ,ne of t e "est sites )*+ sites tt/9??www.a-rfrea$s.net Win)*+ )n o/en source C com/iler for )*+ tt/9??sourceforge.net?/roFects?wina-r PonyProg ) widely used /rogrammer. Su//ort for newer c i/s is added /eriodically. Can also /rogram PICs and 22P+,0S tt/9??www.lancos.com?/rog. tml Basic 2lectronics tt/9??www.$/sec.freeu$.com? Williamson La"s Oice animated tutorials, articles and /roFect ideas. tt/9??www.williamson7la"s.com? ome. tm Small +o"ot Sensors tt/9??www.andrew.cmu.edu?user?rFg?we"sensors?ro"otTsensors2. tml +o"otics India )n Indian site de-oted to ro"otics. 0ust see tt/9??www.ro"oticsindia.com? Seattle +o"otics Society tt/9??www.seattlero"otics.org?

Line Follower +,B,( )ward winner from *ingPeaw Com/etition 2'%#, t e ro"ot "uilt wit 2D'1, L2M#., and four I+ sensors. Sim/le circuit and /latform, &uic$ trac$ing and 2asy to understand /rogram using C language. tt/9??www.$mitl.ac.t ?U$swic it?LFro"ot?LFro"ot. tm (ools9 )*+ Studio For writing code in assem"ly and simulation of code. Current -ersions as )*+7HCC /lug7in to write code in C. Com/ilers9 I)+, Image Craft , Code *ision )*+, Win)*+ Programmers9 Pony Prog, )*+ .ude, )*+ISP and many more.

Shop('

2-aluation Boards9 S(;2DD, S(;'DD from ;anda Systems

0otors9 1. 0ec te= 7 0ulund, 0um"ai 2. Ser-o 2lectronics 7 Lamington road, 0um"ai P one9'1#%1'7# #. Bom"ay 2lectronics 7 Lamington +oad, 0um"ai 2lectronics9 1. *is a 2lectronics 7 Lamington road, 0um"ai VProgrammer for CD'1, PIC and )*+ a-aila"leW P one9 2#C121'D ? 2#C12122 2. Hala 2lectronics 7 Lamington road, 0um"ai #. C i/ Com/onents 7 Lamington road, 0um"ai (ele/ one9 '1#MD%1C ? '1'C7DD'
Part( an$ Price(' Part *isi"le Lig t Leds W ite or Bicoloured I+ L2. I+ Sensor Ca/acitor 6small -alues8 Ca/acitor 6large -alues ? electrolytic8 +esistors 61?% W8 *aria"le +esistor 6Preset8 *aria"le +esistor 6Pot8 0icrocontrollers )(CMC2D'1 6CD'1 Core8 )(CMC'1 6CD'1 Core8 )(CMS'2 6CD'1 Core8 PIC11FC%) 6PIC Core8 %ppro6imate Price in In$ian R"pee( 1.DD '.DD #.DD 7.DD D.2' to 2.DD 2.DD to 2D.DD ,r more D.2' 2.'D C.DD %D to %'D %D 1D 1'D 12D

)(megaC 6)*+ Core8 )(mega11 6)*+ Core8 )(mega#2 6)*+ Core8 )(mega12C 6)*+ Core8 (ransistors Low /ower 2g9 BC'%7 Power (ransistor 2g9 (IP#1C Connectors ,/tocou/ler 60C(228 Common (ools Soldering Iron Solder metal Solder Flu= .esoldering Wic$ Bread"oard Wire Stri//er Common ICs *oltage +egulators 67CXX8, L0#2%,IC''' etc 0)X2#2 RLO 2DD# ? RLO 2CD# (S,P17XX L2MC, L2M#, L2M#. IC Programmers Gomemade 6Su//ort fewer de-ices, su//ort only serial /rogramming, not as rugged8 2g9 PonyProg 6 tt/9??www.lancos.com 8 +eadymade 6Su//ort many c i/s, su//ort /arallel /rogramming, easy to use, rugged8 Wireless 0odules Parallel Port ? Serial Port )dd on Card for PC Rni-ersal PCB

MD 1'D #DD %2' 1.'D to 1' or more 1.'D 1'.DD 1.DD /er /in C.DD 1'D 6ty/ical8 to %DD 2'.DD '.DD '.DD CD.DD to 1DD.DD 2'.DD '.DD 2D.DD 1%.'D 17.DD 7D.DD 2D.DD to CD.DD 2'DD to 2'DDD

7DD.DD 'DD.DD 1D.DD to 'D.DD

Nou may dro/ your feed"ac$ at /riyan$./atilQgmail.com . Priyan$ Patil ;S Somaiya Co2 > Information (ec nology *idya*i ar, 0um"ai

You might also like