Last active
May 20, 2019 18:46
-
-
Save elktros/2b3817b87e2fbf387a116e77006769f1 to your computer and use it in GitHub Desktop.
Python Script for Interfacing PIR Motion Sensor with 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 time | |
sensor = 16 | |
buzzer = 18 | |
GPIO.setmode(GPIO.BOARD) | |
GPIO.setup(sensor,GPIO.IN) | |
GPIO.setup(buzzer,GPIO.OUT) | |
GPIO.output(buzzer,False) | |
print "Initialzing PIR Sensor......" | |
time.sleep(12) | |
print "PIR Ready..." | |
print " " | |
try: | |
while True: | |
if GPIO.input(sensor): | |
GPIO.output(buzzer,True) | |
print "Motion Detected" | |
while GPIO.input(sensor): | |
time.sleep(0.2) | |
else: | |
GPIO.output(buzzer,False) | |
except KeyboardInterrupt: | |
GPIO.cleanup() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I keep on getting :
Traceback (most recent call last): File "/home/pi/smart_lighting.py", line 8, in <module> GPIO.setup(sensor,GPIO.IN) ValueError: The channel sent is invalid on a Raspberry Pi
Can you help?