Raspberry Pi - PIR Automated 10 Minute Mp3 Stream Player
by wilsnico in Circuits > Raspberry Pi
2 Views, 0 Favorites, 0 Comments
Raspberry Pi - PIR Automated 10 Minute Mp3 Stream Player

Automatic PIR internet mp3 stream player that is programmable to stop after a while. Ideal for use in places such as the toilet
Supplies
PAM8403 Audio 2x3W Mini Digital Power Amplifier Board
2pcs Mini Speaker 3W
PIR Motion Sensor
Info
Start script :
sudo python3 pir.py
Change: URL = " " with Your mp3 stream address.
Change: "time.sleep(600)" if you want a shorter or longer playing time.
Data cable PIR on Pin 4.
Code
import time
import vlc
from gpiozero import MotionSensor
pin = 4
url = " "
pir = MotionSensor(pin)
#define VLC instance
instance = vlc.Instance('--input-repeat=-1', '--fullscreen')
#Define VLC player
player=instance.media_player_new()
#Define VLC media
media=instance.media_new(url)
#Set player media
player.set_media(media)
while True:
print("waiting...")
pir.wait_for_motion()
player.play()
time.sleep(600)
player.stop()
time.sleep(1)