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- Arduino
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

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


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:

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

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

 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

Ok, now you have all the parts.  To get this working correctly you need to 

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.

Step 9: Video of Finished Product

Here's the sound switcher at work
Wow, this is a really cool project with a lot of potential uses! I'm surprised this wasn't featured at one point. I think it might be because the circuits look a little messy and complicated. If you redid the pictures and breadboard and simplified the construction a bit, I think this would be a really popular instructable. Maybe putting it in a final, compact, more practical enclosure would help. Try using a program called Fritzing to make nice-looking breadboard layout illustrations.
I have some 5 v speakers, but i believe the current flowing through the circuit is too low. how did you get the speakers to be so loud?
what format is your schematic in?
rename .tmp to pde
I want to build one of these that uses an IR sensor to switch from one speaker to another.. But this looks like such an intimidating project to take on. Im not very experienced with constructing such projects. am i going to need a soldering iron for this project as well?<br>
&nbsp;Well, let's see<br /> <br /> Arduino $30<br /> Wave Shield $22<br /> 6 Transistors - 60 cents<br /> then probably $1to $2 worth of transistors<br /> I'm guessing the stereo plugs are a couple of dollars a piece, I used parts from broken electronics for mine.<br />
What was your budget?<br />

About This Instructable




More by davewking:Egg-bot Creations and Tips Question Box Puzzle "Up" Gingerbread house 
Add instructable to: