Duino audio trigger from multiple sensors, 4channel output

Hi all,

First time posting, very new to the Arduino environment. I have to say I love what I've been doing so far, testing different instructables and seeing what this little board can do. I have a Mega and Uno, and I need help with a project I would like to make. I've been looking at different ways to approach this, and need some guidance with my installation. I am an absolute noobie when it comes to coding, so I would appreciate some help with that and with what tools to use. I have built a laser trip-wire alarm that is self calibrating, and would like to base my project on that. I used this tutorial.

I would like to make my project a bit bigger, and not have to use a computer running software (like processing or other programs, IF POSSIBLE). I want to basically make the project a bit bigger. My hopes would be this:

When the Arduino turns on, all the sensors calibrate to the ambient lighting, and signal they are done. Then the Arduino turns on a relay, which turns on the lasers, and it calibrates the LDR sensors (photo resistor) with the lasers on. Now, whenever one of the lasers is tripped (the LDR value goes to ambient), the Arduino triggers a sound file. Each sensor has its own unique sound file assigned to it, and these play through one of four (mono) sound channels. The sound files would be roughly a 10 seconds long. When the sound stopped playing, the sensor could be tripped again and would play the sound again. These would have to play at the same time if more then one LDR sensor would be tripped.

My necessities would be:
-using 4 audio channel output
-using the Arduino to relay the lasers on
-using some sort of self calibrating code (that would allow for resetting a few times a day)

I have several Raspberry Pi's available to me, if they would be necessary to play the audio, but I have never held one in my hand so I have zero experience with them. I would also really like to not have to use a computer, because I want the whole thing to be as small as possible. But of course I understand that because of the 4 channel audio it might not be possible.
A further step in this project would be for the Arduino to have some sort of switch that could choose a 'audio bank' to play the sounds from, basically choosing one of four different folders of audio to play back when the LDR sensors are tripped).

Any sort of guidance is would be really helpful, I think I am a fast learner, but on the other hand two weeks ago I didn't know what a resistor was for... :fearful:

Thanks in advance for any help,

Tommy Jay

The calibration should be done several times per second. Have the lasers cycle on and off at 10-100Hz. Then your code should look for the differences synchronised with that frequency. Infrared remotes, like on your TV, do this at about 38kHz, but they’re sending more data and they have specialised chips at both ends.

MP3 shields are available that let the Arduino select a file from an SD card. Your choice of sounds is therefore unlimited. They probably cost about the same as a Rasberry, so you have a choice to make.

(Don’t use a relay at 100Hz. It will wear out quickly.)

Hi Morgan,
Thanks for the fast reply.

The calibration should be done several times per second. Have the lasers cycle on and off at 10-100Hz. Then your code should look for the differences synchronised with that frequency.

I have absolutely no idea how to do this. Even the self calibrating tripwire has a bit too much code for me to understand. I think that because I want this to run for several hours a day, it would be good for it to maybe calibrate every once in a while, but it will probably run in a closed room with no windows. But good idea, calibrating it maybe once every 10 minutes. I still have no idea how to do this though :frowning:

Also, The 'several times per second' thing probably wouldn't be viable for me. I plan on putting a hazer (like a smoke machine) into the room and having a very small amount of smoke there, so that the lasers will be visible.

MP3 shields are available that let the Arduino select a file from an SD card. Your choice of sounds is therefore unlimited. They probably cost about the same as a Rasberry, so you have a choice to make.

As for the cost, I do have the opportunity to borrow up to 10 Pi's for no cost, but I don't know how to use them. I was thinking that because of the 4 mono channels that I would need two Pi's and separate the stereo connection. But if there is an easier way, like buying an SD/MP3/Wave shield and just plopping it onto my Arduino (if it works with the Mega) then that could also be a possibility.

I also bought several Grove Relay v1.1 relay switches for the Arduino, but I bought them at a time I didn't understand any of this, and I'm now finding out that they are pretty useless without some shield that I need. I couldn't find any info on google about these specifically and although I tried to use them on a circuit and just experimented with the pin layout, I didn't get it to work... I wanted to use this to turn on my separate 'laser circuit' but I guess I'll have to find another relay that works standalone.

Interesting that you're doing lasers and tripwires, I play with that a little bit in my current project too.

It largely depends on the environment, but in my indoor installation I don't need any self-calibration. Even with sun shining through the windows the contrast of the ambient light and my laser is producing values different enough every time, don't worry about that, especially in the beginning.

As for the relays – unless you're running the tripwire across 50 meters, you probably don't need a laser powerful enough that should require a relay. Arduino's built-in 5V power with some resistors should be plenty for a small laser (I'm actually powering mine using a digital output pin since it switches on and off quickly all the time).

Personally I don't know much about the MP3 shields or how to use them, but a possible simple solution would be running the sound files through Pure Data, which runs well on a Raspberry Pi (which is basically a regular computer once set up).

