Last active
February 28, 2017 10:39
-
-
Save 15nmcgoldrick/8d749ff54f473c37c1f63965353856dd to your computer and use it in GitHub Desktop.
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 | |
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