Last active
June 10, 2016 21:56
-
-
Save rjulian/f5a961e72b9b493ebf9aeedb5973687f to your computer and use it in GitHub Desktop.
Simple PIR sensor program for raspberry Pi.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import datetime | |
import time | |
GPIO.setmode(GPIO.BCM) | |
GPIO_PIR = 21 | |
GPIO.setup(GPIO_PIR,GPIO.IN) | |
Current_State = 0 | |
Previous_State = 0 | |
try: | |
print "Waiting for PIR to settle ..." | |
while GPIO.input(GPIO_PIR)==1: | |
Current_State = 0 | |
print " Ready " | |
while True : | |
Current_State = GPIO.input(GPIO_PIR) | |
if Current_State==1 and Previous_State==0: | |
print " Motion detected!" | |
print datetime.datetime.now() | |
Previous_State=1 | |
elif Current_State==0 and Previous_State==1: | |
print " Ready" | |
Previous_State=0 | |
time.sleep(0.01) | |
except KeyboardInterrupt: | |
print " Quit" | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment