I'm trying to write a program in python 3.4 for my Raspberry Pi that will take some photos when motion is detected from an IR sensor ( A bird table in this case).
The camera and IR sensor are working fine but I'm trying to figure out how to just take a few pictures when a bird triggers the sensor and then put the program to sleep for a bit and then take some more photos later when another bird arrives. The problem with my program is that it just continually takes photos non-stop when any motion is detected. Any ideas. Thanks.
from gpiozero import MotionSensor import time from datetime import datetime from picamera import PiCamera from time import sleep camera=PiCamera() pir = MotionSensor(4) while True: if pir.motion_detected: sleep(1) filename = datetime.now().strftime("%Y-%m-%d_%H.%M.%S") camera.capture('/home/pi/Desktop/images/'+filename +'.jpg') print('picture taken')