{"id":1469,"date":"2013-02-09T18:46:08","date_gmt":"2013-02-09T16:46:08","guid":{"rendered":"http:\/\/sickel.net\/blogg\/?p=1469"},"modified":"2013-02-09T20:55:29","modified_gmt":"2013-02-09T18:55:29","slug":"arduino-and-infrared-reflective-sensor","status":"publish","type":"post","link":"http:\/\/sickel.net\/blogg\/?p=1469","title":{"rendered":"Arduino and infrared reflective sensor"},"content":{"rendered":"<p>Testing a <a href=\"http:\/\/dx.com\/p\/k1208042-lm393-infrared-reflective-sensor-module-blue-150314\">infrared reflective sensor module<\/a>.<\/p>\n<p>I set it up with an arduino board, running the following sketch:<\/p>\n<pre>\r\nint sensorPin = 10;\r\nint value = 0;\r\nint prevval =0;\r\nint count=0;\r\nvoid setup() {\r\n  pinMode(sensorPin,INPUT);\r\n  Serial.begin(9600);\r\n}\r\nvoid loop() {\r\n value = digitalRead(sensorPin);\r\n if(value==0 && prevval==1){ \/\/ something is dected\r\n   count++;\r\n }\r\n prevval=value;\r\n Serial.print(count);\r\n Serial.print(\"   \");\r\n Serial.println(value, DEC);\r\n delay(50);\r\n}\r\n<\/pre>\n<p>To run this, connect dout on the sensor to digital pin 10 on the arduino, connect + on the sensor to 5V and &#8211; to ground.<br \/>\nWhen the infrared light is reflected back to the detector, the output goes low. The sensitivity can be adjusted using the trim pot, turning it counter-clockwise lowers the sensitivity, i.e. what passes in front must come closer or be more reflective. In addition to watching the serial monitor for changes, there is a led that lights up when something is detected.<\/p>\n<div id=\"attachment_1472\" style=\"width: 777px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/sickel.net\/blogg\/wp-content\/2013\/02\/irreflector.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1472\" data-attachment-id=\"1472\" data-permalink=\"http:\/\/sickel.net\/blogg\/?attachment_id=1472\" data-orig-file=\"http:\/\/sickel.net\/blogg\/wp-content\/2013\/02\/irreflector.png\" data-orig-size=\"767,412\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"Adjustments of the sensor\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Adjustments of the sensor&lt;\/p&gt;\n\" data-large-file=\"http:\/\/sickel.net\/blogg\/wp-content\/2013\/02\/irreflector.png\" src=\"http:\/\/sickel.net\/blogg\/wp-content\/2013\/02\/irreflector.png\" alt=\"To lower the sensitivity, turn ccw, turn cw to increase the sensitivity\" width=\"767\" height=\"412\" class=\"size-full wp-image-1472\" srcset=\"http:\/\/sickel.net\/blogg\/wp-content\/2013\/02\/irreflector.png 767w, http:\/\/sickel.net\/blogg\/wp-content\/2013\/02\/irreflector-300x161.png 300w\" sizes=\"auto, (max-width: 767px) 100vw, 767px\" \/><\/a><p id=\"caption-attachment-1472\" class=\"wp-caption-text\">Adjustments of the sensor<\/p><\/div>\n<p>The sensor module is marked &#8220;auto-ctrl.com&#8221; and &#8220;LOGO-sensor Var1.5&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Testing a infrared reflective sensor module. I set it up with an arduino board, running the following sketch: int sensorPin = 10; int value = 0; int prevval =0; int count=0; void setup() { pinMode(sensorPin,INPUT); Serial.begin(9600); } void loop() { &hellip; <a href=\"http:\/\/sickel.net\/blogg\/?p=1469\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[33],"tags":[],"class_list":["post-1469","post","type-post","status-publish","format-standard","hentry","category-arduino"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pnVtD-nH","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/1469","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1469"}],"version-history":[{"count":4,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/1469\/revisions"}],"predecessor-version":[{"id":1474,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=\/wp\/v2\/posts\/1469\/revisions\/1474"}],"wp:attachment":[{"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1469"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1469"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sickel.net\/blogg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1469"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}