Skip to content

Instantly share code, notes, and snippets.

@15nmcgoldrick
Last active February 28, 2017 10:39
Show Gist options
  • Save 15nmcgoldrick/8d749ff54f473c37c1f63965353856dd to your computer and use it in GitHub Desktop.
Save 15nmcgoldrick/8d749ff54f473c37c1f63965353856dd to your computer and use it in GitHub Desktop.
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(23,GPIO.out)
GPIO.setup(17,GPIO.out)
GPIO.setup(16,GPIO.out)
#the code
GPIO.output(16,GPIO.HIGH) #turns green light on
GPIO.output(23, GPIO.HIGH) #turns motor on
sleep(5) #this allows the previous action to work for 5 seconds
GPIO.output(23,GPIO.LOW) #turns motor off
GPIO.output(16,GPIO.LOW) #turns green light off
GPIO.output(23,GPIO.HIGH)
GPIO.output(17,GPIO.HIGH)
sleep(5)
GPIO.output(23,GPIO.LOW)
GPIO.output(17,GPIO.LOW)
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(23, GPIO.IN) #Read output from motion sensor
GPIO.setup(17, GPIO.OUT) #LED output pin
while True:
i=GPIO.input(23)
if i==0: #When output from motion sensor is LOW
print "No intruders",i
GPIO.output(3, 0) #Turn OFF LED
time.sleep(0.1)
elif i==1: #When output from motion sensor is HIGH
print "Intruder detected",i
GPIO.output(3, 1) #Turn ON LED
time.sleep(0.1)
cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment