{"id":741,"date":"2014-01-30T18:19:55","date_gmt":"2014-01-31T01:19:55","guid":{"rendered":"http:\/\/somethingk.com\/main\/?p=741"},"modified":"2017-03-24T06:57:26","modified_gmt":"2017-03-24T13:57:26","slug":"pir-sensor-on-the-pi","status":"publish","type":"post","link":"https:\/\/somethingk.com\/main\/pir-sensor-on-the-pi\/","title":{"rendered":"PIR Sensor on the Pi"},"content":{"rendered":"<section id=\"text-4\" class=\"widget boka-widget widget_text amr_widget\">\t\t\t<div class=\"textwidget\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script>\r\n<ins class=\"adsbygoogle\"\r\n     style=\"display:block; text-align:center;\"\r\n     data-ad-layout=\"in-article\"\r\n     data-ad-format=\"fluid\"\r\n     data-ad-client=\"ca-pub-7619916617995509\"\r\n     data-ad-slot=\"9102150708\"><\/ins>\r\n<script>\r\n     (adsbygoogle = window.adsbygoogle || []).push({});\r\n<\/script><\/div>\n\t\t<\/section>\n<p>Today I soldered a PIR sensor to my Pi! Basically, I want it to detect movement and turn on a LCD screen, then turn the screen off again after a minute of no movement. So when I walk into a room, the screen turns on and when I leave, the screen turns off.<\/p>\n<p><strong>Equipment<\/strong><\/p>\n<ul>\n<li>My Pi (See early <a title=\"Soldering an LCD to the Raspberry Pi\" href=\"http:\/\/somethingk.com\/main\/?p=666\">Posts<\/a>)<\/li>\n<li><a title=\"PIR\" href=\"http:\/\/www.adafruit.com\/products\/189\" target=\"_blank\">PIR Sensor<\/a> ($10)<\/li>\n<li>Soldering Iron (<a title=\"Aoyue 937+\" href=\"http:\/\/www.amazon.com\/Aoyue-937-Digital-Soldering-Station\/dp\/B000I30QBW\" target=\"_blank\">Aoyue 937+<\/a>\u00a0is about $63 on Amazon)<\/li>\n<li><a title=\"Alpha Fry AT Core Solder\" href=\"http:\/\/www.amazon.com\/gp\/product\/B00030AP48\/ref=oh_details_o03_s00_i01?ie=UTF8&amp;psc=1\" target=\"_blank\">Solder<\/a>\u00a0($8.16 Amazon Prime)<\/li>\n<\/ul>\n<p><strong>Solder<\/strong><\/p>\n<p>First thing, I looked up the pinout for the Raspberry Pi. The below diagram comes from <a title=\"RPi Low-level peripherals\" href=\"http:\/\/elinux.org\/RPi_Low-level_peripherals\" target=\"_blank\">elinux.org<\/a>.<\/p>\n<p><a href=\"http:\/\/elinux.org\/images\/2\/2a\/GPIOs.png\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/elinux.org\/images\/2\/2a\/GPIOs.png\" alt=\"\" width=\"254\" height=\"581\" \/><\/a><\/p>\n<p>We care about one of the 5V, ground and GPIO25 pins.<\/p>\n<ul>\n<li>Solder the sensor red cable to either 5V.<\/li>\n<li>Solder the black cable to ground.<\/li>\n<li>End by soldering the yellow line to GPIO25.<\/li>\n<\/ul>\n<p>Your results should be similar to my picture below.<\/p>\n<p><a href=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/back.jpg\"><img decoding=\"async\" class=\"aligncenter size-medium wp-image-743\" src=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/back-300x225.jpg\" alt=\"back\" width=\"300\" height=\"225\" srcset=\"https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/back-300x225.jpg 300w, https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/back-1024x768.jpg 1024w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Next, I used this <a title=\"Building a living photo frame with a Raspberry Pi and a motion detector\" href=\"http:\/\/www.ofbrooklyn.com\/2014\/01\/2\/building-photo-frame-raspberry-pi-motion-detector\/\" target=\"_blank\">guy&#8217;s pir.py<\/a> script. The script requires the Python library RPi.GPIO. I installed this by downloading the library from <a title=\"RPi.GPIO 0.5.4\" href=\"https:\/\/pypi.python.org\/pypi\/RPi.GPIO\" target=\"_blank\">here<\/a>, the direct link is <a title=\"RPi.GPIO-0.5.4.tar.gz\" href=\"https:\/\/pypi.python.org\/packages\/source\/R\/RPi.GPIO\/RPi.GPIO-0.5.4.tar.gz\" target=\"_blank\">here<\/a>. To untag or unzip the file I used the following command:<\/p>\n<pre>tar -xvf\u00a0RPi.GPIO-0.5.4.tar.gz<\/pre>\n<p>Before installing it, make sure you have python-dev installed.<\/p>\n<pre>apt-get install python-dev<\/pre>\n<p>With that necessary package, install RPi.GPIO.<\/p>\n<pre>cd\u00a0RPi.GPIO-0.5.4\r\npython setup.py install<\/pre>\n<p>Now you can run the pir.py script. I made some slight changes to his code. I didn&#8217;t feel the need to call separate scripts to run a single command so I made the following edits.<\/p>\n<pre>import subprocess<\/pre>\n<p>to<\/p>\n<pre>import os<\/pre>\n<p>and<\/p>\n<pre>def turn_on(): \r\n\u00a0\u00a0\u00a0\u00a0subprocess.call(\"sh \/home\/pi\/photoframe\/monitor_on.sh\", shell=True)<\/pre>\n<pre>def turn_off(): \r\n\u00a0\u00a0\u00a0\u00a0subprocess.call(\"sh \/home\/pi\/photoframe\/monitor_off.sh\", shell=True)<\/pre>\n<p>this<\/p>\n<pre>def turn_on(): \r\n\u00a0\u00a0\u00a0\u00a0os.system(\"chvt 2\")<\/pre>\n<pre>def turn_off(): \r\n\u00a0\u00a0\u00a0\u00a0os.system(\"chvt 2\")<\/pre>\n<p><span style=\"font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 14px; line-height: 1.5em;\">Run the script and test it out! The sensor will turn off after a minute of no movement and on again once it detects something. I ended by setting my script to run on <a title=\"Init.d Scripts\" href=\"http:\/\/somethingk.com\/main\/?p=705\">startup<\/a>.<\/span><\/p>\n<p><a href=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/2014-01-30-20.33.51.jpg\"><img decoding=\"async\" class=\"aligncenter size-medium wp-image-751\" src=\"http:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/2014-01-30-20.33.51-225x300.jpg\" alt=\"2014-01-30 20.33.51\" width=\"225\" height=\"300\" srcset=\"https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/2014-01-30-20.33.51-225x300.jpg 225w, https:\/\/somethingk.com\/main\/wp-content\/uploads\/2014\/01\/2014-01-30-20.33.51-768x1024.jpg 768w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>I need to put a picture in the frame to act as background to the pi&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today I soldered a PIR sensor to my Pi! Basically, I want it to detect movement and turn on a LCD screen, then turn the screen off again after a minute of no movement. So when I walk into a room, the screen turns on and when I leave, the screen turns off. Equipment My Pi (See early Posts) PIR [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[147,37,6,72],"tags":[199,201,202,59,198,196,203,339,61,204,197,163,200],"class_list":["post-741","post","type-post","status-publish","format-standard","hentry","category-hardware","category-kali","category-linux","category-python","tag-movement","tag-off","tag-on","tag-pi","tag-pinout","tag-pir","tag-power","tag-python","tag-raspberry-pi","tag-rpi-gpio","tag-sensor","tag-soldering","tag-turn"],"_links":{"self":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/comments?post=741"}],"version-history":[{"count":9,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/741\/revisions"}],"predecessor-version":[{"id":1092,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/posts\/741\/revisions\/1092"}],"wp:attachment":[{"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/media?parent=741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/categories?post=741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/somethingk.com\/main\/wp-json\/wp\/v2\/tags?post=741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}