{"id":137,"date":"2015-09-20T13:17:08","date_gmt":"2015-09-20T13:17:08","guid":{"rendered":"https:\/\/einhugur.com\/blog\/?page_id=137"},"modified":"2016-05-01T19:31:54","modified_gmt":"2016-05-01T19:31:54","slug":"ir-infrared-obstacle-reflection-photoelectric-sensor","status":"publish","type":"page","link":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/ir-infrared-obstacle-reflection-photoelectric-sensor\/","title":{"rendered":"IR Infrared Obstacle Reflection Photoelectric Sensor"},"content":{"rendered":"<p>In this example we are going to connect to infrared obstacle reflection photoelectric sensor motion detection sensor.<\/p>\n<p><span style=\"color: #808080;\">I am not going to deny it, I find this sensor to be awful rubbish. Without reading the data you can hook it up and see it when the 2nd green lights goes off then its sensing something. Problem is that it usually does not sense something when you expect it to, and if you look on the net then you will see others have same stories, and that it gets even worse in sunlight.<\/span><\/p>\n<p><span style=\"color: #808080;\">Even fiddling with the sensitivity screw on it did not make it give detections at times when I actually wanted them.<\/span><\/p>\n<p><span style=\"color: #808080;\">Good thing is since this sensor can be tested without reading its data then we know this is just not a good sensor and that our reading from it is not to blame.<\/span><\/p>\n<p><span style=\"color: #808080;\">But we will still cover the wiring since its simple. This one has straight forwards markings and just simple 0 or 1 to poll.<\/span><\/p>\n<p><strong>Disclaimer:<\/strong><\/p>\n<p>We do not take any responsibility for possible errors in the guide or errors that you might do wiring it up. Incorrect wiring can result in damaged sensor or damaged Raspberry PI.<\/p>\n<p><strong>Pieces we use are:<\/strong><\/p>\n<ul>\n<li>Raspberry PI 2<\/li>\n<li>Cobbler and Cobbler cable<\/li>\n<li>IR Infrared Obstacle Reflection Photoelectric Sensor sensor\u00a0(They go as low as $0.90 on Aliexpress where I got this one from probably even lower if you buy more than one unit &#8211; though I am not sure anyone would want many pieces of this one).<\/li>\n<li><a href=\"https:\/\/github.com\/xojo\/GPIO\">Wiring PI Xojo module from\u00a0Paul Lefebvre<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>First thing is connecting the sensor:<\/strong><a href=\"https:\/\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/HC-SR501-connection.jpg\"><br \/>\n<\/a><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/IRSensor-e1442754741492.jpg?ssl=1\"><img data-attachment-id=\"139\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/ir-infrared-obstacle-reflection-photoelectric-sensor\/irsensor\/\" data-orig-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/IRSensor-e1442754741492.jpg?fit=480%2C640&amp;ssl=1\" data-orig-size=\"480,640\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;2.2&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone 6&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1442753957&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.15&quot;,&quot;iso&quot;:&quot;64&quot;,&quot;shutter_speed&quot;:&quot;0.033333333333333&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;6&quot;}\" data-image-title=\"IRSensor\" data-image-description=\"\" data-medium-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/IRSensor-e1442754741492.jpg?fit=225%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/IRSensor-e1442754741492.jpg?fit=474%2C632&amp;ssl=1\" loading=\"lazy\" class=\"alignnone size-medium wp-image-139\" src=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/IRSensor-e1442754741492-225x300.jpg?resize=225%2C300&#038;ssl=1\" alt=\"IRSensor\" width=\"225\" height=\"300\" srcset=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/IRSensor-e1442754741492.jpg?resize=225%2C300&amp;ssl=1 225w, https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/IRSensor-e1442754741492.jpg?w=480&amp;ssl=1 480w\" sizes=\"(max-width: 225px) 100vw, 225px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<ul>\n<li>(5V)\u00a0Red is the 5V input \u00a0(was marked as VCC on the sensor)\u2013 I always use red for the power input.<\/li>\n<li>(GPIOX)\u00a0Yellow is the Data pin (was marked as OUT on the sensor)<\/li>\n<li>(GND)\u00a0Blue is the ground (was marked as GND on the sensor) &#8211; I always use blue for the ground.<\/li>\n<\/ul>\n<p><strong>Connecting to the Cobbler:<\/strong><\/p>\n<p>Make sure your Raspberry PI is not powered on when you do the connections.<\/p>\n<figure id=\"attachment_80\" class=\"wp-caption alignnone\"><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628.jpg?ssl=1\"><img data-attachment-id=\"80\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/hc-sr501-sensor\/sensor-connection\/\" data-orig-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628.jpg?fit=480%2C640&amp;ssl=1\" data-orig-size=\"480,640\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;2.2&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;iPhone 6&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;1442662628&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;4.15&quot;,&quot;iso&quot;:&quot;64&quot;,&quot;shutter_speed&quot;:&quot;0.033333333333333&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;6&quot;}\" data-image-title=\"Cobbler\" data-image-description=\"\" data-medium-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628.jpg?fit=225%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628.jpg?fit=474%2C632&amp;ssl=1\" loading=\"lazy\" class=\"size-medium wp-image-80\" src=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628-225x300.jpg?resize=225%2C300&#038;ssl=1\" alt=\"Cobbler for Raspberry PI\" width=\"225\" height=\"300\" srcset=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628.jpg?resize=225%2C300&amp;ssl=1 225w, https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628.jpg?w=480&amp;ssl=1 480w\" sizes=\"(max-width: 225px) 100vw, 225px\" data-recalc-dims=\"1\" \/><\/a><figcaption class=\"wp-caption-text\">Cobbler for Raspberry PI<\/figcaption><\/figure>\n<p><a href=\"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/GPIO-Header.png?ssl=1\"><img data-attachment-id=\"82\" data-permalink=\"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/hc-sr501-sensor\/gpio-header\/\" data-orig-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/GPIO-Header.png?fit=440%2C870&amp;ssl=1\" data-orig-size=\"440,870\" 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;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"GPIO Header\" data-image-description=\"\" data-medium-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/GPIO-Header.png?fit=152%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/GPIO-Header.png?fit=440%2C870&amp;ssl=1\" loading=\"lazy\" class=\"size-medium wp-image-82 alignnone\" src=\"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/GPIO-Header-152x300.png?resize=152%2C300&#038;ssl=1\" alt=\"GPIO Header\" width=\"152\" height=\"300\" srcset=\"https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/GPIO-Header.png?resize=152%2C300&amp;ssl=1 152w, https:\/\/i2.wp.com\/einhugur.net\/blog\/wp-content\/uploads\/2015\/09\/GPIO-Header.png?w=440&amp;ssl=1 440w\" sizes=\"(max-width: 152px) 100vw, 152px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<p>In my example then I have it connected as follows:<\/p>\n<ul>\n<li>Red to pin 2 (5V)<\/li>\n<li>Blue to pin 25 (GND)<\/li>\n<li>Yellow to GPIO 5 which is pin 29.<\/li>\n<\/ul>\n<p><strong>The Xojo code:<\/strong><\/p>\n<p>I have a timer to poll the sensor. we set the timer up and the pin mode in the Window Open event.<\/p>\n<pre lang=\"xojo\">Sub Open()\r\nConst kInfraRedSensorPin = 5\r\n\r\nGPIO.SetupGPIO\r\n\r\nGPIO.PinMode(kInfraRedSensorPin, GPIO.INPUT)\r\n\r\nTimer1.Mode = Timer.ModeMultiple\r\nTimer1.Enabled = true\r\n\r\nEnd Sub\r\n<\/pre>\n<p>In the Timer.Action event I got the following code:<\/p>\n<p>(If you want it more responsive then you can increase the cycles of the for loop)<\/p>\n<pre lang=\"xojo\">Sub Action()\r\n\r\nDim i as Integer\r\nConst kInfraRedSensorPin = 5\r\n\r\nfor n as Integer = 1 to 10\r\ni = GPIO.DigitalRead(kInfraRedSensorPin)\r\n\r\nif i &lt;&gt; 0 then\r\nListbox1.AddRow \u201cMotion detected\u201d\r\nreturn\r\nend if\r\nApp.DoEvents(1)\r\nnext\r\n\r\nEnd Sub<\/pre>\n<p>Thats all there\u00a0is to it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this example we are going to connect to infrared obstacle reflection photoelectric sensor motion detection sensor. I am not going to deny it, I find this sensor to be awful rubbish. Without reading the data you can hook it up and see it when the 2nd green lights goes off then its sensing something. &hellip; <a href=\"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/ir-infrared-obstacle-reflection-photoelectric-sensor\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">IR Infrared Obstacle Reflection Photoelectric Sensor<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":94,"menu_order":60,"comment_status":"closed","ping_status":"closed","template":"","meta":{"spay_email":""},"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/Pd75nk-2d","jetpack-related-posts":[{"id":507,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/mini-ir-pyroelectric-infrared-pir-motion-human-sensor-detector-module\/","url_meta":{"origin":137,"position":0},"title":"Mini IR Pyroelectric Infrared PIR Motion Human Sensor Detector Module","date":"May 1, 2016","format":false,"excerpt":"Connecting the\u00a0Mini IR Pyroelectric Infrared PIR Motion Human Sensor Detector Module. This guide is detail guide for one of the sensor types on this guide here:\u00a0Infrared motion detection We\u00a0found no official name for this sensor\u00a0but its sold as \"Mini IR Pyroelectric Infrared PIR Motion Human Sensor Detector Module\". WARNING do\u2026","rel":"","context":"Similar post","img":{"alt_text":"MiniMotionSensor","src":"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2016\/05\/MiniMotionSensor.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":94,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/","url_meta":{"origin":137,"position":1},"title":"Xojo GPIO","date":"September 19, 2015","format":false,"excerpt":"Guides for GPIO in Xojo \u00a0Infrared motion detection (Updated 1. May 2016) Shows\u00a02 ways of coding: Using Interrupts or simple polling. Sensors: \u00a0HC-SR501,\u00a0ST-00082 Mini,\u00a0Mini IR Pyroelectric Infrared PIR Motion Human Sensor Detector Module Uses:\u00a0Basic GPIO Relay board In this example we \u00a0wire up a relay board and let your Xojo\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":113,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/flame-sensor\/","url_meta":{"origin":137,"position":2},"title":"Flame sensor","date":"September 19, 2015","format":false,"excerpt":"In this example we are going to connect to flame\u00a0sensor. Programming for this sensor works on exactly the same principle as the\u00a0HC-SR501 infrared sensor and the F85 vibration sensor except the signal from this sensor comes inverted. As in it will send 1 when everything is all right and zero\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/FlameSensor-e1442681877884-225x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":108,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/f85-vibration-sensor\/","url_meta":{"origin":137,"position":3},"title":"F85 Vibration sensor","date":"September 19, 2015","format":false,"excerpt":"In this example we are going to connect to\u00a0vibration sensor. This example is super easy after doing the infrared motion detection with the HC-SR501 in a previous example, since basically same code will work. I found this sensor to be excellent, it gives readings when I expect it to and\u2026","rel":"","context":"Similar post","img":{"alt_text":"","src":"https:\/\/i1.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/Sensor-connection-e1442664059628-225x300.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":79,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/hc-sr501-sensor\/","url_meta":{"origin":137,"position":4},"title":"Infrared motion detection","date":"September 19, 2015","format":false,"excerpt":"In this example we are going to connect to infrared motion detection sensor (various of sensors work, see bellow the ones we have tested). (Updated 24. Oct 2015, adding code with interrupts and changed setup to use a breadboard) (Updated 8. Nov\u00a02015, adding ST-00082 Mini sensor) (Updated 1. May 2016,\u2026","rel":"","context":"Similar post","img":{"alt_text":"HC-SR501 Sensor_bb","src":"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/HC-SR501-Sensor_bb.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":128,"url":"https:\/\/einhugur.net\/blog\/index.php\/xojo-gpio\/dht11-and-dht22-humidity-temperature-sensors-3-pin-version\/","url_meta":{"origin":137,"position":5},"title":"DHT11 and DHT22 humidity & temperature sensors (3 pin version)","date":"September 20, 2015","format":false,"excerpt":"In this example we are going to connect\u00a0to DHT11 and or DHT22 humidity & temperature sensor. This sensor reads both the humidity and temperature. (This guide was updated on 24. Oct 2015, greatly improving the DHT11 device driver code and added DHT22 device driver code and wiring pictures for the\u2026","rel":"","context":"Similar post","img":{"alt_text":"DHT22 sensor","src":"https:\/\/i0.wp.com\/einhugur.com\/blog\/wp-content\/uploads\/2015\/09\/DHT22.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages\/137"}],"collection":[{"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=137"}],"version-history":[{"count":10,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages\/137\/revisions"}],"predecessor-version":[{"id":514,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages\/137\/revisions\/514"}],"up":[{"embeddable":true,"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/pages\/94"}],"wp:attachment":[{"href":"https:\/\/einhugur.net\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}