Created
December 19, 2017 00:02
-
-
Save michaelkuty/9995545e952296338139e31248cfd2f9 to your computer and use it in GitHub Desktop.
simple pir security
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 time | |
GPIO.setmode(GPIO.BCM) | |
GPIO.setup(17, GPIO.IN) #PIR | |
GPIO.setup(21, GPIO.OUT) # LED | |
GPIO.setup(4, GPIO.OUT) # RELAY | |
try: | |
time.sleep(2) # to stabilize sensor | |
while True: | |
if GPIO.input(17): | |
print("Motion Detected...") | |
GPIO.output(21, True) # LED | |
GPIO.output(4, False) # Relay | |
time.sleep(5) #to avoid multiple detection | |
else: | |
print("Clean...") | |
GPIO.output(21, False) | |
GPIO.output(4, True) # Relay | |
time.sleep(0.1) #loop delay, should be less than detection delay | |
except: | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment