Skip to content

Instantly share code, notes, and snippets.

@elktros
Last active May 20, 2019 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elktros/2b3817b87e2fbf387a116e77006769f1 to your computer and use it in GitHub Desktop.
Save elktros/2b3817b87e2fbf387a116e77006769f1 to your computer and use it in GitHub Desktop.
Python Script for Interfacing PIR Motion Sensor with Raspberry Pi.
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()
@Rishan123
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment