Skip to content

Instantly share code, notes, and snippets.

@kentros
Created February 17, 2018 04:44
Show Gist options
  • Save kentros/44a9ad332a8e6e07445be650b9a82d47 to your computer and use it in GitHub Desktop.
Save kentros/44a9ad332a8e6e07445be650b9a82d47 to your computer and use it in GitHub Desktop.
Passive Infrared Sensor code for a Raspberry Pi
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
PIR_PIN = 25
GPIO.setup(PIR_PIN, GPIO.IN)
def MOTION(PIR_PIN):
print 'Motion Detected! ' + time.ctime()
print 'PIR Module Test (CTRL+C to exit)'
time.sleep(2)
print 'Ready'
try:
GPIO.add_event_detect(PIR_PIN, GPIO.RISING, callback=MOTION)
while 1:
time.sleep(100)
except KeyboardInterrupt:
print ' Quit'
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment