-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotionSensorPiCam.py
More file actions
35 lines (30 loc) · 825 Bytes
/
MotionSensorPiCam.py
File metadata and controls
35 lines (30 loc) · 825 Bytes
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
34
#!/usr/bin/env python3
from gpiozero import MotionSensor
from gpiozero import Buzzer
from picamera import PiCamera
from datetime import datetime
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
buzzer_pin = 24
led_pin = 18
GPIO.setup(24, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)
camera = PiCamera()
pir = MotionSensor(4)
while True:
pir.wait_for_motion()
filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264")
camera.capture("/home/pi/Desktop/image.jpg")
camera.start_recording(filename)
GPIO.output(buzzer_pin, True)
GPIO.output(led_pin, True)
sleep(1)
GPIO(1)
GPIO.output(buzzer_pin, False)
pir.wait_for_no_motion()
GPIO.output(led_pin, True)
GPIO.output(buzzer_pin, True)
sleep(1)
GPIO.output(buzzer_pin, False)
camera.stop_recording()