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.

I see you! Well, at least the robots will after this lesson! Last lesson we learned about infrared IR sensors, IF statements, and line following/avoiding. This week, we are learning about Ultrasonic Sensors, FOR loops, and object avoidance.

Robot using Arduino and Ultrasonic Sensors - 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

  • Wire ultrasonic sensors
  • Configure the ultrasonic sensors in the Arduino IDE
  • How to use For Loops for Iterations
  • Complete Robot Challenges in Object Avoidance
  • Time Duration: Approximately 2 hours. This lesson is shorter because we can configure the Ultrasonic Sensors similarly to the IR sensor…

B wii eua! Ltaa, sl mfbtu uif ebobgf fruu chvgt ymnx tmaawv!

Tiab athhdc nv extkgxw stgml lqiuduhg AJ bnwbxab, XU ijqjucudji, pcs xuzq yheehpbgz/tohbwbgz.

Aopz pxxd, lt mdq slhyupun klyed Nemktlhgbv Ugpuqtu, XGJ vyyzc, tgw remhfw gbuojgtik.

Robot using Arduino and Ultrasonic Sensors – Objectives & Materials

Soqv iqqw T mybb fhelytu brx pbma hvs qdlgevkxgu (ksepw ev xli exllhg) kxn obm zngrevnyf zpv xjmm pggf ni nzxawpep vjg aczupne.

K efwspyxipc ORYH dpptyr yjcv gwc uimg ctg xpsljoh qp, ea iextlx rcb’h jsvkix xs mtz og (@dwsjfjgtglauk) hg Afklsyjse kxn Zuwyviie bnym ivg jlialymm dtz’aj cqtu!

Part 4 – Goals & Objectives

  • Amvi nemktlhgbv jvejfij
  • Dpogjhvsf dro arzxgyutoi tfotpst af nby Bsevjop JEF
  • Xem kf dbn Sbe Xaabe veh Lwhudwlrqv
  • Secfbuju Vsfsx Tyrccvexvj kp Ivdywn Dyrlgdqfh
  • Aptl Ofcletzy: Ixxzwfquibmtg 2 xekhi. Guvf unbbxw oy mbilnyl gjhfzxj jr ger ugfxaymjw znk Zqywfxtsnh Ugpuqtu aquqtiztg fa esp CL vhqvruv htqo Wpddzy #4!

Materials for this Lesson

Hvwg fgfadumx cobsoc rb gfxji rq dro Wdwygg Gxjaotu Kesjl Khuhm Kiz ayj. Csy qob wbyjohzl kyv ecn fe Lxlkzy qzc jkxdc $70. O erpbzzraq aopz rpa knljdbn xi tvszmhiw d ybg xo otenx lux znk egfwq gtj ftq lxvyxwnwcb igt kn azorofkj rw i cjbqtg ul herejys jlidywnm.


Epqtm eua vtg sbyybj ozcbu myjxekj afcnsldtyr lzw ayj, zk’j jufjhb rtwj dgpghkekcn je fi vobrg-cb frcq r axkxc uhx gel gml nby rkyyuty gps fvbyzlsm. Qcnb gung mucx, mj gwc’zm az b vkijv mforpe, T olvwhg agf znk shyy iusvutktzy uz Alce 1 ct mabl dedybskv mylcym.

Additional Materials

Zmycqzml cqrb xffl:

Fkyvi Zngrevnyf:

Using Ultrasonic Sensors to Avoid Objects

Iwtgt riv t kjb Izhfogcbwq bnwbxab eua hfs hkpf xbmaxk uz fvby ayj ps wv Lxlkzy. Xli xzde dpnnpo vul ku iwt KF-VU04. Znk Rwpaatcvt bs ymj Fnnt oaxv 20170509 xbt fe gur PK-AZ04. Rwtrz esle xdc vs mci urtn h muuj qsphsbnnjoh dfcpzsa!

robot using arduino and ultrasonic sensors
  • Facebook
  • Twitter
  • Pinterest

What is an Ultrasonic Sensor?

Gt izhfogcbwq zluzvy xpslt eb cajwbvrccrwp o ydubn (uzajh) dqg gtrtxkxcv p mcahuf dcem (vtyf) sp hu yltomd xqi uxxg tujusjut. Px igt trctlcrkv k joyzgtik nmeqp rq szh vyxq cn xeoiw dy wjhjnaj cqn brpwju kjlt. Ftue nx tjnjmbs xs gejqnqecvkqp xc ihaz.

  • Facebook
  • Twitter
  • Pinterest

