PIR sensor lags in taking pictures

  • Context: Electrical 
  • Thread starter Thread starter fog37
  • Start date Start date
  • Tags Tags
    Pictures Sensor
Click For Summary

Discussion Overview

The discussion revolves around the performance of a Raspberry Pi setup using a PIR motion sensor and a Pi Camera, specifically addressing the lag in taking pictures when motion is detected. Participants explore potential reasons for the delay and suggest alternative solutions or sensors.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Experimental/applied

Main Points Raised

  • One participant notes that the PIR sensor's response time may be affected by the temperature of the hands, as the sensor detects changes in infrared radiation.
  • Another participant questions the specific model of the PIR sensor being used and whether it has an LED indicator for motion detection, suggesting that delays could be related to the sensor's design.
  • Some participants propose that the adjustable delay feature of the PIR sensor might be contributing to the lag in capturing images.
  • There is a suggestion to consider using alternative motion detection technologies, such as microwave or ultrasonic sensors, which may respond more quickly.
  • A participant raises the issue of the time it takes to initialize the camera and suggests that this could also contribute to the overall delay in taking pictures.
  • One idea presented is to implement a circular buffer to capture images at a steady rate, allowing for the retrieval of images taken just before motion is detected.
  • Concerns are expressed about the potential wear on the Raspberry Pi's SD card due to continuous writes if a circular buffer is used on the system drive.
  • A participant shares a code snippet for the current implementation, indicating that the goal is to capture images whenever an object is presented to the camera.

Areas of Agreement / Disagreement

Participants express various viewpoints regarding the causes of the delay and potential solutions, with no consensus reached on the best approach or the specific reasons for the lag in taking pictures.

Contextual Notes

Some limitations include the dependence on the specific model of the PIR sensor, the initialization time of the camera, and the potential impact of using a circular buffer on the SD card's lifespan.

fog37
Messages
1,566
Reaction score
108
TL;DR
PIR and Pi Camera Circuit taking pictures when detecting motion
Hello,
I am using a Raspberry Pi with a PIR motion sensor and a Pi Camera. The idea is that the camera should take a picture every time the PIR sensor detects motion. The system works but it does not respond, i.e. take a picture, as fast as I would like if I wave my hand in front of the PIR sensor...

Any idea why? Ideally, I could just wait a second, wave my hand in front of the sensor, and have the camera take a pic. But it does not happen? Any idea?

Should I use a distance sensor instead?

Thanks!
 
Physics news on Phys.org
Maybe your hands are cold.
A PIR sensor measures the average temperature of two areas. When the temperature shows an imbalance, it detects that difference. Warming or cooling the sensor through changes in the IR environment takes time. The signal is noisy so it also takes time to average the result.

There are faster motion detectors that detect changes in the space near a sensor by using a very low power microwave field.

Ultrasonic range detectors are also possible.
 
  • Like
Likes   Reactions: fog37
fog37 said:
Summary:: PIR and Pi Camera Circuit taking pictures when detecting motion

I am using a Raspberry Pi with a PIR motion sensor and a Pi Camera. The idea is that the camera should take a picture every time the PIR sensor detects motion. The system works but it does not respond, i.e. take a picture, as fast as I would like if I wave my hand in front of the PIR sensor...

Any idea why? Ideally, I could just wait a second, wave my hand in front of the sensor, and have the camera take a pic. But it does not happen? Any idea?
Which PIR sensor are you using? Does it have an LED indicator that flashes when it detects a change? If so, is there a delay in the LED flash compared to what you expect, or a delay in the notification of the Pi after the LED flash?

Most PIR sensors use refracting lenses to detect any motion of IR sources. Does your PIR sensor have that, or is it simpler?
 
  • Like
Likes   Reactions: fog37
berkeman said:
Which PIR sensor are you using? Does it have an LED indicator that flashes when it detects a change? If so, is there a delay in the LED flash compared to what you expect, or a delay in the notification of the Pi after the LED flash?

Most PIR sensors use refracting lenses to detect any motion of IR sources. Does your PIR sensor have that, or is it simpler?
Thanks.

I am using this one:

https://www.adafruit.com/product/18...zoF9xZKUOHnCKh7yyQ7Avni0qnJZcAsxoCrgsQAvD_BwE

1618703255373.png
 
fog37 said:
I am using this one:
(possibly works on zombies, not guaranteed). This one has an adjustable delay before firing (approx 2-4 seconds),
Are you testing it with Zombies? It looks like it's not guaranteed in that use-case... :smile:

It looks like the delay "feature" might be an issue? I don't see an LED output to indicate firing, unfortunately...

EDIT/ADD -- I just tested my room PIR sensors (that light nightlights), and the LEDs blink within about 100-200ms of motion being detected and the nightlights lite with that delay (plus some ballast delay). I think you just need to pick different PIR sensors that don't have a minimum delay of 2s.
 
  • Like
Likes   Reactions: fog37 and hutchphd
How are you taking pictures? With raspistill? Have you tested how long it takes to take the picture? If memory serves me well there is quite a lag required to init the camera.
 
  • Like
Likes   Reactions: fog37
Maybe you could capture images at a steady rate, storing them in a short circular buffer, then keep the image from 2 seconds before the sensor reported detecting motion.
 
Baluncore said:
Maybe you could capture images at a steady rate, storing them in a short circular buffer, then keep the image from 2 seconds before the sensor reported detecting motion.

I would just try to avoid keeping the buffer on the system drive, pi uses SD card for disk (unless there is some other disk mounted through net/USB) and it is quite easy to wear flash memory witch continuous writes required for such a buffering.
 
  • Informative
  • Like
Likes   Reactions: fog37 and berkeman
Borek said:
I would just try to avoid keeping the buffer on the system drive, pi uses SD card for disk (unless there is some other disk mounted through net/USB) and it is quite easy to wear flash memory witch continuous writes required for such a buffering.
Hello,

This is the code is reported below. No raspstill. The end game is for the camera to snap picture every time an object is presented to it (a cup, a book, etc.).

Python:
from gpiozero import Button, MotionSensor
from picamera import PiCamera
from time import sleep
from signal import pause
#create objects that refer to a button,
#a motion, sensor, and the PiCamera
button = Button(2)
pir = MotionSensor(4)
camera = PiCamera()
#start the camera
camera.rotation = 180
camera.start_preview()
#create image names
i = 0
#stop the camera when the pushbutton is pressed
def stop_camera():
camera.stop_preview()
#exit the program
exit()
#take a photo when motion is detected
def take_photo():
global i
i = i + 1
camera.capture('/home/pi/Desktop/image_%s.jpg' % i)
print('A photo has been taken')
sleep(10)
#assign a function that runs when the button is pressed
button.when_pressed = stop_camera
#assign a function that runs when motion is detected
pir.when_motion = take_photo
pause()
 

Similar threads

  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 35 ·
2
Replies
35
Views
8K
  • · Replies 26 ·
Replies
26
Views
5K
  • · Replies 7 ·
Replies
7
Views
7K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
2
Views
867
Replies
2
Views
4K