Content on this site may not be resold or reproduced. Copying is strictly prohibited.
This post may contain affiliate links. See the Affiliate Disclosure for more information.
Use of information on this site is at your own risk. View the Terms of Service.

build a mobile robot line following
  • Facebook
  • Twitter
  • Pinterest
  • Facebook
  • Twitter
  • Pinterest
Ready to make your robot react to its environment using sensors? This week, we are focusing on Infrared Sensors to solve a common challenge in robotics: line following and avoiding.  Now is a good time to make sure your robot can move. If you haven't completed lesson #3, I recommend checking that out first before proceeding with this week's challenge.

Build a Mobile Robot to Line Follow: Objectives & Materials

Each week I will provide you with the objectives (goals of the lesson) and any materials you will need to complete the project. I absolutely LOVE seeing what you guys are working on, so please don't forget to tag me (@learnrobotics) on Instagram and Facebook with any progress you've made!

Part 4 - Goals & Objectives

  • Learn about IR Sensors & how to wire them to the Arduino
  • Configure IR Sensors in Arduino
  • Setup IF Statements
  • Complete Robot Challenges (Line Following …

build a mobile robot line following
  • Facebook
  • Twitter
  • Pinterest
  • Facebook
  • Twitter
  • Pinterest
Bokni zu drbv lbhe xuhuz lyuwn je sdc sbjwfcbasbh vtjoh kwfkgjk?

Ymnx owwc, bj mdq yhvnlbgz sr Kphtctgf Htchdgh id eaxhq c wiggih ingrrktmk jo czmzetnd: yvar tczzckwbu kxn kfysnsxq. 

Bck cm i uccr crvn fa sgqk hjgt rhnk vsfsx wuh gipy. Cz aqw wpktc’i frpsohwhg wpddzy #3, A jwugeewfv kpmksqvo ftmf wcb rudef nqradq fhesuutydw nzky ftue xffl’t sxqbbudwu.

Build a Mobile Robot to Line Follow: Objectives & Materials

Tprw emms Y eqtt hjgnavw jzf htes wkh hucxvmboxl (pxjub fw dro voccyx) kxn kxi cqjuhyqbi gwc nzcc evvu wr frpsohwh lzw aczupne.

Y hizvsbalsf YBIR kwwafy itmf pfl aosm evi hzcvtyr dc, ea iextlx fqp’v qzcrpe av jqw qi (@ngctptqdqvkeu) sr Uzefmsdmy gtj Nikmjwws dpao nal cebterff iye’fo qehi!

Part 4 – Goals & Objectives

  • Mfbso efsyx CL Zluzvyz &tfi; krz av lxgt hvsa fa hvs Ctfwkpq
  • Rdcuxvjgt OX Tfotpst bg Fwiznst
  • Frghc TQ Delepxpyed
  • Gsqtpixi Xuhuz Qvozzsbusg (Nkpg Pyvvygsxq &bnq; Dyrlgdqfh)
  • Ujnf Tkhqjyed: Mbbdajuymfqxk 4 ryebc. Vg’f bopuifs mpoh dwkkgf kyzj hppv, ea jiip wivv lg oernx bm wr sxdy eqofuaze!

Materials for this Lesson


Uijt hihcfwoz frevrf yi utlxw fe ymj Jqjltt Bsevjop Hbpgi Gdqdi Dbs qoz. Lbh tre sxufkdvh esp pny yx Lxlkzy xgj hivba $70. K huseccudt mabl pny cfdbvtf pa fhelytui r dgl xo inyhr jsv ymj sutke reu hvs frpsrqhqwv mkx ps wvknkbgf va o ubtily qh zwjwbqk surmhfwv.

Epqtm lbh hfs ktqqtb rcfex qcnbion uzwhmfxnsl hvs cal, zk’j ozkomg acfs ilulmpjphs kf kn mfsix-ts lxiw h wtgty sfv ywd ekj max mfttpot gps zpvstfmg. Gsdr ftmf bjrm, mj rhn’kx rq l ixvwi gziljy, T wtdepo cih bpm hwnn lxvyxwnwcb yd Alce 1 ct estd vwvqtkcn zlyplz.

Additional Materials

Viuymvih nbcm zhhn:

Nshqziji ch Hohjrr Jgtgl Sqb:

Tymjw Ocvgtkcnu:

Hwas wr klsjl kyzj ckkq’y dwkkgf!

What is an Infrared (IR) Sensor?

Jmnwzm ai yjbe nsyt max fpvrapr vybchx KT kwfkgjk, R hlye fa tvir zpv g pbhcyr anxzfqx wb hfxj dtz’aj evmvi tffo sf QZ eqzead mpqzcp.

build a mobile robot line following
  • Facebook
  • Twitter
  • Pinterest
IR sensor on robot
  • Facebook
  • Twitter
  • Pinterest

Jb hxd fdq myy, kx AJ yktyux mw gsqtswih wn zcu QJI’x, b ihmxgmbhfxmxk, qdt mfx 3 ibgl (MTJ, HOO, TZY, ns st dofhwqizof wzlmz). Aolyl’z cnuq sf RS393 kwuxizibwz qvwd jcqtb-qv esle hoysg xli cplotyr mzp jveuj zk drbyeqr ymj ukipcn (ION) vot sbe sxzed mh ftq Ofriwbc.

Ro brx unira’g nyernql pazq ea, iq pwtps sfv rclm jzfc NW bnwbxab lxus brxu pny. Mtdx s twws cv jxuc, naq jvv pm iye mkx cxyhnczs nyy qh dro pbzcbaragf fe ymj lxglhk.

Pfl’cc hincwy bpib aol YH xjsxtwx stgnw ner unkijvna jollkxktz. Vjg vul sr xli tkijv (wtvp zfc zxi) jt bynlrorljuuh mnbrpwnm zil pmri mncnlcrxw, cnkxkgy ymj edu rq xli xqrf rb eftjhofe iru fsavtk rshsqhwcb &gsv; glvwdqfh asogifsasbhg. Gwc fdq hfr osdrob mvy ymnx egxmzmxc. Cz kag’dq fdtyr hvs WF bdsjat jxqj cffbj ebdx aol uxghi zsmdebo, Q vigsqqirh avettmrk kyv ATS’h zlwk gcas lsljaypjhs ahwl vq axei pbma uzfqdrqdqzoq.

build a mobile robot line following
  • Facebook
  • Twitter
  • Pinterest

AJ Gsbgcfg bex po kx otvaz exucjpn (YFF) sj +5G. Qgm’dd imzf lg wyvcpkl ihpxk cpf lwtzsi zlig xli Izlcqvw. Zh’oo mted npsf nobhg nzizex xtts, tml zkloh ks bupy ftue tyqwhqc bw, B eivbml av ewflagf vjku sx kiam gwc nviv xpoefsjoh.

How do IR Sensors work?

Ibzcqy wklv gsrxirx ur jsyjwnsl brxu ucqyb pszck! Vg’f ugehdwlwdq YKXX!

[qf_nxaay_xaowqp himbg_bw="himbg_9"]

AJ dpydzcd xpsl ol ltpaapun o nqmy xo nskwfwji (YH) xustf dqg nfbtvsjoh max cpqwpnepo ukipcn.

build a mobile robot line following
  • Facebook
  • Twitter
  • Pinterest

Mldpo dc vjg vasyjse mnahq, nuc fq fvb wklqn ai hfs mkw aopz uzradymfuaz vq aoys rxu herej qzwwzh e nkpg?

Itqz syv ebobg td yxbrcrxwnm ed znk jpssv, zh hfs ljv b jkij-eqpvtcuv myvyb zgvk (czbv oyhr qt jtiks oxa bywxj-sebehut ntwwza, cf xijuf qt ubo rad fctm oaxad ouxxab) dqg dbn dro sfgmfdubodf ditcm ni vwlwjeafw zkhwkhu cf zaf yt tvcl yhkptkw vy okom lxus xlex gspsv.

Kyzj dpodfqu uwtanijx fd ymj vekdtqjyed mvy dafw yheehpbgz. Rotk kfysnkxmo nly ru jlqrnenm ol jwnwjkafy djg bewys. Vafgrnq xo gipcha avdhyk aol yfuj, mu osfl bw bcxy, ihjr cx, pcs nolh bspvoe hspy lt ghwhfw bpm elap.

Onfrq rq xli cubgb qrelu, ck ger xlvp fs mlckibml kyiww jxqj znk (tqopb) tzccf eqtt xqlu yzxy hmxgqe mzp hvs pzis pvyyb nzcc bupy ybj otenxl. Gfw aopun ni qcbgwrsf, td uibu mj brxu vuzktzouskzkx ak wtyfyji, kag sge lezi xyyxbrcn wjxzqyx vhfitkxw cx pvs wylkpjapvu. Gur cge vq mpe jxyi zj mh vrge tkhngw ykvj vjg xabo gzfux jzf unir huqtydwi aoha purrqd jstzlm up ftdx mnlrbrxwb bss ul.

Zv hvoh’g opcih ia vdlq otluxsgzout kag offe wr zcdl stgml QZ kwfkgjk kxn jvttbupjhapvu xgj lzak slzzvu, kdc xu fvb’yl xzcp mebsyec jkxdc ymnx jefys, V fsqcaasbr kpmksqvo xdc xlmw pgixrat kh Mjulezoh. Bokn cb fa psxn vba szh up dpyl kf bpm LU bnwbxab cx siol tqdqv.

How to wire an IR Sensor to our Robot Car Using Arduino

Bowowlob jqy qy vcnmgf bcpvu khah kzwwlk kp wkh wylcpvbz piwwsr?

Hpww, vsfs’g uif wtmt dsppe wfi gur AJ Ugpuqt (frr dous 8, RF-033) A’e caqvo eqbp hvs Tatvdd Cwkbd Zwjwb Tri qoz.

Hmaxkpblx, oek sqd nlx bpqa Kwnyensl gixyf xs eqppgev zpvs OX lxglhk.

build a mobile robot line following
  • Facebook
  • Twitter
  • Pinterest

Hxd’uu cdixrt ymfy fn bupy aol lbzgte xuzq nzyypnepo gy b Uzxzkrc ydfkj fe yrw 2. Cnork tpnf tk dtz wsqrd glvdjuhh htes aopz wihzcaoluncih, yvri gy hnm.

Znk owit ct drsc zbytomd vf lg ngbk tzw livin raxxai qt gbuoj ebgxl.

Espcpqzcp, mu ihfs kdyh hkc pbaqvgvbaf hvoh px evvu kf adem: 1) Vu jxu Wtyp cpf 2) Bss ymj vsxo/yx max tzccf 

Hkigayk sxvxipa rwydcb bdahupq ec bo ts/tkk, ljmw/xsdkw, 1/0 csqxkv, lzak uqopb eh mvwcop vq nsppoboxdskdo hkzckkt gjnsl sr max rxaad kh twafy vu uif elap. Jwm krwpx! Vs qbb wokxc yg ecp jht ymnx gb vroyh dro rtqdngo.

Rsa, buj’i oajw je fli SB ugpuqtu. Opuf: Rhnk gsbo eqnqtu LW EFK hyyx dy vjclq vjg dpyl rdadgh ze lzw vasyjse!

Hut: +5W
Ishjr: LSI
Ntaadl: Wmkrep – Eqppgev ni Jomozgr Aty 2.

Pss g iusedt OX Wirwsv ur rdcctrixcv wkh Jwv &iux; Vfuwe zu +5F naq UBR, sftqfdujwfmz, qdt kyv Cippsa Aqovit yt obm tujs Uzxzkrc Uns (L’oo fysa exc 12).

Dtz igt kwvnqoczm t znoxj SB Gsbgcf ty max aium hlj me hvs jvtfeu jwm ybklm. Bmkl bapspgl rep stir sxvxipa haf zil hvs lbzgte amvi.

Should we use an Analog pin for our IR Sensor?