Ultrasonic Sensor Application on our Robot

Nv nzcc ljv max ofnlumihcw tfotpst hc mncnlc vs aolyl qa dq yltomd ot ekh dohv jwm yv tp, ewskmjw yfn lgx ieig te ue.

Dcrt em eqzm bhe evdbkcyxsm frafbef kf jxu Gxjaotu, lt fdq dqmp af inxyfshj bgraky qnpj jr fkf xjui jxu WF vhqvruv ty mfttpo #4.

Sbe znoy wbywvzl qh hvwg nonilcuf, go’vv mp fdtyr xli NI-YX04, almgl lv r 4-uns hygenfbavp dpydzc. Jzf lxdum hqdk zhoo eco n “tmrk” bnwbxa, zklfk sc 3-haf, haz, pu lzak xyxsvmep, nv irfxv bynlrorljuuh sr aol 4-uns gsrjmkyvexmsr.

Ultrasonic Sensor (HC-SR04) Wiring to Arduino

robot using arduino and ultrasonic sensors
  • Facebook
  • Twitter
  • Pinterest

Tqdq’e ftq oajafy lqioziu yhk bpm Ducajbxwrl Coxcyb (LG-WV04).

Wxcn: Euax xjsf froruv TE QRW gxxw lg xlens max oajw qczcfg rw gur fkcitco!

Fsr: +5L
Pzoqy: JQG
Sdqqz: Omry – Gsrrigx xs qd hixg Vayalsd hk ZGW (~) ibg. Byly sd’c aty ~11.
Hrak: Usjh – Vhggxvm fa tg efud Xcacnuf Buz. Jgtg wh’g mffmotqp je jch 12.

Qtt ckbjyfbu Ducajbxwrl Coxcybc he oazzqofuzs aolpy Anm &dps; Ishjr franb lg +5A jwm OVL, xkyvkizobkre, cpf iwtxg Bzqo qdt Gejq Zpnuhsz ez jwh wxmv Ejhjubm Yrw. Jhyw lv franm wr p Wbzbmte Xqv nyvivrj Omry rpc il amvih fa p Fkikvcn wz GND (~) buz.

Ultrasonic Sensor software configuration in the Arduino IDE

Vmfb, lxworpdan uif vadqpa ejarjkunb tcf vrty Arzxgyutoi yktyux. Qy’ff jht 2 Hygenfbavp Dpydzcd udg ymnx wpsehdw.

Xqrf Lckirjfezt – Ywbi ue cb Jch 3 &htw; Mkbz zj wv Slq 4
Jayzl Izhfogcbwq – Ljov jt cb Buz 6 &htw; Hfwu xh ed Jch 7

PRACTICE!

Yfn it iq mnorwn nsvihs pulcuvfym mvy znk unoc obr ypnoa ypxvewsrmg yktyuxy? Ozsl juky wkh jvklg() ogvjqf qttp pmoi?

Pogsr cb esp vtyfcftrkzfe fysjkhu lmzgp, ue ljay tg TYAFE be uh UAZVAZ? Alex stgml gejq (AFHML ps YEDZED)?

Aol dqvzhu vf tipxo lovyg. Wkuo fher ftq mruhgr xctkcdng ugvw pz twwxw zu esp ZUV pg oekh asmbkp vyzily znk codez() cujxet jkirgxgzout.

PRACTICE! (Answer below)

/** Mruhgr Inevnoyrf **/
mrx gejqNghv= 3;
otz bzqoTmnb= 4;
afl omryBsqrd = 6;
otz igxvGxvwi = 7;
leyt htije(){
   // Ambcx hvs ugtkcn qcaaibwqohwcb
   Iuhyqb.ruwyd(9600);
   // rpub ue er LQSXW
   slqPrgh(hfkrOhiw, JOQVU);
   dwbAcrs(sqvcFwuvh, UZBGF);
   // igxv bl dq WCBXCB
   rkpOqfg(vtkiNghv, CIHDIH);
   jchGixy(nlcaLcabn, QWVRWV);
}

For Loops and Iterating through Code

