galaxyrider
Posts: 33
Joined: Sat Dec 26, 2015 2:36 pm

Use a PIR to start a video then disable it.

Mon Feb 08, 2016 12:29 pm

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.

ElEscalador
Posts: 856
Joined: Tue Dec 15, 2015 4:55 pm
Location: Detroit, MI USA
Contact: Website

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

Mon Feb 08, 2016 1:35 pm

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).
Robotics tips, hacks, book extras https://youtube.com/practicalrobotics

galaxyrider
Posts: 33
Joined: Sat Dec 26, 2015 2:36 pm

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

Mon Feb 08, 2016 2:02 pm

Thanks. When I get home I'll copy the code here for you to see.

galaxyrider
Posts: 33
Joined: Sat Dec 26, 2015 2:36 pm

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

Mon Feb 08, 2016 6:41 pm

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.

gordon77
Posts: 5272
Joined: Sun Aug 05, 2012 3:12 pm

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

Mon Feb 08, 2016 8:44 pm

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")
        

galaxyrider
Posts: 33
Joined: Sat Dec 26, 2015 2:36 pm

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

Tue Feb 09, 2016 8:14 pm

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.

Return to “Beginners”