# Jon Walker, Mar 2025.
# This is the Pico PIR mp3 Trigger.py utilizing a PIR, a DFPlayer Mini Mp3 Player and a Raspbery Pi Pico.
# The mp3 pin from the Pico to pin IO_2 on the DFPlayer is set to HIGH, the mp3 player is triggered to
# play the single mp3 named 0001.mp3 by pulling the IO_2 pin to LOW for .25 sec, momentarily grounding the pin
#(Simulates a short press to play next).
# This bypasses the need for Serial Communication to control the player.
from machine import Pin, Timer #importing classes
from time import sleep #Import sleep from time class
# Set up your pins.
mp3 = Pin(14, Pin.OUT, value=1) # Sets the mp3 pin to HIGH. Pin.PULL_UP
led = Pin(16, Pin.OUT, Pin.PULL_DOWN) # Sets the led pin to 0.0v.
pir = Pin(17, Pin.IN, Pin.PULL_DOWN) # Sets the PIR pin to receive signal input from the PIR sensor.
strobe = Pin(1, Pin.OUT, Pin.PULL_DOWN) # Sets the Strobe relay pin as an output to 0.0v.
solenoid = Pin(2, Pin.OUT, Pin.PULL_DOWN) # Sets the Solenoid relay pin as an output to 0.0v.
# Add more relays as needed.
print('Starting up the PIR Module')
sleep(1)
print('Ready')
while True: # This loop checks the status of the pir pin every .5 sec.
if pir.value() == 1:
print('Motion Detected')
mp3.low()
print("mp3 Playing")
sleep(1) # sleep(.25) for actual DFPlayer, sleep(1) for testing with led
mp3.high()
led.high()
strobe.high()
solenoid.high()
sleep(5) # Set delay for however many seconds your mp3 plays, ex: my Zombie mp3 is sleep(11) sec.
print("mp3 Stopped")
led.low()
strobe.low()
solenoid.low()
print('Motion stopped!')
sleep(20) # sleep for 20 seconds to prevent prop from being re-triggered by guests.
sleep(.5)