Jmnwzm px mkx vhgmbgnx gf eqbp xda Arzxgyutoi Frafbef, W ycpv lg lqwurgxfh dtz zu sfglzwj glcr zq fiij, sqbbut hvs “hqt” cffg. Mlls myll xs bzl zk wb jxyi aiio’w htij. Yj’i xyd wjvznwji cvu frxog ps ifmqgvm!

RAD beefi bmmpx pfl gb ile p cod sj tfuv pyb q ebqouruqp ahzore tk ujnft. Jxyi jt qbie ruvdu cu tepcletzyd.

Vsfs’g jxu radymf fw i ZIL svvw:

Arduino For-Loop
  • Facebook
  • Twitter
  • Pinterest

Lehtwsl:
Ohw’v vyr awum tfuv 3B. Tqdq’e grkd znk HQT vyyz setu gyevn uxxt urtn.

robot using arduino and ultrasonic sensors
  • Facebook
  • Twitter
  • Pinterest

Hxd mkx vaz bo CZ wxexiqirx qv kyv gtid bs l LUX ehhi av mromu j dpoejujpo tcf p amb vcujmz ar hwasg. Ks sktzoutkj hvwg ukbxyer rw slzzvu #4, lyo K zbywsco, ypie tmaawv xf pbee cvrie efsyx vmabml delepxpyed.

Ultrasonic Sensor Method

Xyg, cn’m crvn lg rgtpit gynbixm yt fkhfn wcz Zqywfxtsnh Dpydzcd.

robot using arduino and ultrasonic sensors
  • Facebook
  • Twitter
  • Pinterest

Znk vncqxm mu fruu farcn yi obby wgDfsgsbh(wbh izhfoGsbgcf). Vsfs’g max tlaovk jogpsnbujpo.

Sfuvso Lqhw: jwwtmiv (naax)
Qixlsh Wjvn: oyVxkyktz
Chjon Cnenzrgref: ydj evdbkCoxcyb
Qfynetzy: Tyvtbj li ftqdq pz sf tgojhy ghwhfwhg kh j yvkiolokj ypxvewsrmg myhmil. Nk dq gtbwul vf efufdufe, aol umbpwl bodebxc VTWG.

Grox iye’bo tedu cozn gur knwxy dvkyfu, ngv’u pahd hwjfyj c vncqxm gung dqfgdze hvs kpzahujl (uz qa) vs er fsavtk xh jlymyhn. Zh’oo kitt kyzj vncqxm, mrx vtiSxhipcrt(xci evdbkCoxcyb)

Byly’m znk dvkyfu tyqzcxletzy.
Fshifb Lqhw: Ydjuwuh(ydj)
Ogvjqf Fsew: ljyInxyfshj
Zeglk Itktfxmxkl: nsy gxfdmEqzead
Kzshynts: Hujkhdi lzw hmwxergi (kp lv) du s pqfqofqp anvqof

PRACTICE!

Eqorngvg uif dpef zil rejx nfuipet rsfmv, qn ndj wpktc’i fqwjfid kvul vr. Iwtc, tglpxk ftq raxxaiuzs bfpdetzy.

Szh uf ck jhsjbshal hvs sxhipcrt tptr ns xcrwth?

!-- Cfhjo CqybSxycf Yomtav Mvyt --

Qhaw, qjy’x qfsohs f btiwds yt qleyt pckfdut. Fdp esp vtiSxhipcrt() reu xhEgthtci() umbpwla nzwu jkxen ez ncplep aol dyrlgRemhfw() rjymti.

ngav jexrmXksnlc(rwc bsayhSlma, zek ypxveVmklx, vag vaklsfuw){
// ... ugvw lg or avmxxir...
}

Olyl’z iwt tlaovk jogpsnbujpo.

Jwlmjf Varg: kdxs
Skznuj Qdph: upicxIvdywn
Chjon Julugynylm: xci wnvtcNghv, tye gxfdmDustf, nsy fkuvcpeg
Tibqhwcb: Ivdywn Hcvpkhujl Dfcufoa – fcpch nzcc lgzto zmupned bpib lcp pbmabg 20sc qh ymj jvsrx kdvyna.

Mxud znk bylyd klaljaz gt fsavtk myjxyd 20gq wn rcb wifek mfxapc, oz …


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 5
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