Introduction: Sound Switcher
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- Photocell
1 - Computer running a Ruby script that checks email and connect to the Arduino over serial
Step 2: Transistors
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
Step 4: Sensors
-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
Here's a little utility I wrote really quick to covert text to speech. It's written in C# with the free Visual C# 2008 Express Edition . You'll probably need .Net 3.5 to run this. The code is included, but if you just want the exe you can get it in CommandLineText2Speech/CommandLineText2Speech/bin/Release in the zip file. To get the tool working you can just open up a command prompt, navigate to the directory where you put the exe, and type CommandLineText2Speech.exe. It will output this:
Usage:
To list installed voices:
CommandLineText2Speech.exe whatvoices
To convert text to a wav:
CommandLineText2Speech.exe [voice] [rate - default 0 (-10 to 10)] [volume - default 80 (0 to 100)] "[text to convert]" [output file]
In other words you'll probably want to first run:
CommandLineText2Speech.exe whatvoices
This will list out what voices you have installed on your computer. You'll need the name of a voice to run the tool. The voices that come with Windows aren't great, AT&T has some that are pretty good. Next to convert text to a wav file do this
CommandLineText2Speech.exe "Microsoft Sam" 0 80 "This is a test" test.wav
Here's what it all means:
"Microsoft Sam" - the voice, this is one that comes with Windows, you have to put it in quotes since there's a space
0 - Normal Speed (can go from -10 to 10)
80 - Normal Volume (can go from 0 to 100)
"This is a test" - The text that will be turned into a wav file
test.wav - what the wav file will be called
Attachments
Step 6:
The attached Ruby code does the following checks to see if there's new email and if there is it transfers it to the Arduino via the USB to Serial interface built into the Arduino. I've had problems with doing high speed connections over Serial (likely the size of the buffer). The settings for the file are all at the top of the file. This uses my C# program to create a wav file. I should probably convert this all to one language, I'm a big fan of Ruby, but it didn't look like it could create the wav from text very easily so I wrote the little C# app.
You'll also need the ruby serial gem, I've included that as well. To install it (after you've installed Ruby) type "gem install win32-serial-0.5.1-x86-mswin32-60.gem" in the command prompt of the directory where you download the gem to. That's all you should need for this program to work.
Step 7: Code
Attachments
Step 8: Run the Programs
1. Install Wave Shield on Arduino
2. Connect Arduino to Computer (or use XBee) -- I'm assuming you already have the firmware installed
3. Run the Ruby checkEmail.rb script
4. Enjoy your music, the Arduino will interrupt you when it needs to read your email or when it senses something in your surrondings.