Feel free to stop by the BA studio to see my mighty lazers in action!

Hey ddx32,

Thanks for the reply! I guess you have more experience with the lasers and are playing around with them and the Arduino environment for longer then me, so I'm gonna take your word for it. When I followed keithkay's intractable on building the tripwire, there were many very basic tutorials on the tripwire, that were nothing more then a buzzer and a LDR, and I wanted to step it up a bit. The calibration seemed like something important and valuable, so I didn't want to skip the step just to make my project medieval simple. But if you're playing with lasers and say that it doesn't really matter, then I guess it doesn't really matter :slight_smile:

As for the relays, I wanted to use them mainly because I already have them, and don't know what to do with them. But you're right, I use my laser at 3.3V, so I guess using Arduino's built in digital pins would be a step forward, and I could possibly even use that as an advantage to set the lasers to make some on/off animation and play around with them independently. Although, my plan is for them to run about 20m, maybe slightly more. Guess i'll need good wires.

As for the audio, I guess right now that seems to be my biggest challenge. Is there a way to hook up TWO RasPi's so that I can use 2x stereo output? Because it seems like an overhaul to plug some big usb sound card into a RasPi in order to get 4 mono channels out. And I've thought about the pd connection before, but is it functional? Any experience with sending multiple Arduino commands to the RasPi to trigger soundfiles in pd?


In the past days I have taken the input from this forum and from other sources that I talked to.
So, I will try to start from the beginning on my 0.2 version.

My Arduino project should have about 20 (possibly more) laser diodes, they are a small 5mW red laser diode that uses 3.3-5V. These are all pointed, on the other side of the room, at photo-resistors (LDR), and each laser can be independently turned on and off, and each photo resistor is an independent input (probably using a 4051 mux/demux chip). Apart from these, there is also one input device, which I imagine to look like a spin wheel, with 4 different options. The arrow can be turned to the four different options, each being 90 degrees of the square. If there would be a more ‘modern/convenient/stylized way’ to do this, I would change it in the future. But for now i imagine this arrow that I can turn.

The project requires four mono outputs, or 2 stereo channel outputs. Because of this, I would like to somehow connect the Arduino and allow it to communicate with a raspberry pi, or two raspberry pi’s. When one of the lasers is tripped, and a signal is sent from the Arduino to the pi, and the pi plays a sound. if multiple sensors are tripped, then multiple sounds are played. Each LDR sensor has one sound assigned to it, which plays through a predefined mono output. this means that if there would be exactly 20 sensors, then there would be sounds assigned to each speaker.

It is very important that each of the sensors has the sound that it plays whenever it is triggered and only plays through a predefined sound channel. My friend advised me that this part might be simple to program by using Pure Data (pd) which can run on linux, and that would run on the Raspberry Pi. From my understanding it would be simple because it is a node visual structure where I can link each of the LDR sensor inputs to play a specific sound and output them in their correct speaker.

One place where it gets interesting/complicated, is that the input device that I mentioned earlier determines which ‘bank’ of audio files the sensors trigger. I would like it if there were 4 predefined audio file banks (or better said folders). The way this would work, is that the spinning arrow determines which bank of audio files are played. To better explain, it could be that on one option, whenever a laser is tripped a you can hear a number being read. if you turn the arrow, then any time a sensor is tripped a letter can be heard. And when you turn it again, you can hear a color, and so on. The point is that in a very basic understanding of the matter, i could say that when the wheel is turned to position 1, the Arduino sends a command to the RasPi to ‘launch file 1’, which is a pure data file with one layout. if the arrow is turned to a different position, then the Arduino sends the RasPi a command to ‘launch file 2’, which would close the first one and open a second layout with different files. This is my very basic example of how I would do it, but I am sure that there is some magical code that makes it work better. Maybe PureData isn’t the right way to go, that too is only an idea.

Lastly, and this really can be a final touch on the cake, since now all of the lasers are independent outputs of the Arduino and can each be turned on or off, I would love it if they could be programmed to have some animation, like a very basic laser show, just some synchronized turning off and on and flashing, maybe something that lasts 5 seconds and happens on boot and every time the sound bank is changed. I think this would be quite easy to accomplish and can be left as the final step…

Thanks for any input or ideas,

As time passes and I put more thought into the user interface of the 'switching though different audio banks' spindle/wheel/arrow mechanism, I realized I would wish to make an ideal revision. This would completely remove user interaction as far as choosing and inputting, and it would go as follows, hopefully simplifying the code:

Instead of the user choosing which bank the audio is currently played back from, the audio bank changed automatically and autonomously every 10 minutes. When it does, the lasers (as they are all individual digital outputs) flash in a sequence to symbolize the change. Instead of a wheel, there is only 4 lights that signify which bank is being used. Each light symbolizes one of the audio banks, and the active bank light is light up. This should best be done with a short (20 cm) LED strip; it could probably be done with a digital output and a relay is not necessary.