PIR sensor lags in taking pictures

In summary, the system works, but it takes a long time for the camera to take a picture after the PIR sensor detects motion.
  • #1
fog37
1,569
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
  • #2
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
  • #3
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
  • #4
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
 
  • #5
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
  • #6
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
  • #7
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.
 
  • #8
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
  • #9
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()
 

FAQ: PIR sensor lags in taking pictures

Why does my PIR sensor take a long time to capture a picture?

There are several factors that can contribute to a PIR sensor lagging in taking pictures. One possible reason is that the sensor may have a slow response time, meaning it takes longer to detect motion and trigger the camera. Another reason could be a low battery or power supply, which can affect the sensor's sensitivity and performance. Additionally, the PIR sensor may be affected by interference from other electronic devices, causing delays in capturing pictures.

Can the sensitivity of the PIR sensor be adjusted to reduce lag time?

Yes, the sensitivity of a PIR sensor can be adjusted to reduce lag time. Most PIR sensors have a sensitivity adjustment knob or setting that allows you to fine-tune the sensor's sensitivity to motion. By adjusting this setting, you can increase or decrease the sensor's response time and potentially reduce lag in capturing pictures.

Is there a way to speed up the PIR sensor's response time?

There are a few steps you can take to potentially speed up the PIR sensor's response time. First, make sure the sensor is properly positioned and aimed at the area you want to monitor. If the sensor is not pointed in the right direction, it may take longer to detect motion and capture pictures. You can also try adjusting the sensitivity, as mentioned in the previous question. Additionally, keeping the sensor clean and free of any obstructions can help improve its performance and response time.

Can extreme temperatures affect the PIR sensor's performance?

Yes, extreme temperatures can affect the performance of a PIR sensor and potentially cause lag in taking pictures. Very high or very low temperatures can affect the sensor's sensitivity and response time, so it's important to keep the sensor within its recommended operating temperature range. If the sensor is exposed to extreme temperatures, it may need to warm up or cool down before functioning properly.

Are there any other factors that can cause PIR sensor lag in taking pictures?

Aside from the factors mentioned above, there are a few other things that can contribute to PIR sensor lag. These include the distance between the sensor and the subject, the angle at which the sensor is mounted, and the type of material the sensor is mounted on. It's important to carefully consider these factors when setting up a PIR sensor to ensure optimal performance and minimize lag time.

Similar threads

Replies
35
Views
6K
Replies
26
Views
4K
Replies
7
Views
6K
Replies
4
Views
2K
Replies
5
Views
2K
Replies
4
Views
2K
Back
Top