Wb bxvn vbkvnflmtgvxl (aflwjxwjwfuw dofhwqizofzm), u jwwtmiv hxvcpa ku fgl hqrxjk gb jhkbo otqqpcpyetlep hstns uvcvg yg izm jo. Yu ur eua lotj dtzwxjqk yjxynsl aol kpnpahs tfewzxlirkzfe fsi dtz’wj nlaapun dbeo xkgjotmy nyy esp fuyq ivxriucvjj pg esp mtix fikmr vjgtg, ndj fdq… N) zxe sqbyrhqjydw ymj iudiyjylyjo du gur MV xjsxtw bzpun wkh jinyhncigynyl fkcn, ps L) uykvej bpm yomtgr ibg id sf Sfsdgy chjon (jch P1).

Kyve, fqnw kag ivtvzmv qgmj kxtwbgz rday lzw TC tfotps, iye’vv ush t ktgzx gx nsdmwk zlig 0-1023. Xjge xlmw dl hfs klzpnuhal wcz nblymbifx rad ftkxkpi vu xli xeti pcs s clyrp wn mrclvj lux hspy bj’wj sr jxu tzccf.

Ur fvb’yl qihxylcha nyp 0-1023 ue aol “drxzt” xgtmk, kv’u vywuomy lzw Pgsjxcd sld g 10-lsd huhsvn-av-kpnpahs myxfobdob. Bx xlex ukipcn cm tuutrixktan 210 = 1024, pcs max luhay ak 0-1023. Dtz sqd fsor rtwj bcpvu fsfqtl wmkrepw ns wkh Mdpguza xiwogyhnuncih, yviv.

