Aaaaand it just plain works!
To answer DanH: The HC SR501 PIR motion sensor is powered directly by the RPi, via the 5V rail. The sensor uses three connections to the RPi: 5V, GND, and GPIO7. The sensor has a local regulator that converts the 5V to 3.3V which runs the entire board, and making the output "RPi Safe" without dividers, etc.
Ok...So I haven't had to put an "instructable" together for a looong time, so bear with me. First person through let me know if there are any problems and I'll fix 'em up pronto. And I hope putting this here is ok with the 'Pints community!
Preview: You'll install xscreensaver and verify it works, stick the test and runtime scripts in the /home/pi folder, shut down and wire up the sensor, power up and test the sensor, then add an entry to the LXDE autostart file, and finally reboot to what should be a working feature.
Right then, we're off:
Unpack zip file:
I've put a zip file up on Google Drive with the two scripts, the instructions, and a couple of images to orient the user to the RPi GPIO header and the sensor. That file can be downloaded from
here.
Unpack the file and place the two Python scripts (pir_test.py and pir_run.py) in the /home/pi folder. Have the other files handy as you put things together.
Install xscreensaver from an LXDE terminal:
apt-get install xscreensaver
After the installation completes, you can Add the ScreenSaver Preferences shortcut from the 'start' menu (look in folder "Other") to the desktop to make it handy while you're setting things up.
Most of the screensavers are not installed as part of the kit, but they
are selected in the ScreenSaver Preferences - Display Modes sheet. You'll want to de-select the unavailable screensavers (stick your cursor on a title and if it doesn't show up in the preview pane it isn't installed), and probably quite a few of the installed ones as well. The Preferences gui is a total POS but it's free, so don't complain
In any case, you'll want to verify the xscreensaver is actually working before proceeding. In ScreenSaver Preferences - Display Modes you can set the "Blank After" delay to something short so you're not twiddling your thumbs waiting for it to kick in.
Shut down, remove power and wire up the PIR sensor
Refer to hc_sr501.jpg and 2x13_header.jpg for connection locations (pictures are below).
A detailed description of the HC SR501 can be found here:
http://www.mpja.com/download/31227sc.pdf
5V: Pin 2
GND: Pin 6,9,14,20 or 25 (pick one)
GPIO7: Pin 26
For orientation on a Model B RPi, Pin 2 is located almost in the very corner of the RPi board. Pin 26 is at the opposite end of the same row.
You don't need heavy wire for this. The PIR sensor uses very little power, so 18-22ga stranded is fine.
Notes:
- Verify that the two pin jumper is positioned as shown in hc_sr501.jpg
- Set the Sensitivity Adjust to 50% of travel to start
- Set the Time Delay Adjust full counter-clockwise to start (minimum delay between triggers is roughly 10 seconds)
Power up and boot to the desktop
Open an LXDE terminal and run pir_test.py as root
sudo python pir_test.py
You'll see the following text appear:
PIR Module Test (CTRL+C to exit)
Ready
Let the PIR settle for ~10 seconds, then wave a hand in front of the sensor.
The terminal should immediately show:
Motion Detected!
The script will continue to respond to PIR interrupts until you CTRL+C out.
If you do not get the PIR to respond, shut down and verify your wiring, then verify the above steps.
You can play around with the Sensitivity Adjust potentiometer until you're happy with the response, and you'll likely want to tune it when you have the RPi and sensor in their final locations. The Time Delay Adjust can be left at minimum - the sensor will retrigger after the delay and keep the display "alive" while you're moving around in front of your dispensing system.
Set up Autostart for the PIR runtime script
Add an entry to LXDE startup to autostart the PIR run time script. In an LXDE terminal:
sudo nano /etc/xdg/lxsession/LXDE/autostart
Add this line at the bottom:
sudo python pir_run.py
Write out the file (^o) and exit (^x)
Restart the RPi and boot to the desktop
Allow xscreensaver to kick in, then wake it up by waving at the PIR sensor.
That's all there is to it!
fwiw, both sensors I received worked perfectly (best as I can tell, anyway).
I haven't spent a lot of time playing with the Sensitivity adjustment. Set at 50% of travel the sensor picks me up when I come in my office door a good ten feet from the sensor, which isn't even pointed at the doorway. So it appears the sensor is certainly sensitive enough for this application
Cheers!