PIR sensor install  
(revised 04/06/2014 - added missing 'sudo' to beginning of screen saver installation command; added sudo apt-get update command)
(revised 04/01/2014 - added .xscreensaver config file)

1. Unpack zip file
	Archive includes:	
		pir_test.py
		pir_run.py
		2x13_header.jpg		- image showing RPi GPIO header pin locations
		hc_sr501.jpg		- image of HC-SR501 PIR sensor
		pir_sensor_install.txt 	- this file
		.xscreensaver		- config file for xscreensaver


2. Install xscreensaver from an LXDE terminal:

sudo apt-get update
sudo apt-get install xscreensaver

After the installation completes, you can copy the ScreenSaver Preferences shortcut from the 'start' menu to the desktop
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, and probably quite a few of the installed ones as well.

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.

[added 04/01/2014] If you want to save yourself some time/aggravation, you can place the included .xscreensaver config file in the /home/pi folder. Also, if you're interested in more detail on xscreensaver, the user manual can be found here http://www.jwz.org/xscreensaver/man1.html.

3. Place pir_test.py and pir_run.py in /home/pi

4. Shutdown the RPi, remove power, and hook up the sensor
Refer to hc_sr501.jpg and 2x13_header.jpg for connection locations.
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

You don't need heavy wire for this. The PIR sensor uses very little power, so 18-20ga 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)


5. Power up and boot to the desktop. Open an LXDE terminal and run pir_test.py:

	sudo python pir_test.py

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 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.


6. 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)
Exit (^x)

6. Restart the RPi and boot to the desktop

Allow xscreensaver to kick in, then wake it up by waving at the PIR sensor.

Cheers!

/dave t. (aka day_trippr)


Scripts are below:
==================================================================
pir_test.py

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
PIR_PIN=7
GPIO.setup(PIR_PIN, GPIO.IN)

def MOTION(PIR_PIN):
	print "Motion Detected!"
	time.sleep(1)

print "PIR Module Test (CTRL_+C to exit)"
time.sleep(2)
print "Ready"

try:
	GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=MOTION)
	while 1:
		time.sleep(100)

except KeyboardInterrupt:
	print " Quit"
	GPIO.cleanup()


==================================================================
pir_run.py

#!/usr/bin/env python

import os
import RPi.GPIO as GPIO
import time

cmd = 'xscreensaver-command -deactivate'

GPIO.setmode(GPIO.BCM)
PIR_PIN=7
GPIO.setup(PIR_PIN, GPIO.IN)

def MOTION(PIR_PIN):
	os.system(cmd)
	time.sleep(1)

time.sleep(2)

try:
	GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=MOTION)
	while 1:
		time.sleep(100)

except KeyboardInterrupt:
	GPIO.cleanup()
