Skip to content

Instantly share code, notes, and snippets.

@michaelkuty
Created December 19, 2017 00:02
Show Gist options
  • Save michaelkuty/9995545e952296338139e31248cfd2f9 to your computer and use it in GitHub Desktop.
Save michaelkuty/9995545e952296338139e31248cfd2f9 to your computer and use it in GitHub Desktop.
simple pir security
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