Have you ever had your music cranked up at work and didn't realize someone was trying to talk to you. Even worse, have you ever wanted to sleep at work, but didn't have a good way to wake up if someone (like your boss) was about to come into your cubicle. I have. To solve these problems I invented the Arduino based SoundSwitcher.
Basically this uses 6 transistors to switch between a sound source (in my case an iPod) and Ladyada's Wave shield letting you know what's going on. You can then connect the Arduino to whatever type of sensor you like. For example, mine's connected to a Parallax Ping ultrasonic range finder, microphone, doorbell button, and computer (alerts on a new email). You could go further by connecting a photo resistor to detect when your cell phone is ringing (the screen lights up), or a Parallax CH4 sensor so you can get an early warning of raising methane levels in your cubicle because your cubicle mate had too much cabbage at lunch. Anyway, most of you probably don't have that problem (wish I didn't).
Besides what the project actually does, it also gives instructions on converting text to a wav file and transfering files to the SD card on the Arduino over Serial. Hopefully these can be usefull to others in their projects.
NOTE: I'm pretty new to all this stuff, so there's no guarantee I'm doing things right. This is the first project I've ever designed with transistors, so I may be missing some caps and diodes somewhere . . . If anyone has any advice I'd be happy to hear it and incorporate it.
Step 1: Parts
1- Wave Shield (Ladyada)
6 - 2n3904 transistors
6 - 330 Ohm resistors
6 - 22 Ohm resistors
2 - 10k Ohm resistors (pullups for buttons)
2 - buttons
2 - Stereo male headphone connectors
1 - female stereo headphone connector
Whatever sensors you want, I did
1 - Microphone
1 - Parallax Ping Ultrasonic Range Finder
1 - Computer running a Ruby script that checks email and connect to the Arduino over serial
Step 2: Transistors
Transistors are mainly used to amplify things or as switches. In this case I'm using the transistors as a switch. When I turn the Arduino pin high then the transistor allows sound to come from the device connected to them to my earphones. Three transistors on each side allow me to switch the ground, and left and right stereo channels for each sound source. I experimented with several resistors and settled on these. The transistors don't get hot and the resistance from the transistor itself is very low when the Arduino pin connected to it is high. This is important so I can get good unmuffled sound.
As you can see in the schematic in the next step the transistors are each connected so that the base goes to the Arduino pin to control it (with a resistor between them). The emitter is connect both to ground (with a resistor) and the sound input. The collector is connected to sound output to the headphones.
Here's a good webpage on using transistors as switches http://www.rason.org/Projects/transwit/transwit.htm
Step 3: Connect It All Together
The schematic is pretty simple. One thing to keep in mind is that the wave shield uses a bunch of pins on the Arduino, so stay away from those (I filled them in with solder on my board). I used pins 8 and 9 for transistors (8 plays wave shield, 9 plays external sound source). Analog pin 0 was used for the microphone (it doesn't work very well though, I'm working on this). Analog pin 1 is used for "Ignore" button. When this button is pushed all sensors are ignored for a predefined amount of time. Analog pin 2 is a "doorbell". There are still some free pins for other things. I'm planning on adding a photo resistor that I put up against a cell phone screen to detect when it's ringing on Analog pin 3. I'll add that here once I try it out.
Step 4: Sensors
Right now I'm using the following "sensors" (probably inputs is more accurate) to trigger events:
-Push button for doorbell - This is pretty simple, makes it so someone can push a button and it will play a sound through your earphones letting you know someone's around. The button I used closed the circuit by default, and opened the circuit when the button was pushed (I just had these around). Don't forget pullup resistors (generally a 10k Ohm resistor that goes to the Arduino pin side of the wire to help give a good high signal when the circuit is open). Mine is connected to Arduino Analog Pin 2.
-Parallax Ping Ultrasonic range finder - Let's me know when someone is close by (i.e. someone is about to enter your cubicle). Mine is connected to Arduino Pin 6 (on the white wire of the sensor). The red wire of the sensor goes to 5 volts and the black wire goes to ground.
-Microphone - This is meant to detect when someone is talking to you. You know those guys who don't realize you have headphones on and start talking. I'm still working this one out, it looks like I need a preamp to get good reading with the microphone I got from sparkfun. An interesting next step would be to record a few seconds of the sound to a file on the wave shield and then play it so you know if it's something you care about before you turn your music off.
-Computer - Right now this uses a Ruby script to check for new email and sends a signal to the serial port where the Arduino is to let it know a new email has been received. You could obviously do a lot more with this. Basically anything the computer could alert on, you could have it alert on through your headphones. It would be cool if I could have the computer automatically generate a wave file using some of the AT&T voices, then send it over to the Arduino via serial. That one's a ways out there though.
-Cell phone ringing sensor - I used a photocell from Radio Shack (The Shack) for this. I connected it to analog pin 4 then to 5 volts. You also need to do a 10k Ohm resistor from the side that connects to pin 4 on the Arduino to ground (otherwise the signal won't change). For my phone if the photocell I'm using goes above 400 on the analog read on the Arduino, then the screen is lit up.
Other Potential Sensors
-Desk Phone ringing sensor - Maybe the microphone could pick this up. Depending on the phone there's probably several ways to do that. I'll have to think about this some more to see if I can come up with a general purpose solution.
-Laser and a photo resistor - You could point a laser pointer across your cubicle opening to a photo resistor. When the light is broken because someone walks into your cubicle you could sound an alert.
-CH4 gas detector - Detect raising methane levels in your cubicle. This can help serve as an early warning system against gas passed nearby.
Step 5: Command Line Text to Speech
Step 7: Code
I've attached my Arduino sketch. It has a lot of comments in it to help. It basically keeps checking all the inputs, if one of them fires, then it switches the sound the the Wave Shield and plays the wav file associated with that alert.
Step 8: Run the Programs
Step 9: Video of Finished Product
Here's the sound switcher at work