@@ -0,0 +1,2001 @@
+# Detect motion from PIR module%0A# SKELETON code modified from http://www.raspberrypi-spy.co.uk%0A# Added computation of voltage time from PIR and checks%0A# by AC Jan 06 2014%0A%0A%0A# Import required Python libraries%0Aimport RPi.GPIO as GPIO, time%0A%0A# Use BCM GPIO references instead of physical pin numbers%0AGPIO.setmode(GPIO.BCM)%0A%0A# Define GPIO to use on Pi%0AGPIO_PIR = 7%0A%0A# Set pin as input, check connection to sensor%0AGPIO.setup(GPIO_PIR,GPIO.IN)%0ACurrent_State  = 0%0APrevious_State = 0%0A%0A# Check unique ID and datastream%0A#%0A#%0A%0A%0A# Define function to measure charge time%0A  # allows for PROPORTIONAL motion level not just high/low%0A  # (need breadboard w/resistor and capacitor in series)%0Adef RCtime (PiPin):%0A  measurement = 0%0A  # Discharge capacitor%0A  GPIO.setup(PiPin, GPIO.OUT)%0A  GPIO.output(PiPin, GPIO.LOW)%0A  time.sleep(0.1)%0A%0A  GPIO.setup(PiPin, GPIO.IN)%0A  # Count loops until voltage across capacitor reads high on GPIO%0A  while (GPIO.input(PiPin) == GPIO.LOW):%0A    measurement += 1%0A  return measurement%0A%0A%0A%0A%0Atry:%0A %0A  print %22Waiting for PIR to settle ...%22%0A %0A  # This will run unless PIR output is zero, ensuring that it settles%0A  while GPIO.input(GPIO_PIR)==1:%0A    Current_State  = 0%0A %0A  print %22  Ready%22%0A %0A  # Loop until users quits with CTRL-C%0A  while True :%0A %0A    # Read PIR state%0A    Current_State = GPIO.input(GPIO_PIR)%0A %0A    if Current_State==1 and Previous_State==0:%0A      # PIR is triggered%0A      print %22  Motion detected!%22%0A      # Voltage is reocrded as high or low%0A      # Record time taken to reach high voltage for proportional motion level%0A      time = RCtime(7) %0A      # Update previous state%0A      Previous_State=1%0A    elif Current_State==0 and Previous_State==1:%0A      # PIR has returned to ready state%0A      print %22  Ready%22%0A      Previous_State=0%0A%0A    # Output voltage and time to formatting function / database%0A    # %0A    #%0A    %0A    # Wait for 10 milliseconds; may change with testing%0A    time.sleep(0.01)%0A %0Aexcept KeyboardInterrupt:%0A  print %22  Quit%22%0A  # Reset GPIO settings%0A  GPIO.cleanup()%0A%0A  %0A

Add skeleton code for PIR motion sensor