Hi there!
Super newbie here, hoping someone could assist.
I’m hoping to create - in the least amount of parts/easiest way possible a proximity sensor that triggers a sound. I’ve created an installation called ‘the boredom zone’ for kids and what I’m hoping to add is that when they walk over a threshold or past a trigger a voice booms “YOU HAVE ENTERED THE BOREDOM ZONE”. It is very silly.
Hi Jessie,
One way of doing this is based on a chunk of my Borg Cube project
The bits you would need are
- a Raspberry Pico
- a PiicoDev Laser sensor PiicoDev LiPo Expansion Board for Raspberry Pi Pico | Core Electronics Australia
- PiicoDEv expansion board to mount the pico
PiicoDev LiPo Expansion Board for Raspberry Pi Pico | Core Electronics Australia - and a DFRobot MP3 player
DFRobot DFPlayer PRO - A MP3 Player | DFR0768 | Core Electronics Australia
With a bit of code, just aim the laser sensor across the entrance - when it senses a body walking close by - trigger the MP3 player. the MP3 player can drive speakers directly OR you can add an amplifier for MORE VOLUME
Yes there are many other ways to do this, some require other types of sensors and signal converters. E.G. a pressure pad switch, a capacitive sensor field, a simple LDR and voltage divider etc.
And here is a “bit of code” that should do the necessary … Note - to be finally tested with sounds as I am looking for my spare MP3 player (it’s somewhere here, I’m sure …).
The print statements for the distance tests work ok and the play script is a direct copy from the Borg code, so I am pretty confident in the overall operation … but testing needs to be finished.
The main audio track should be the first track in the player, and other sound effects (SFX) could be loaded if you wish.
The durations array holds the run time in seconds + 1 sec of each track to make sure that they run to completion.
There are two Constants near the top of the code - these are the settings for the distance sensor trigger values
The print statements let you know what is happening if the pico is connected to a Raspberry pi / Thonny environment.
(here is the link to the MP3 player doco - shows how to connect it, and load audio, just needs a USB cable and your PC)
##########################
#
# Sound Effects
#
##########################
#
# Murray T
#
##########################
# PiicoDev Libs
from PiicoDev_Unified import sleep_ms # Cross-platform compatible sleep function
from PiicoDev_VL53L1X import PiicoDev_VL53L1X # distance sensor
import random # random fns
from machine import Pin, UART, Timer # Access to the GPIO pins
import sys # sys.exit()
import array
####################################
#
# UART and Sound FX setup
#
uart = UART(0, baudrate=115200, tx=Pin(12), rx=Pin(13)) # NB GPIO12 and GPIO13
#initialise MP3 player
uart.write("AT\r\n") # wakeup
sleep_ms(100)
uart.write("AT+AMP=ON\r\n") # useful for testing w/o external amp
sleep_ms(100) # - just connect a speaker
uart.write("AT+PLAYMODE=3\r\n") # single track and stop
sleep_ms(100)
uart.write("AT+VOL=5\r\n") # single track and stop
sleep_ms(100)
####
#### NEED TO SETUP THE DURATIONS HERE ####
####
# Audio track durations - run time + 1 second
# track no 1 2 3 4 5 6 7 there is NO track 0
durations = [0, 17, 10, 2, 2, 6, 2, 3 ]
####################################
# define PiicoDev objects
distSensor = PiicoDev_VL53L1X() # initialise distance sensor
# definition of trigger distances
MTRIG = 1500 # main trigger
RTRIG = 2500 # random sfx trigger
g_timer = False # true if timer running
#
# timer reset
#
def timerdone(t): # t is required arg in def statement
global g_timer
g_timer = False # allow another Borg message
tim = Timer(-1,mode=Timer.ONE_SHOT, period=10, callback=timerdone)
#
# CORE 0 process
#
def main_thread():
global g_timer
dist = distSensor.read() # read the distance in millimetres
# distance sensor range 0 - 4000 mm (nominal)
# assumption - trigger distance < 1500 mm
# 0 ---1000---1500---2000---2500---3000----inf
# |"BOREDOM ZONE" | (random FX) | silence ....
#
if dist < MTRIG:
print("trigger")
if g_timer == False:
g_timer = True
play = 1 # Track 1 = YOU HAVE ENTERED THE BOREDOM ZONE
# build the play command
c_num = "% s" % play # / itoa()
s = "AT+PLAYNUM=" + c_num + "\r\n" # / concatenate
uart.write(s) # / and send it
# one shot firing after durations[play] seconds to allow MP3 player to finish
tim.init(mode=Timer.ONE_SHOT, period=durations[play]*1000, callback=timerdone)
### Optional random SFX bit
### comment out down to EOC marker if not required
elif dist < RTRIG:
print("rand trig")
if g_timer == False:
g_timer = True
play = random.randint(2,7) # pick a random other track (2 -> 7)
# build the play command
c_num = "% s" % play # / itoa()
s = "AT+PLAYNUM=" + c_num + "\r\n" # / concatenate
uart.write(s) # / and send it
# one shot firing after durations[play] seconds to allow MP3 player to finish
tim.init(mode=Timer.ONE_SHOT, period=durations[play]*1000, callback=timerdone)
### EOC
### end of optional random SFX bit
else:
print("nada")
pass # do nothing
sleep_ms(200)
#####################################
#####################################
## START HERE
#####################################
#####################################
while True:
main_thread()
Hi Jessie
And a friend provided this link to a simple RADAR sensor
Some info here
and a HEAP of info about it here
And a simple code to test it - you could merge in the MP3 Player code instead of the led.on line
from machine import Pin
led = Pin(25, Pin.OUT)
radar = Pin(22, Pin.IN, Pin.PULL_DOWN)
detect = False
while True:
detect = radar.value()
if detect:
led.on()
else:
led.off()
I have tried it - it does give a solid trigger but is interesting to aim, in that it seems to have a wide pickup field.
cheers,
Murray
Hi Jessie,
This is exactly the kind of project I love, electronics doesn’t always have to be serious and intellectual.
@Murray125532 has got a killer solution there, no doubt there are 2 million more ways to achieve the same goal but using what you already have worked out is hard to beat.
… Aaaannnnddd it works
Found the spare MP3 Player, hooked it up … and got sounds!
I setup 2 sounds, reset the trigger distances to something short range (so I didn’t have to stand up at the bench), waved my hand over the sensor, and got the two sounds at the appropriate distances. And got silence when the sensor was detecting the ceiling (way up over the bench), i.e. out of range!
Only used one speaker ( the other one is somewhere away with the Borg ) but the MP3 player can happily run 2 speakers (Left and Right), so you can ‘spread’ the sound around a bit.
(hmmm must find a stereo effect one day…)
cheers
Murray
You can do it with an Arduino. A proximity/SONAR sensor,an SD card+SD card storage board and a speaker with a necessary amplifier circuit.