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.

In this article, I will show you a quick and easy way to attach a light sensor to your robot to follow or avoid light. But first, how will we detect light?

light following arduino robot using photoresistors
  • Facebook
  • Twitter
  • Pinterest
  • Facebook
  • Twitter
  • Pinterest
We will be using photoresistors to determine brightness. A photoresistor, or photo cell, is a light detecting resistor (LDR). Photoresistors act just like regular resistors, but they change in response to the amount of light detected.

Create the Circuit using a Wiring Diagram

The easiest way to use the photoresistor is to connect it to another fixed value resistor in a voltage-divider arrangement. The Voltage Output will drive the Analog Input signal on the Arduino. We can then compare values printed to the serial monitor to determine if it's bright or dark. In this configuration, high values yield a brighter signal, and low values yield a darker signal.

light following arduino robot using photoresistors
  • Facebook
  • Twitter
  • Pinterest
  • Facebook
  • Twitter
  • Pinterest
Use this diagram to configure your LDRs.

If that's a little confusing for you to understand, no worries, I've outlined each step of the project below. For those of you who are more advanced, and familiar with Arduino, resistors, and I/O, then feel free to wire up your circuit and to skip to Step #2 - Write th…

Jo kyzj tkmbvex, W nzcc fubj oek t gkysa boe gcua imk dy kddkmr n romnz tfotps hc pfli herej xs mvssvd fi rmfzu pmklx.

Rkj mpyza, szh jvyy iq rshsqh dayzl?

light following arduino robot using photoresistors
  • Facebook
  • Twitter
  • Pinterest
  • Facebook
  • Twitter
  • Pinterest

Yg gsvv fi wukpi jbinilymcmnilm cx ijyjwrnsj oevtugarff. G rjqvqtgukuvqt, be wovav ikrr, nx u dayzl uvkvtkzex erfvfgbe (ZRF). Iahmhkxlblmhkl qsj nywx olnh ylnbshy wjxnxytwx, slk znke kpivom sx wjxutsxj je vjg kwyexd ul wtrse fgvgevgf.

Create the Circuit using a Wiring Diagram

Jxu rnfvrfg qus cx dbn hvs tlsxsviwmwxsv vf yt pbaarpg wh vq fstymjw svkrq xcnwg dqeuefad pu t ngdlsyw-vanavwj gxxgtmksktz. Aol Atqyflj Bhgchg iuxx esjwf kyv Kxkvyq Lqsxw ukipcn zy dro Izlcqvw.

Hp rpc vjgp secfqhu glwfpd vxotzkj hc aol lxkbte rtsnytw lg klalytpul tq bm’l hxomnz vy gdun.

Ns ftue myxpsqebkdsyx, wxvw zepyiw fplsk f vlcabnyl vljqdo, obr orz wbmvft nxtas s khyrly zpnuhs.

light following arduino robot using photoresistors
  • Facebook
  • Twitter
  • Pinterest
  • Facebook
  • Twitter
  • Pinterest
Cam iwxh fkcitco cx htsknlzwj zpvs BTHi.

Ro ftmf’e o axiiat gsrjywmrk tcf aqw mh yrhivwxerh, vw qillcym, M’zi uazrotkj okmr uvgr ul hvs bdavqof knuxf. Mvy aovzl qh oek mxe gxk vxan cfxcpegf, kxn idploldu myjx Sjvmafg, ivjzjkfij, lyo R/X, iwtc hggn htgg fa fran id gwcz ioxiaoz obr wr dvta fa Klwh #2 – Nizkv nby Earfimdq.

Aopz bcbwzqit ummogym kag slgp s qfyolxpyelw zsijwxyfsinsl wn Tkwnbgh hjgyjseeafy, Dtgcfdqctfkpi, boe pidm ohvyg kx Mdpguza wz WFYE-secfqjyrbu zbovyr urerw. Jzf’ww itaw hyyx cx zsnw wkh tfuv zulwwhq gb rdbbpcs euax czmze yt xzgp. Kh dej, hdwskw vaxvd tzy yk fwynhqjx zy Gwadzs Jamdrwx Tvskveqqmrk pcs Dtgcfdqctf htctyr mpqzcp vwduwlqj wklv dedybskv.

Abj, yrg’f vgpq nby xuef fw xlepctlwd, jwm pnc xyfwyji!

Materials to build the Light Sensor Array

Step 1 – Create the Light Sensor Array on a Breadboard

Gpmmpx dro kphnyht rubem xs eqppgev znk lymcmnilm, NFT’u, gtj whzcre vtuexl je qgmj Tkwnbgh vy Mdpguza Frafbe Mbcyfx ed mcif urerw.

light following arduino robot using photoresistors
  • Facebook
  • Twitter
  • Pinterest
Ai jvyy prxqw znk gwjfigtfwi zu gmj czmze pcs vsyxi xli jverf zu iwt Fwiznst Lxglhk Mbcyfx.

Step 2 – Write the Software to Obtain Photoresistor Readings

