ancris00
Posts: 135
Joined: Sun Jan 19, 2020 8:56 pm
Location: Miranda de Ebro, Spain
Contact: Website

Program to take pictures of the intruder does not work

Fri May 14, 2021 8:54 pm

Hi all,
I have a sensor (PIR) connected to pin 17
and a relay in pin 27

When motion is detected the program switchs on the relay (supplying energy to a pair of torches)
and ideally, the program starts to take pictures of the thief, but only takes one, why?

Code: Select all

from gpiozero import MotionSensor
from gpiozero import LED
from picamera import PiCamera
from datetime import datetime

pir = MotionSensor(17)
relay = LED (27)
camera = PiCamera()
camera.rotation = 180
camera.resolution = (640, 480)
timestamp = datetime.now().isoformat()

while True:
	pir.wait_for_motion()
	relay.on()
	camera.capture('/home/pi/%s.jpg' % timestamp)
	
	pir.wait_for_no_motion()
	relay.off()
	
when I move I can listen to the relay switching on and off
please help
:lol: :lol: Pi 4 Model B :lol: :lol:
Raspbian Buster with desktop 4.19

User avatar
topguy
Posts: 7139
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Program to take pictures of the intruder does not work

Fri May 14, 2021 9:31 pm

You dont update the "timestamp" value in the loop, its just writing the same filename over and over...

ancris00
Posts: 135
Joined: Sun Jan 19, 2020 8:56 pm
Location: Miranda de Ebro, Spain
Contact: Website

Re: Program to take pictures of the intruder does not work

Sat May 15, 2021 9:36 am

Shall I put this line

Code: Select all

 timestamp = datetime.now().isoformat()
inside the loop as well ?
:lol: :lol: Pi 4 Model B :lol: :lol:
Raspbian Buster with desktop 4.19

User avatar
B.Goode
Posts: 12054
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Program to take pictures of the intruder does not work

Sat May 15, 2021 12:37 pm

ancris00 wrote:
Sat May 15, 2021 9:36 am
Shall I put this line

Code: Select all

 timestamp = datetime.now().isoformat()
inside the loop as well ?

It doesn't need to be 'as well'.

Just inside the loop. Prior to using it to construct the filename. After the wait_for_motion delay is triggered seems a sensible choice.

ancris00
Posts: 135
Joined: Sun Jan 19, 2020 8:56 pm
Location: Miranda de Ebro, Spain
Contact: Website

Re: Program to take pictures of the intruder does not work

Sat May 15, 2021 1:59 pm

It works! thanks
:lol: :lol: Pi 4 Model B :lol: :lol:
Raspbian Buster with desktop 4.19

Return to “Python”