본문 바로가기

Tech/라즈베리파이

라즈베리파이3 - 모션센서 PIR

라즈베리파이3 - 모션센서 PIR


cat motion.pir.02.py 

import RPi.GPIO as GPIO

import time

 

GPIO.setmode(GPIO.BCM)

PIR_PIN = 25 # GPIO PIN POSITION

GPIO.setup(PIR_PIN, GPIO.IN)

 

def MOTION(PIR_PIN):

    print "Motion Detected!"

 

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()