Arduino sound?

I need to play a specific, single musical note based on a sensor input. According to the playground, I could pulse a pin at the frequency of the note and generate the sound that way; is this the best way to simply play a note, and how would I interface the Arduino with a simple set of computer speakers? Is a digital pin the only option, or would a USB serial connection be possible/better?

please don't multipost, i think 4 in an afternoon is enough

You could "interface" a speaker via a resistor from a digital pin. Say 1k. Or use one of those piezo sound transducer thingys (I'm not sure what they are called :p)

Have you seen the Tone library? Google Code Archive - Long-term storage for Google Code Project Hosting.

Sorry for the multipost, internet issues. Thanks for the link, very helpful in the software aspect. The page mentions that you can't connect the pin straight to a speaker's audio-in line; what sort of circuit would one use to connect the two?

The page mentions that you can't connect the pin straight to a speaker's audio-in line; what sort of circuit would one use to connect the two?

Most loudspeaker are low impedance, say 8 ohms nominal, and that would draw too much current from an Arduino output pin and could damage the pin. So if you wire a series resistor (200 ohms) from the output pin to one of the speaker pins and ground the other speaker terminal that should keep every thing safe. Depending on the efficiency of the speaker and your desires that may not be loud enough for you application, but good enough to work on the code as you develop the program. In that case you would need some kind of audio amplification module to make it louder. Amplified computer speakers can be easily adapted to use.

Lefty

Lefty

I have some super-loud speakers from an old stereo I took apart. I'm planning on using those once I get my Arduino.

Off topic, but this is kind of funny: I joined this forum when I was considering getting an Arduino, but I still haven't gotten one. It's on my Christmas list (in fact, a family member got one, but I can't get it 'til the 25th). I've already racked over 200 posts without an Arduino :O. All my knowledge is theoretical haha ;D.

The page mentions that you can't connect the pin straight to a speaker's audio-in line; what sort of circuit would one use to connect the two?

Most loudspeaker are low impedance, say 8 ohms nominal, and that would draw too much current from an Arduino output pin and could damage the pin. So if you wire a series resistor (200 ohms) from the output pin to one of the speaker pins and ground the other speaker terminal that should keep every thing safe. Depending on the efficiency of the speaker and your desires that may not be loud enough for you application, but good enough to work on the code as you develop the program. In that case you would need some kind of audio amplification module to make it louder. Amplified computer speakers can be easily adapted to use.

Lefty

So how would I wire it if I have a set of computer speakers with just one line-in plug? Would I need to ground something, or would a 1k-ohm resistor in series keep everything safe?

or would a 1k-ohm resistor in series keep everything safe?

That should work fine.

Lefty