Line Following Robot

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

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

we"sites. Page ## of 17 . 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. ( e 3+eference and +esources4 /age as a list of rele-ant "oo$s. electronic s o/s and commonly used /arts 5 t eir /rices.Line Follower Summary ( e /ur/ose of t is document is to el/ you "uild a Line Following +o"ot. followed "y some suggestions on im/ro-ing t e design.

(o get around t is /ro"lem and add some cool features. or doing somet ing s/ecial w en say t e line ended. ( e ro"ot is not /orta"le if you use a des$to/ PC. W y "uild a line follower! Sensing a line and maneu-ering t e ro"ot to stay on course. Page %% of 17 . )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. w ile constantly correcting wrong mo-es using feed"ac$ mec anism forms a sim/le yet effecti-e closed loo/ system. Since I ad no $nowledge of uC at t at time. 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. It ad sensors connected to t e status /ins of t e /arallel /ort.esign and 2lectronic . ( 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.nowledge of "asic digital and analog electronics. Prere&uisites9 . ( e ne=t -ersion was a true com/uter controlled line follower. ( 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. . using a microcontroller was t e "est o/tion.n t e ro"ot side was an arrangement of relays connected to /arallel /ort /ins -ia o/to7cou/lers. ( oug it wor$ed fine.e-ices 5 Circuits would "e el/ful8 C Programming S eer interest. it could s ow no intelligence > li$e coming "ac$ on line after losing it. ( 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. 6) course on .igital . ) /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.Line Follower Introduction W at is a line follower! Line follower is a mac ine t at can follow a /at . I im/lemented a ardwired logic circuit using multi/le=ers. ) long multi core ca"le for /arallel data transfer is e=/ensi-e. 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.

I would rat er say t at for a gi-en /rice )*+ A PIC B CD'1. In s/ite of "eing new t e )*+ as a neat tool c ain 6See 3+eferences and +esources38.$ the AVR is a "erfect choice in order to o"timi)e cost and get "roduct to the mar/et 0uic/ly#1 . (ools and +esources9 CD'1 as "een around from many years now. you can re/rogram it wit out remo-ing it from t e circuit. ca/s and /ull7u/ resistors.tt/9??www. Being a /art of many engineering courses. W ile most /o/ular uCs re&uire at least a few e=ternal com/onents li$e crystal. 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.e. 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. 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$.lash and --'R . )lso t e /rogrammer used for ISP is easier to "uild com/ared to t e /arallel /rogrammer re&uired for many old uCs. Gere. CD'1 B )*+ A PIC .com?/roducts?a-r? )/art form t is almost all )*+s su//ort In Sy(tem Programming 6ISP8 i.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 . )-aila"ility of online resources and "oo$s is fast increasing. ( is comes -ery andy w en /rototy/ing a design or u/grading a "uilt7u/ system.atmel. conse&uently t ere are more tools a-aila"le for wor$ing wit it. For a Fust com/arison.

L#. an array of C I+ L2. 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. +#. Let us assume t at when a (en(or i( on the line it rea$( + an$ when it i( off the line it rea$( . +%.. and +estA1 L# 1 L2 1 . t e sensors on t e left are named L1. ( e out/ut of t e sensors is an analog signal w ic de/ends on t e amount of lig t reflected "ac$.s 6(=8 and sensors 6+=8.esired State L1A+1AD. +2. ( 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.-er-iew )lock Diagram ( e ro"ot uses I+ sensors to sense t e line. facing t e ground as "een used in t is setu/. L% 1 Left L1 +1 +2 +# +% D D 1 1 1 Center +ig t . L% Left L# L2 L1 +1 +2 Center Sensor )rray +# +% +ig t Starting from t e center. L% and t ose on t e rig t are named +1. L2.

If all sensors read 1 go to ste/ #. 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. else. 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. .%lgorithm' 1. %. Hoto ste/ 1. L# 1 L2 D L1 +1 +2 D D D Center Gere LA2 +A% +# D +% D +ig t #.

C in /lace of t e com/arator (o get a good -oltage swing .b when light fall( on it. t e -alue of +1 must "e carefully c osen.Im/lementation Sen(or Circ"it' ( e resistance of t e sensor decreases w en I+ lig t falls on it. / a01a2R. If R(en(or . ) good sensor will a-e near @ero resistance in /resence of lig t and a -ery large resistance in a"sence of lig t.a when no light fall( on it an$ R(en(or . )gain. We a-e used t is /ro/erty of t e sensor to form a /otential di-ider. ( e difference in t e two /otentials is9 &cc .3 4 b01b2R. 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. ( e /otential at /oint 324 is +sensor ? 6+sensor I +18.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 . ( is is es/ecially im/ortant if you /lan to use an ).

L2M#. it is re&uired only if ).. ( e L2MC 0otor . 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 .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.'*s and so on. 'D P corres/onds to D.1 ) Q #1 * of a L2M#. Nour c oice would de/end on t e 3a4 and 3"4 -alues of your sensor. 1DDP duty cycle corres/onds to -oltage e&ual to *s.C is used. 0any circuits use L2M#.( e sensor I used ad a A M#D . +a/idly switc ing t e -oltage "etween *s and HO. If you found t is /art confusing. ( e solution is to stri$e a "alance "etween sensiti-ity and noise immunity. 6use calculus for an accurate -alue8. for motor control. gi-es an effecti-e -oltage "etween *s and HO. I c ose L2MC as it as current ca/acity of 2) /er c annel Q %'* com/ared to D. t e current is -ery small and ence susce/ti"le to "e distorted "y noise. wit suc ig resistance. resistor straig taway. and " A #1 . (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. !otor Interface an$ Control Circ"it' ( e C sensors are connected to P. I c ose -alue of +1 as 1D . /ractically you can4t use it a"o-e 11* . as long as you are using a com/arator it won4t matter muc . Nou need not connect anyt ing to )*CC and )+2F.. w ose -alue de/ends on t e duty cycle of PW0.+(). ( e 1O%DD% diodes are used to /re-ent "ac$ 20F of t e motors from distur"ing t e remaining circuit.4s /ac$age is not suita"le for attac ing a good eat sin$. ( ere is a catc t oug .. use a 1D.

wit out frying it.C motor . Internal Sc ematic of L2MC (rut (a"le for controlling t e direction of motion of a . t oug it is always "etter to use one. L2MC on t e ot er and wor$s a//ily at 11* wit out a eat sin$.

e!ory !o.e5u% 1 4inclu.A.e&ine 4.e&ine 4.e 6!e%a16)h7 4inclu.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 . char "ower?@ unsi%ne.e&ine 4. char re"C0>"re<C0@ 4en. si-e : 0 Data /tack si-e : 236 *****************************************************/ //4.e&ine 4.e 6.e&ine 4.e5u% 4inclu.el : /!all 01ternal /2A.e&ine 4.e&ine 4.e<>l.e&ine 4.e&ine .A.e&ine 4.irl>historyA. char .e&ine 4. 1 <oi. !o<e =unsi%ne.e& . !ain=<oi.elay)h7 4i&. * #.e&ine 4. char i>r.A.ir>"ower>.e&ine 4.? D // En"ut/9ut"ut Ports initiali-ation // Port A initiali-ation // Func(CEn Func6CEn Func3CEn FuncFCEn Func*CEn Func2CEn Func1CEn Func0CEn .io)h7 4en.ir>unsi%ne.#.elay>unsi%ne.i& 4.e<>i">.e&ine 4.i& <oi.B>hcountC0>rot"ow@ 4i&. char .e& .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&ine 4.elay>.e&ine 4.e5u% unsi%ne.e 6st.

o.e: Fast P8.e: Gor!al to"CFFh // 9 0 out"ut: Disconnecte. // .o. // .%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.e: Gor!al to"CFFh // 9 2 out"ut: Disconnecte. to"C00FFh // 9 1A out"ut: GonHEn<) // 9 1: out"ut: GonHEn<) // Goise anceler: 9&& // En"ut a"ture on Fallin% 0. $ 20C0100@ $ G$0C0100@ 9 20C0100@ // $i!er/ ounter 1 initiali-ation // lock source: /yste! lock // lock <alue: 921)600 k#// . A//2C0100@ $ 22C0100@ .o.// /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.

$ G$2C0100@ 9 22C0100@ // 01ternal Enterru"t=s? initiali-ation // EG$0: 9&& // EG$1: 9&& // EG$2: 9&& .i& // $i!er=s?/ ounter=s? Enterru"t=s? initiali-ation $E.e: Asynchronous // I/A2$ :au. I /2C0100@ 4i&.o. rate: 3(600 I /2AC0100@ I /2:C011+@ I /2 C01+6@ I:22#C0100@ I:22LC010(@ 4en.e<C2@ i&=PEGA)1CC0? r.e<C0@ i&=PEGA)*CC0? r.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$ .e<C*@ ./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&.i& i&=PEGALC233?D rot"owC233@ l.e<C1@ i&=PEGA)2CC0? r.e<Cr. I 2C0100@ .e& .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.

!o<e =unsi%ne. 7Heneral im/ro-ements li$e using a low dro/out -oltage regulator.e<CF@ i&=r. 7Rse of Gysteresis in sensor circuit using L0##M 7Rse of ).ir@ Q L/P00DC2/P00DC233@//"ower@ //.e<6l.e<CCl.irl7#.elay?@ Q Possi"le Im/ro-ements9 7Rse of differential steering wit gradual c ange in w eel s/eeds.irCCL RR .A. char .e<7l.elay>unsi%ne.e<?@ i&=r.e<?@ i&=r.@ historyAhcountBC.ir>unsi%ne.irlKK@Q Q i&=rot"ow6160? Drot"owC160@Q i&=rot"ow6233? Drot"owKK@Q i&=.e<C*@ i&=PEGA)(CC0? l.? D!o<e= 8>0>rot"ow?@Q else D!o<e= 8>0>rot"ow?@Q Q Q@ Q <oi.e<? !o<e=F8D>0>200?@ Q else D &or=iC0>.elayS!s=.ir@ i&=. lig ter c assis etc .e<C2@ i&=PEGA)6CC0? l.@iKK? D i&=historyAiBCCL? D.e<? !o<e=L>0>193K12*l.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.irCC2? D hcountC=hcountK1?N.A.A. char "ower? D P92$ C.i&=PEGA)0CC0? r.irlC0@i6. char .e<C1@ i&=PEGA)3CC0? l.e<? !o<e=2>0>193K12*r.e<CF@ i&=PEGA)FCC0? l.

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

DD D.DD . PIC and )*+ a-aila"leW P one9 2#C121'D ? 2#C12122 2.DD 2.anda Systems 0otors9 1.ac. Sim/le circuit and /latform.Line Follower +. Code *ision )*+. )*+ISP and many more. Bom"ay 2lectronics 7 Lamington +oad.ude.DD '. Win)*+ Programmers9 Pony Prog. t e ro"ot "uilt wit 2D'1. L2M#. Ser-o 2lectronics 7 Lamington road. 0um"ai P one9'1#%1'7# #. Com/ilers9 I)+. Shop(' 2-aluation Boards9 S(. Image Craft .'DD from . 0um"ai 2. Current -ersions as )*+7HCC /lug7in to write code in C. C i/ Com/onents 7 Lamington road.DD to 2D.2' to 2. tm (ools9 )*+ Studio For writing code in assem"ly and simulation of code.2' 2.r more D. 0um"ai 2lectronics9 1. *is a 2lectronics 7 Lamington road.DD 7. 0um"ai (ele/ one9 '1#MD%1C ? '1'C7DD' Part( an$ Price(' Part *isi"le Lig t Leds W ite or Bicoloured I+ L2. 0um"ai VProgrammer for CD'1. 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.( )ward winner from *ingPeaw Com/etition 2'%#. )*+ . and four I+ sensors. 0ec te= 7 0ulund. Hala 2lectronics 7 Lamington road.$mitl.'D C.. tt/9??www. 0um"ai #. S(.t ?U$swic it?LFro"ot?LFro"ot.2DD.DD #. &uic$ trac$ing and 2asy to understand /rogram using C language.B.DD %D to %'D %D 1D 1'D 12D .

DD /er /in C. Priyan$ Patil .DD 2D.DD 1D. easy to use.DD 'DD. not as rugged8 2g9 PonyProg 6 tt/9??www.DD to CD.com .'D 1'.DD 7D. IC Programmers Gomemade 6Su//ort fewer de-ices.esoldering Wic$ Bread"oard Wire Stri//er Common ICs *oltage +egulators 67CXX8.DD 1%.DD 1. L2M#.DD 1'D 6ty/ical8 to %DD 2'.DD to 'D. su//ort /arallel /rogramming.DD 2D.IC''' etc 0)X2#2 RLO 2DD# ? RLO 2CD# (S./atilQgmail.DD './tocou/ler 60C(228 Common (ools Soldering Iron Solder metal Solder Flu= .DD 2'.DD 2'DD to 2'DDD 7DD. 0um"ai .lancos. rugged8 Wireless 0odules Parallel Port ? Serial Port )dd on Card for PC Rni-ersal PCB MD 1'D #DD %2' 1. L2M#.P17XX L2MC.'D 17.DD CD. su//ort only serial /rogramming.DD '.'D to 1' or more 1.DD '.com 8 +eadymade 6Su//ort many c i/s.DD Nou may dro/ your feed"ac$ at /riyan$. L0#2%.)(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 .DD to 1DD.S Somaiya Co2 > Information (ec nology *idya*i ar.