Page 1 of 1

Use a PIR to start a video then disable it.

Posted: Mon Feb 08, 2016 12:29 pm
by galaxyrider
Hello. I am doing a project with my grand children where a PIR is used to start a video. When that has stopped they push a button to start another video. The problem I'm having is that all the programs I've found to use the PIR have a while loop so the video keeps playing. Is there a command to stop it or is there another program that will just detect it once? Thanks.

Re: Use a PIR to start a video then disable it.

Posted: Mon Feb 08, 2016 1:35 pm
by ElEscalador
What is the code for the while loop? I'd think you could A. Put a command in your while lop to stop recording when pir goes inactive and B. Nest that start stop stuff within a for loop that numerically increments to change the name of the file every iteration(so you don't overwrite the last file).

Re: Use a PIR to start a video then disable it.

Posted: Mon Feb 08, 2016 2:02 pm
by galaxyrider
Thanks. When I get home I'll copy the code here for you to see.

Re: Use a PIR to start a video then disable it.

Posted: Mon Feb 08, 2016 6:41 pm
by galaxyrider
Hello. This is the code I am using. It does start the video as planned but I cannot stop the PIR detecting movement.

Code: Select all

import os
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(4, GPIO.IN)
while True:
    if GPIO.input(4):
        os.system("omxplayer -o hdmi /home/pi/output.mp4")

Thanks.

Re: Use a PIR to start a video then disable it.

Posted: Mon Feb 08, 2016 8:44 pm
by gordon77

Code: Select all

import os
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)

GPIO.setup(4, GPIO.IN)
GPIO.setup(7, GPIO.IN)
runvideo = 0
while runvideo ==0:
    if GPIO.input(4):
        os.system("omxplayer -o hdmi /home/pi/output.mp4")
        runvideo = 1

while True:
    if GPIO.input(7):
        os.system("omxplayer -o hdmi /home/pi/another.mp4")
        

Re: Use a PIR to start a video then disable it.

Posted: Tue Feb 09, 2016 8:14 pm
by galaxyrider
Thank you very much for your help. I would never of got the PIR sorted without your help. I played around with the second bit of the code so that a button push starts a second video. It was a code from CamJam EduKit that I'd modified. This is a great way to learn even though it can be a bit frustrating sometimes. It's good to know that there are so many people out there to help when it does get frustrating.