PIR sensor lags in taking pictures

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

The discussion centers on the lag experienced when using a PIR motion sensor with a Raspberry Pi and a Pi Camera to capture images. Users noted that the PIR sensor, specifically the Adafruit PIR sensor, has a minimum delay of 2-4 seconds before it triggers the camera, which is unsuitable for rapid motion detection. Suggestions included using faster motion detection technologies such as ultrasonic sensors or microwave sensors, and optimizing the image capture process by implementing a circular buffer to store images prior to motion detection.

PREREQUISITES
  • Understanding of Raspberry Pi hardware and GPIO pin configuration
  • Familiarity with Python programming and libraries such as gpiozero and picamera
  • Knowledge of PIR sensor operation and limitations
  • Basic concepts of image processing and buffering techniques
NEXT STEPS
  • Research alternatives to PIR sensors, such as ultrasonic or microwave motion detectors
  • Learn about implementing circular buffers in Python for image storage
  • Explore the use of the raspistill command for optimized image capture
  • Investigate the impact of SD card wear on Raspberry Pi performance and alternatives for storage
USEFUL FOR

Electronics hobbyists, Raspberry Pi enthusiasts, developers working on motion detection projects, and anyone interested in optimizing image capture systems.

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
7K
  • · 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
702
Replies
2
Views
4K