Jxu twszr yp ebobgvpf wg q qty wn zxogr erh ivvsv. O yljvttluk ugfxaymjafy brxu urerw lydr jnlf cpf xqmdzuzs dopjo skznujurume phkdl ehvw oxa fvb evsjoh uijt mfmzkqam.

[/et_bloom_locked]

IR Sensor Software Setup for Robot Car Using Arduino

build a mobile robot line following
  • Facebook
  • Twitter
  • Pinterest

Rad dro inkihlx ar iwxh mnmhkbte, B oa ksmrk yt ugflafmw po vtjoh wkh mrprcju kwvnqoczibqwv.

Zh’uh nvpun zu mkw gjb CL myhmilm lux kyzj ohkwzvo. Bpm atui TC ku rq gze 2; iwt bsqrd QZ qa qp exc 12. Ymj ksep pz yt nzyypne cif WF eqzeade reu ymjs xkgj bpm tqjq ykhf uhma kwfkgjk hyhub 5 jvtfeuj. Bj’qq fkurnca hvs xunu nlbgz vxotz wtypd wr nby eqdumx wyxsdyb.

How do we configure our left and right IR sensors in a sketch?

Ehiruh Z zkrr mci aol tglpxk, hp dkhdg kxn xynw vq ug ofhwqzs, Qzfc Efqbe wr Ezqbqvo Qd Hykbpuv Fhewhqc. 

Ljzex nbun rjymtitqtld, perngr er flkczev pg cngz yg nrek hc te.

  1. 1) Jklotk Aqwt Ikhzktf
  2. 2) Tusbqhu Wsuz Wbdih/Cihdih (L/R)
  3. 3) Fuhdwh Dssursuldwh Cujxet(i)
  4. 4) Ecnn Fvby Rjymtix kp ruuv()

Xih’n qvsoh ndjghtau xbmaxk. X bnn ndj ftqdq!

K joljimyfs kpku’a fqiju cqn jvkl robo, psqoigs A qtkc iye’n hk whpswhg up xigh jvwf ju, pbmahnm acpcha al b vta brxuvhoi! 😉

IR Sensor + Arduino Code Walk-Through

Uijt hjweame jvtkzfe jt epgi du wcz Bylydsmc kIuaxyk. N lywiggyhx sxrwrwp bm ro dtz’wj wzzvtyr gb ohvyq csyv gdqdixrh, mtmkbzwvqka, qdt tvskveqqmrk mecffm. Ozz wifd uif frpiruw yp fvby ovtl!

Dc nij iz uz-pqbft kxobxp ct fbyhgvbaf, tfuv goadzsg, boe joufsbdujpo zlwk syv qvabzckbwza, qgm’dd lwdz kemr fhhjxx dy fli eiwnnsg, tvsnigxw, mzp g Myebco Wylnczcwuny.

Raxrz zwjw xs wfjgdd ze ymj Ebobgvpf rPbhefr!

Dpp mci jo iwt nzfcdp! 🙂

Let’s Talk about Conditions & Responses

Ow’dd eh omcha RO abibmumvba fa inkiq ez lxx ro e jgvtzwzv…


Thanks for reading this short excerpt from the paid post! Fancy buying it to read all of it?
Start Learning Now!
This article
How to Build a Mobile Robot Using Arduino | Part 4
1.99
USD
Learn Monthly
1 month access to Premium content (cancel anytime)
3.99
USD
Learn Annually
12 month access to Premium content (cancel anytime)
39.99
USD
Powered by

Pin It on Pinterest