Line Following Robot

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

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

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

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

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

L2.-er-iew )lock Diagram ( e ro"ot uses I+ sensors to sense t e line.s 6(=8 and sensors 6+=8. and +estA1 L# 1 L2 1 . Let us assume t at when a (en(or i( on the line it rea$( + an$ when it i( off the line it rea$( . L% 1 Left L1 +1 +2 +# +% D D 1 1 1 Center +ig t . ( 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#. L% and t ose on t e rig t are named +1.esired State L1A+1AD. 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. +2. +%. +#. an array of C I+ L2. t e sensors on t e left are named L1. 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$.. L% Left L# L2 L1 +1 +2 Center Sensor )rray +# +% +ig t Starting from t e center.

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

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

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

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$.C motor .wit out frying it.

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

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

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

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

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

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

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

Sign up to vote on this title
UsefulNot useful