Shop OBEX P1 Docs P2 Docs Learn Events
Driving a Small Speaker (not a piezo buzzer) from a BS2. — Parallax Forums

Driving a Small Speaker (not a piezo buzzer) from a BS2.

Martin_HMartin_H Posts: 4,051
edited 2012-04-24 19:05 in BASIC Stamp
I recently purchased a small speaker that says it can be driven from an microcontroller pin, but before I plug it into my BS2 I want to do due diligence. The data sheet says that it is impedance is 100 ohms and its rated input power is 0.15 W. My guess using the voltage drop across 100 ohms would be 50 mA, and 0.15 W at 5 volts is 30 mA. Both of these are well above the BS2's 20 mA per pin output. So I'm assuming I need to limit the current consumption.

Does anyone have any pointers on driving a small speaker (not a piezo buzzer) from a stamp? I assume I either add a current limiting resistor, or feed the pin output into a transistor and drive the speaker off that.

Comments

  • GordonMcCombGordonMcComb Posts: 3,366
    edited 2012-03-20 07:59
    Unless you place a constant DC bias across the speaker (not a good idea anyway) the voltage will only be around 2.5V, assuming a 50% duty cycle for the PWM you use to make sound. That still may be too much for a Stamp, so you can further decrease the current with a resistor. That speaker (I'm assuming it's the one from Pololu) is very loud anyway, so a dropping resistor will not affect its output that much. You can start with a 100 ohm resistor and see how that works for you.

    The transistor idea works, too. Just wire it as a switch.

    -- Gordon
  • Martin_HMartin_H Posts: 4,051
    edited 2012-03-20 08:06
    Unless you place a constant DC bias across the speaker (not a good idea anyway) the voltage will only be around 2.5V, assuming a 50% duty cycle for the PWM you use to make sound. That still may be too much for a Stamp, so you can further decrease the current with a resistor. That speaker (I'm assuming it's the one from Pololu) is very loud anyway, so a dropping resistor will not affect its output that much. You can start with a 100 ohm resistor and see how that works for you.

    Thanks Gordon. That is indeed the speaker, so I'll try a 100 ohm and see how it goes. I'm glad to hear it is loud as I wanted something louder than the typical buzzer.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-20 08:27
    Martin,

    Remember that a speaker is an inductive load and, like any inductive load, needs a catch diode across it to protect the switching circuitry from fly-back voltage spikes.

    -Phil
  • Martin_HMartin_H Posts: 4,051
    edited 2012-03-20 08:58
    Phil, thanks for the warning about that gotcha. I will definitely add a diode.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-03-20 09:15
    Consider using a capacitor in series with the speaker instead of a resistor. Something on the order of 100µF to 470µF with the (+) to the Stamp and the (-) to the speaker. The capacitor removes the DC component that comes along with the single-ended PWM that the Stamp uses to generate audio. The DC component is not good for the speaker. The capacitor also avoids the danger that the pin might be left high and source a continuous DC current through the speaker and the output pin. If you use a capacitor, you can probably drive the 100Ω speaker without an additional resistor. The average current in the audio is unlikely to exceed the capability of the pin, which itself has an output resistance of around 40 ohms. Under those conditions there would not be danger of inductive kickback from small speaker like that, and what there is could be caught by the Stamp's own substrate diodes.

    The capacitor does cut down on the low frequency response, but that speaker drops off pretty fast below 1kHz anyway.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-03-20 09:34
    Tracy, thanks. I've seen capacitors in schematics with speakers but didn't know why there were there. Filtering the DC component makes sense, so I'll stop by Radio Shack on the way home tonight. I may try this a few different ways to see how it works.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-20 09:48
    One thing to note: using the cap requires an output that's symmetrically driven both high and low, such as that from a micro like the BASIC Stamp. It will not work with a single-transistor open-collector driver. You would have to construct a half-bridge amplifier to get the same effect with transistors.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-03-20 10:44
    Most small audio amplifier chips now use "bridge tied load", so no capacitor is necessary. The capacitor is big and affects the frequency response. Also, with a bridge, there is much less of an audible click when you first turn it on, and off. You could drive one of those amplifier chips from a stamp pin and tie the speaker to the bridge output. Most of them seem to be in surface mount packages for your cell phone, but one in a DIP8 package is the Philips TDA7052A (Mouser).

    There was a design idea in the 3/1 issue of EDN, an H-bridge driver specifically for a piezo speaker. A rather risky design in terms of protection from incorrect drive, but a nice simple circuit. The Micrel MIC4426 series that Phil brought to my attention also presents a neat option for bridge drive with voltages greater than the MCU Vdd. The PWM output from FREQOUT on the Stamp has a lot of high frequency switching going on, so you have to take that into consideration when using any external circuit.
  • Martin_HMartin_H Posts: 4,051
    edited 2012-04-23 18:01
    Thanks for all the suggestions. In case anyone is curious I ended up using a 220 uF capacitor with a 220 ohm resistor in series with the speaker. I probably could have used a smaller resistor value, but the Pololu speaker is loud. If I use it outside I might go with a 100 ohm resistor.
  • ercoerco Posts: 20,256
    edited 2012-04-24 16:06
    Just brainstorming here. Instead of a big cap and a resistor, couldn't you just use a much smaller cap value to limit volume? Put impedance to work for you. Dunno, 1uF is probably still too big, so probably down in the large microfarad range. Might affect frequency response, but I'm trying to stop you from blowing half a penny for a resistor.

    Half a penny saved is half a penny earned. :)
  • Martin_HMartin_H Posts: 4,051
    edited 2012-04-24 19:05
    Interesting idea. If I had a scope I could see how the waveform changed based upon capacitor size. I imagine that a smaller capacitor would produce a smaller amplitude since it can store less energy. But analog circuits have always seemed like a dark art to me. Given me logic gates and flip flops any day of the week.
Sign In or Register to comment.