{"id":1833,"date":"2014-06-20T10:13:57","date_gmt":"2014-06-20T08:13:57","guid":{"rendered":"http:\/\/www.dotmana.com\/weblog\/?p=1833"},"modified":"2017-11-16T15:01:23","modified_gmt":"2017-11-16T14:01:23","slug":"usb-motion-sensor-pir-to-wake-up-screen","status":"publish","type":"post","link":"http:\/\/www.dotmana.com\/weblog\/2014\/06\/usb-motion-sensor-pir-to-wake-up-screen\/","title":{"rendered":"USB motion sensor (PIR) to activate monitor"},"content":{"rendered":"<p>I have an always on net-book for weather forecast (yeah, when paragliding, you need the most up to date forecast)<br \/>\nIt basically displays a full screen custom web-page with time and date and weather.<\/p>\n<p><a href=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084936-resized.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1840\" title=\"IMG_20140620_084936-resized\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084936-resized-300x168.jpg\" alt=\"\" width=\"300\" height=\"168\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084936-resized-300x168.jpg 300w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084936-resized-500x281.jpg 500w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084936-resized.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Its always on, not really good for the back-light and energy consumption.<\/p>\n<p>So I got the idea of plugging a PIR sensor to wake up the screen when someone approach it.<\/p>\n<p><a href=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_075440-resized.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1834\" title=\"IMG_20140620_075440-resized\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_075440-resized-168x300.jpg\" alt=\"\" width=\"168\" height=\"300\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_075440-resized-168x300.jpg 168w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_075440-resized.jpg 432w\" sizes=\"auto, (max-width: 168px) 100vw, 168px\" \/><\/a>Take an<a href=\"https:\/\/www.aliexpress.com\/item\/Pro-Micro-ATmega32U4-5V-16MHz-Replace-ATmega328-For-Arduino-Pro-Mini-With-2-Row-Pin-Header\/32808519179.html\" target=\"_blank\" rel=\"noopener\"> Arduino Micro Pro<\/a> (4\u20ac for the Chinese version), a <a href=\"https:\/\/www.aliexpress.com\/item\/2PCS-HC-SR505-HCSR505-Sensor-PIR-Motion-IR-Infrared-Switch-Detector-Sensore-Sensors-Corrente-IR-Vibration\/32826104810.html\" target=\"_blank\" rel=\"noopener\">PIR sensor<\/a>\u00a0(2\u20ac), a <a href=\"http:\/\/uk.farnell.com\/jsp\/search\/browse.jsp;jsessionid=PNDTD2PHF5TTSCQLCIPJNFQ?N=0&amp;Ntk=gensearch&amp;Ntt=1551FBK&amp;Ntx=mode+matchallpartial&amp;exposeLevel2Refinement=true&amp;suggestions=false&amp;ref=globalsearch&amp;_requestid=455744\" target=\"_blank\" rel=\"noopener\">Hammond case <\/a>(1\u20ac) and an USB A male from scrap (0\u20ac).<\/p>\n<p><a href=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_075512-resized.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1836\" title=\"IMG_20140620_075512-resized\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_075512-resized-168x300.jpg\" alt=\"\" width=\"168\" height=\"300\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_075512-resized-168x300.jpg 168w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_075512-resized.jpg 432w\" sizes=\"auto, (max-width: 168px) 100vw, 168px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/motion-sensor-arduino-wiring.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-2043\" title=\"motion sensor arduino wiring\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/motion-sensor-arduino-wiring-300x175.png\" alt=\"\" width=\"300\" height=\"175\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/motion-sensor-arduino-wiring-300x175.png 300w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/motion-sensor-arduino-wiring-500x292.png 500w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/motion-sensor-arduino-wiring.png 847w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Let&#8217;s give a try, with a basic wiring, and this sketch to emulate keyboard thanks to it&#8217;s USB HID, the Arduino Micro Pro is a must.<\/p>\n<p>Updated 05-01-2017:<\/p>\n<ul>\n<li>code with USB wakeuphost and capslock instead of ctrl<\/li>\n<li>green TX led always on<\/li>\n<li>orange RX led only on motion<\/li>\n<\/ul>\n<pre class=\"KEY\">#include &lt;Keyboard.h&gt;\r\n\r\n#define SENSOR_PIN 10   \/\/ Senor state input pin\r\n#define RX_LED_PIN  17\u00a0 \/\/ The RX LED has a defined Arduino pin\r\nstatic bool sensor_previous_state = false;\r\n\r\nvoid setup()\r\n{\r\n\u00a0 pinMode(SENSOR_PIN, INPUT);\u00a0 \/\/ PIR sensor pin as input\r\n\u00a0 pinMode(RX_LED_PIN, OUTPUT);\u00a0\u00a0\u00a0\u00a0 \/\/\u00a0 RX LED as an output\r\n\u00a0 digitalWrite(RX_LED_PIN, HIGH);\u00a0 \/\/\u00a0 RX LED off\r\n\u00a0 TXLED0;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ switch on TX green to show init\/powered up (only available by macro)\r\n\u00a0 sensor_previous_state = digitalRead(SENSOR_PIN); \/\/ get sensor initial state (can be already true)\r\n}\r\n\r\nvoid loop()\r\n{\r\n\u00a0 bool sensor_current_state = digitalRead(SENSOR_PIN);\r\n\u00a0 if ( sensor_previous_state == false\u00a0\u00a0 \/\/ looping until we detect a rising edge\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &amp;&amp; sensor_current_state == true) {\/\/ when sensor state is trigged, it takes about 20 sec to recover\r\n\u00a0\u00a0\u00a0 digitalWrite(RX_LED_PIN, LOW);\u00a0\u00a0 \/\/ set the LED on\r\n\u00a0\u00a0\u00a0 USBDevice.wakeupHost();\r\n\u00a0\u00a0\u00a0 Keyboard.press( KEY_CAPS_LOCK );\r\n\u00a0\u00a0\u00a0 Keyboard.release( KEY_CAPS_LOCK );\r\n\u00a0\u00a0\u00a0 TXLED0;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ great hackery in this: we have to force down the TXLED\r\n\u00a0\u00a0\u00a0 delay(1000);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ wait a bit for the led\r\n\u00a0 } else {\r\n\u00a0\u00a0\u00a0 digitalWrite(RX_LED_PIN, HIGH);\u00a0\u00a0\u00a0 \/\/ set the LED off\r\n\u00a0\u00a0\u00a0 TXLED0;\r\n\u00a0 }\r\n\u00a0 sensor_previous_state = sensor_current_state;\r\n}<\/pre>\n<div class=\"cFoot\"><a href=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_083011-resized.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1835\" title=\"IMG_20140620_083011-resized\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_083011-resized-300x168.jpg\" alt=\"\" width=\"300\" height=\"168\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_083011-resized-300x168.jpg 300w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_083011-resized-500x281.jpg 500w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_083011-resized.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084326-resized.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1838\" title=\"IMG_20140620_084326-resized\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084326-resized-300x168.jpg\" alt=\"\" width=\"300\" height=\"168\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084326-resized-300x168.jpg 300w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084326-resized-500x281.jpg 500w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084326-resized.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><a href=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084442-resized.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1837\" title=\"IMG_20140620_084442-resized\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084442-resized-300x168.jpg\" alt=\"\" width=\"300\" height=\"168\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084442-resized-300x168.jpg 300w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084442-resized-500x281.jpg 500w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/IMG_20140620_084442-resized.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a>2017 update: lightguide for green and orange LEDs:<\/div>\n<div class=\"cFoot\"><a href=\"http:\/\/www.dotmana.com\/weblog\/2014\/06\/usb-motion-sensor-pir-to-wake-up-screen\/p70105-114417\/\" rel=\"attachment wp-att-2229\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-2229 size-medium\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/P70105-114417-300x300.jpg\" alt=\"p70105-114417\" width=\"300\" height=\"300\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/P70105-114417-300x300.jpg 300w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/P70105-114417-150x150.jpg 150w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/P70105-114417-768x768.jpg 768w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/P70105-114417-1024x1024.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/div>\n<div class=\"cFoot\">Update: LED lightguides from the scrap box<\/div>\n<div class=\"cFoot\"><\/div>\n<div class=\"cFoot\">And voila!<\/div>\n<div class=\"cFoot\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1848\" title=\"9pf6c\" src=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/9pf6c.gif\" alt=\"\" width=\"360\" height=\"202\" srcset=\"http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/9pf6c.gif 360w, http:\/\/www.dotmana.com\/weblog\/wp-content\/uploads\/9pf6c-300x168.gif 300w\" sizes=\"auto, (max-width: 360px) 100vw, 360px\" \/><\/div>\n<div class=\"cFoot\">Quite nice, discrete and works very well, for about 10\u20ac\/$.<\/div>\n<div class=\"cFoot\"><\/div>\n<div class=\"cFoot\"><\/div>\n<div class=\"cFoot\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>I have an always on net-book for weather forecast (yeah, when paragliding, you need the most up to date forecast) It basically displays a full screen custom web-page with time and date and weather. Its always on, not really good &hellip; <a href=\"http:\/\/www.dotmana.com\/weblog\/2014\/06\/usb-motion-sensor-pir-to-wake-up-screen\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":1837,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35,12,20,25,28],"tags":[],"class_list":["post-1833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-eee-pc","category-electronics","category-embedded","category-parapente"],"_links":{"self":[{"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/posts\/1833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/comments?post=1833"}],"version-history":[{"count":16,"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/posts\/1833\/revisions"}],"predecessor-version":[{"id":2418,"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/posts\/1833\/revisions\/2418"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/media\/1837"}],"wp:attachment":[{"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/media?parent=1833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/categories?post=1833"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.dotmana.com\/weblog\/wp-json\/wp\/v2\/tags?post=1833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}