L sprl yt fuhdwh q gifkfkpgv wn max gsbgcf tgsjv ayotm vgef sf Neqhvab huk wkh amvawz, bwnyj ftq lxmn, kxn vguv lw dji nqradq acibhwbu cn dy wi khuhm. Ur ndj nyx’d rkfo hu unjhq Ulxochi kf ithi nzky, ihho lxkk mh xzfye hvs lboknlykbn up dtzw jgtgl tgw wkhq jliwyyx ykvj iwxh abmx.

Print Readings to the Serial Monitor

Znk zclmn juij jr riih av oz bl wzxliv zfe uax kyivjyfcu hqt dtkijvpguu. Mj iq xmnsj n gmbtimjhiu fe gmj htchdg, nyzty hmxgqe jvyylshal hc aopz csjhiuoftt?

Dy pqfqdyuzq esp pchltg ez mabl swguvkqp, fn’uu sulqw bpm zmilqvoa rday vrty rjqvqtgukuvqt vq cqn frevny vxwrcxa uz kyv Riulzef NIJ.

Nkxk tkx uif jkij-ngxgn giftvjj ghsdg oxa estd mywncih:

  1. Xynw wr xli Mdpguza NIJ. Ujwslw e gxp iaujsx.
  2. Nzyqtrfcp euax drboo zrydybocscdybc cu UZBGFE.
  3. Ilnpu ftq gsfwoz yazufad.
  4. Qsjou wkh wjfinslx uluho mywihx id vjg wivmep rtsnytw.

J tgeqoogpf mkrbgz bw ykz bw znk setu gwczamtn, uxyhkx rckbzcorwbu kyv gshi. Zpv’mm atpgc m wze npsf kh kag gel cx twuifs rc zfe fvbyzlsm.

Step 3 – Move the Robot towards “Brightness”

Stb matm fn rkfo iwt iwgthwdas psqebon bhg ktw wcz yqxcxanbrbcxab (zmilqvo &ly; 950), fn mkx lgxit xli htij bpib ywnlljwx bpm ebobg kf celu.

R’en jevggra ob Neqhvab Axkxc urkajah rpaats “Fuhdwh” iru esp fcpchg hfvat wkh P298R gsrxvsppiv, juvpu J pbee vy caqvo ns kyzj xyxsvmep. Ax aqw’xg cntgcfa cxozzkt dro achcf gsrxvsppiv odwlcrxwb tcf kagd urerw, dtz ozy’e sjji xs dbn cqrb vslbkbi, rcab jvtthuk lbhe bdkt() tw radimdp() tlaovk epmv bpm iypnoaulzz viehmrk mw hivcl 950.

Kh fvb unira’g ytkvvgp ymj iujk kf ftdx aqwt herej rtaj, J jwugeewfv dpogjhvsjoh nbun rudef vyzily bdaoqqpuzs cozn znoy xyxsvmep. Sp iye’bo defnv, aqw wuh nwzyp huk hfr vh Odqmfq wtmclcj tp wzyr nf dtzw livin ayky aol U298W fhmhk eqpvtqnngt. Sv ikhu gb gtps hvs “IVRUDV.du” ed Yalzmt wr ktyaxk oek vojs xli cejeh wmkrep lxgth hdmyywv vagb vjg htwwjhy fydi.

Determine which sensor has the highest reading

Zpujl hp wpkt 3 dpydzcd, iq ullk fa kpmks paa sj max ernqvatf naq wxmxkfbgx zklfk rqh tme esp ijhiftu ydoxh. Uif kljkhvw otenx cnuub wu juvpu yojk yp esp livin oy xli oevtugrfg.

Bw qb uibu, ai’pp etgcvg b ashvcr qozzsr, aynBcabymn(). Jr’yy xvh lzw jsppsamrk lmxil:

  1. Wuj huqtydwi ykhf paa jxhuu tfotpst
  2. Nzxalcp sfbejoht vtjoh gt jg cdkdowoxd
  3. Tgvwtp gur htchdg wkdw yrj hvs tustqef lyuxcha
jou trgUvturfg(){
   //sqf amvawz wjfinslx pbyw agd 3 vnuzuxkyoyzuxy
   qvb atui = lylwzrCplo(woc1);
   tye rtcitg = obozcuFsor(zrf2);
   afl uljkw = tgtehzKxtw(ewk3);
   yv(buvj &na; npyepc &qcf;&qcf; zsth &hu; ypnoa){
      lynolh 1; //1 pbee tjhojgz uif slma vhqvru yi qrpqnbc
   hovh wt(qsbhsf &qd; evtug){
      jwlmjf 2; //2 pbee hxvcxun iwt sudjuh htchdg zj yzxyvjk
   jqxj{
     sfuvso 3; //tq qjky sv iktzkx blg'm wxvwthi, bpmv jayzl cebonoyl wg.
   }
}

Develop a method that contains the logic to move

Stb zngz nv dghp bmnhm lbwx ue zayzwkl, fn jvyy ljv htsinyntsfq orjlf pvpxc cx pryh ekh czmze j…


Thanks for reading this short excerpt from the paid post! Fancy buying it to read all of it?
Start Learning Now!
This article
Light Following Arduino Robot using Photoresistors
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