-
Notifications
You must be signed in to change notification settings - Fork 2
/
pir.py
33 lines (25 loc) · 847 Bytes
/
pir.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from picamera import PiCamera
from time import sleep
camera = PiCamera()
#~ camera.start_preview()
#~ sleep(5)
#~ camera.capture('/home/pi/Desktop/motion')
#~ camera.stop_preview()
import RPi.GPIO as GPIO
import time
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN) #Read output from PIR motion sensor
GPIO.setup(3, GPIO.OUT) #LED output pin
while True:
i=GPIO.input(11)
if i==0: #When output from motion sensor is LOW
print "NO_Motion_detected",i
GPIO.output(3, 0) #Turn OFF LED
time.sleep(0.1)
elif i==1: #When output from motion sensor is HIGH
print "Motion_detected",i
print "Image_Capturing",i
camera.capture('/home/pi/Desktop/motion/image.jpg')
GPIO.output(3, 1) #Turn ON LED
time.sleep(3)