Electrical PIR sensor lags in taking pictures

  • Thread starter Thread starter fog37
  • Start date Start date
  • Tags Tags
    Pictures Sensor
AI Thread Summary
The discussion centers on the performance issues of a Raspberry Pi setup using a PIR motion sensor and a Pi Camera, specifically regarding the delay in capturing images upon motion detection. Users note that the current PIR sensor has a built-in delay of 2-4 seconds, which affects responsiveness. Suggestions include testing different PIR sensors with shorter response times and considering the use of other motion detection technologies, such as microwave or ultrasonic sensors, for faster detection. Additionally, the code provided for capturing images is analyzed, with recommendations to implement a circular buffer for image storage to mitigate delays caused by camera initialization. Users also caution against excessive writes to the Raspberry Pi's SD card to avoid wear. Overall, the conversation emphasizes the need for a more responsive sensor and efficient image capture methods to achieve the desired functionality.
fog37
Messages
1,566
Reaction score
108
TL;DR Summary
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 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 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 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 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 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()
 
Back
Top