0

I have some code that when the PIR Sensor is triggered the camera takes one single images and uploads it to Azure blob storage, taking one single photo is not sufficient but I can't get the Program to take multiple images when the camera is triggered. This is the code I have so far

from gpiozero import MotionSensor
from picamera import PiCamera
from datetime import datetime
from azure.storage.blob import BlockBlobService
from azure.storage.blob import ContentSettings

camera = PiCamera()
pir = MotionSensor()
block_blob_service = BlockBlobService(account_name='YOURACCOUNT', account_key='YOURKEY')

while True:
pir.wait_for_motion()
filename = "pircam-" +  datetime.now().strftime("%Y-%m-%d_%H.%M.%S.jpg")
camera.capture(filename)
pir.wait_for_no_motion()
block_blob_service.create_blob_from_path(
'YOURCONTAINER',
filename,
filename,
content_settings=ContentSettings(content_type='image/jpeg'))
1

I personally would change your functions to be pir.isThereMotion() that returns true/false then you could do

while true:
    if pir.isThereMotion():
        filename = "pircam-" +  datetime.now().strftime("%Y-%m-%d_%H.%M.%S.jpg")
        camera.capture(filename)
        time.sleep(1)
        ....

This way it will just take a picture ever second while motion is detected, no need to wait for it to start and wait for it to stop.

but using what you have now, you could just loop on the lines that capture/save an image a certain number of times

while True:
    pir.wait_for_motion()
    for x in range(numberOfPicturesYouWantToTake):
        filename = "pircam-" +  datetime.now().strftime("%Y-%m-%d_%H.%M.%S.jpg")
        camera.capture(filename)
        time.sleep(1)
        ...
1
  • I'll try this out, Thanks for the response.
    – M.McCann
    Apr 26 '19 at 7:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.