{"id":103,"date":"2009-05-06T23:26:01","date_gmt":"2009-05-06T22:26:01","guid":{"rendered":"http:\/\/stigern.net\/blog\/?p=103"},"modified":"2011-12-16T06:16:22","modified_gmt":"2011-12-16T05:16:22","slug":"how-to-make-a-light-tracker-using-photoresistors","status":"publish","type":"post","link":"https:\/\/stigern.net\/blog\/how-to-make-a-light-tracker-using-photoresistors\/","title":{"rendered":"How to make a light tracker using arduino &#038; photoresistors!"},"content":{"rendered":"<p>[youtube=http:\/\/www.youtube.com\/watch?v=iEhX27ahreI&#038;w=480&#038;h=385]<\/p>\n<p>This is how to make a simple light tracker\/follower with the Arduino. The components you need apart from the Arduino is:<\/p>\n<p><a href=\"http:\/\/www.futurlec.com\/Photocells.shtml\" target=\"_blank\">2x Photoresistors<\/a>: &#8220;PHOTOCELL2 Miniature Photocell&#8221;.<br \/>\n<a href=\"http:\/\/www.futurlec.com\/Res14W.shtml\" target=\"_blank\">2x 470 Ohms resistors<\/a>.<br \/>\n<a href=\"http:\/\/www.dealextreme.com\/details.dx\/sku.20023\" target=\"_blank\">1x Servo.<\/a><\/p>\n<p>And of course some <a href=\"http:\/\/www.seeedstudio.com\/depot\/breadborad-jumper-wire-75pcs-pack-p-234.html\" target=\"_blank\">wires<\/a>, and a <a href=\"http:\/\/www.seeedstudio.com\/depot\/mini-bread-board-45x35cmwhite-p-309.html\" target=\"_blank\">breadboard <\/a>or two :). Next step is to wire it all up, I&#8217;ve made a drawing in Fritzing that you can follow. Basically each photoresistor is wired likes this:<\/p>\n<p>PhotoR\u00a0\u00a0\u00a0 \u00a0\u00a0 470Ohms<br \/>\n+5\u00a0\u00a0\u00a0 o&#8212;\/\/\/&#8211;.&#8211;\/\/\/&#8212;o GND<br \/>\n|<br \/>\nPin 0 &amp; 1 o&#8212;&#8212;-<\/p>\n<p><a href=\"http:\/\/stigern.net\/arduino\/LightTracker.jpg\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/stigern.net\/arduino\/lighttracker.th.jpg\" alt=\"\" width=\"150\" height=\"118\" \/><\/a><\/p>\n<p><a href=\"http:\/\/pastebin.com\/f238c7f29\" target=\"_blank\"><\/a><\/p>\n<p>Program Code:<\/p>\n<blockquote><p>#include &lt;Servo.h&gt;<\/p>\n<p>Servo myservo;<\/p>\n<p>int pos = 0;\u00a0 \/\/ Variable to store the servo position.<br \/>\nint inputPhotoLeft = 1; \/\/ Easier to read, instead of just 1 or 0.<br \/>\nint inputPhotoRight = 0;<\/p>\n<p>int Left = 0; \/\/ Store readings from the photoresistors.<br \/>\nint Right = 0; \/\/ Store readings from the photoresistors.<\/p>\n<p>void setup()<br \/>\n{<br \/>\nmyservo.attach(9); \/\/ Attach servo to pin 9.<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{<br \/>\n\/\/ Reads the values from the photoresistors to the Left and Right variables.<br \/>\nLeft = analogRead(inputPhotoLeft);<br \/>\nRight = analogRead(inputPhotoRight);<\/p>\n<p>\/\/ Checks if right is greater than left, if so move to right.<br \/>\nif (Left &gt; (Right +20))<br \/>\n\/\/ +20 is the deadzone, so it wont jiggle back and forth.<br \/>\n{<br \/>\nif (pos &lt; 179)<br \/>\npos++;<br \/>\nmyservo.write(pos);<br \/>\n}<\/p>\n<p>\/\/ Checks if left is greater than right, if so move to left.<br \/>\nif (Right &gt; (Left +20))<br \/>\n\/\/ +20 is the deadzone, so it wont jiggle back and forth.<br \/>\n{<br \/>\nif (pos &gt; 1)<br \/>\npos -= 1;<br \/>\nmyservo.write(pos);<br \/>\n}<\/p>\n<p>\/\/ Added some delay, increase or decrease if you want less or more speed.<br \/>\ndelay(10);<br \/>\n}<\/p><\/blockquote>\n<p><strong>PS. If you got any questions etc, please take it in my <a href=\"..\/..\/forum\/viewtopic.php?f=24&amp;t=458\" target=\"_blank\">forums post here.<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[youtube=http:\/\/www.youtube.com\/watch?v=iEhX27ahreI&#038;w=480&#038;h=385] This is how to make a simple light tracker\/follower with the Arduino. The components you need apart from the Arduino is: 2x Photoresistors: &#8220;PHOTOCELL2 Miniature Photocell&#8221;. 2x 470 Ohms resistors. 1x Servo. And of course some wires, and a breadboard or two :). Next step is to wire it all up, I&#8217;ve made a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,4],"tags":[16,178,172,176,26,95,111,174,179,177,175,61],"class_list":["post-103","post","type-post","status-publish","format-standard","hentry","category-arduino-electronics","category-electronics","tag-arduino","tag-avdvanced","tag-boarduino","tag-follower","tag-guide","tag-how","tag-ldr","tag-light","tag-make","tag-resistor","tag-tracker","tag-tutorial"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/posts\/103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/comments?post=103"}],"version-history":[{"count":1,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/posts\/103\/revisions"}],"predecessor-version":[{"id":306,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/posts\/103\/revisions\/306"}],"wp:attachment":[{"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/media?parent=103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/categories?post=103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stigern.net\/blog\/wp-json\/wp\/v2\/tags?post=103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}