small speaker/amp kit?

I want to attach a speaker to my microcontroller to generate bleeps and blurps and so on. But I've discovered (to no surprise) that if I connect my speaker directly to the output pin of the MCU, the resulting volume is very low.

So I need a little audio amplifier. I have a circuit for this (thanks again to David Cook), but I'm wondering whether there is a kit (or pre-assembled gizmo) out there that takes care of this for me -- something with a small speaker and the circuitry needed to drive it directly from a 3.3V (or 5V) control signal, ground, and power line. No sense re-inventing the wheel if I can avoid it...

Thanks,

- Joe

Reply to
Joe Strout
Loading thread data ...

You can always use the venerable 386 amp chip, but you'd be reinventing the wheel and the sound still wouldn't be any good. *Better sound comes from speakers in an enclosure.* So, buy some $10 portable amplified speakers. Wire your power supply to where the batteries are supposed to go. Clip off the mini plug and solder directly to your circuit. You may find a 386, wired in gain-of-50 configuration, to be a perfect pre-amp. Use DC coupling between your circuit and the amp/preamp (a small 0.1 disc cap).

Here's one to start you off, and it's only $5. Such a deal.

formatting link

-- Gordon

Reply to
Gordon McComb

True, but I have no room for an enclosure in this bot, nor do I care much about the quality of the sound. I just need it to be audible.

Hmm, that's an interesting idea. I'll give that some thought.

Oi. If I have to build a 386 amp circuit, I'd much rather just connect that to the 1" speaker I already have.

That *is* a good deal -- even if I don't end up using it in a robot, it's exactly what I've been looking for for listening to podcasts on my Palm in the car. Thanks for pointing it out!

Best,

- Joe

Reply to
Joe Strout

Hi Joe. If your speaker is a typical 8-ohm jobber, the mcu will not drive it, since the typical output resistance of a CMOS mcu pin is on the order of 150 to 200-ohms or so. OTOH, you may be able to find a

150-ohm speaker.

Also, the mcu will directly drive a common piezo tranducer [external drive type], usually with adequate volume, and/or a magnetic transducer [20-mA type]. In the latter case, it should be wired through a series 10-uF or so electrolytic cap, and have a diode [wired upsidedown] in parallel with the transducer coil to squelch inductive spikes.

You will get less volume if the mcu is 3.3v. Also, if you're using the Armexpress for this, you will get **significantly** better volume if you use a stream of square pulses to the transducer, rather by using the ARMbasic FREQOUT function.

See also ...

formatting link

Reply to
dan michaels

That's interesting. It actually did drive it, just not very loud. (And on Dennis Clark's suggestion, I tried putting about 200 ohms in series with it, and it still worked, but was even softer.)

The speaker I'm using has no useful markings on it, but I don't think it's a piezo, because its backside is strongly magnetic (suggests a regular speaker cone, no?).

That sounds good; I really like simple for this. Something like one of these?

formatting link

Why is that? Not that I don't believe you, I'm just curious. FREQOUT is supposed to generate sine waves, which I'd expect to sound better than square waves. If it's actually able to generate sine waves on a digital output pin... the docs are a bit vague on that, and I haven't got an oscilloscope.

That's very helpful, thank you! But if I can accomplish my modest goal with a directly connected piezo transducer, I'll be all the happier.

Thanks,

- Joe

Reply to
Joe Strout

Wrong direction. Had you driven it with an npn inverter you'd be farther ahead. But just take your DMM and measure the dc resistance to get an idea what your speaker is.

Yeah, without looking. I buy kobitones, and use both piezo and magnetic as indicated last time..

They "sound" better than squarewaves, but that doesn't mean they have as much energy, ie volume.

I didn't measure the FREQOUT signal on my scope, but just tried it both ways with the Armexpress.

Usually they generate such sweet-sounding "sinewaves" by using PWM [squarewaves] at a high enough frequency the speaker mechanics will filter out the PWM fundamental, and then rapidly vary the PWM duty- cycle to produce a "sinewave". I expect if you were to look at the output using a spectrum analyzer, you'd see most of the actual energy is at the PWM fundamental frequency, and is therefore wasted, and much less energy is at the sinewave frequency peak.

Reply to
dan michaels

Reply to
castvee8

In that case you want to use a piezo speaker, though at 3.3 volts you can't expect much. Drive it with as high a voltage as you can; you can use the NPN transistor to level convert from 3.3 to 5 volts. A PM speaker won't move much volume of air you need unless it's in an enclosure. One can't change the laws of physics.

-- Gordon

Reply to
Gordon McComb

Sounds like something Scotty would say.

OK, a transistor circuit would be a good exercise for me. But, for the sake of argument, would an optoisolator work? Suppose I connect the

3.3V MCU output to the "control" side of the optoisolator, and run the unregulated 9V (motor) supply through the "controlled" side (making up terms here since I don't know the proper ones), and connect that to my speaker?

It seems like an optoisolator should be able to operate even at thousands of Hz, and they have the advantages of (1) helping to keep my noisy power line separated from my MCU, and (2) being much easier for me to understand. :)

Thanks,

- Joe

Reply to
Joe Strout

An optoisolator has as its output an open collector transistor, so the overall level-shifting effect is about the same. However, choose wisely (as the knight said to Indiana Jones); some/most opto-isolators are meant to be driven with digital signals, not analog. The phototransistor is not biased linearly.

Many of the old Forrest Mims Radio Shack books show transistor-based level shifting circuits. They are about the easiest things to wire up, and no more involved (actually less so) than an opto-isolator.

-- Gordon

Reply to
Gordon McComb

Good point. I'm still not clear on whether the FREQOUT command on the ARMmite actually generates a real sine wave... the docs claim it's so, but everywhere else in the same docs, these pins are described as digital outputs.

But Don has suggested that I'll get better results using PWM (square-wave) output anyway, and that should work fine with an optoisolator, if I understand correctly.

I'm sure that's true when you understand them, or are working from a schematic made by someone who does. I'm still at the "which of these is the collector, and what's that do again?" stage. But you've encouraged me to give it a try -- it'll be good to have a specific goal for delving (not for the first time!) into transistors.

Thanks again,

- Joe

Reply to
Joe Strout

Well, I'll wrap up this thread with a success story: I took a simple

1-transistor circuit (from David Cook's introduction to motor drivers!) and used it to drive my speaker (switching the motor supply). After much fiddling and fixing of stupid mistakes, it worked! The sound from the speaker isn't what you'd call loud, but it's certainly audible enough for my purposes. (And the motor batteries are rather low -- about 7.5 volts, while they were 9.6V when full, so I imagine it'll be louder on a full charge.)

Incidentally, I also tried it on the piezo element I had on hand. This turns out to not be a speaker, I believe -- it just emits a high-pitched (and obnoxiously loud) tone. Probably meant as an alarm element or some such.

Cheers,

- Joe

Reply to
Joe Strout

There is no such thing as a "real" sinewave coming out of a microcontroller chip, unless it has a DAC built-in, and I don't think any mcus have this. So, they will use either the PWM method I mentioned before, or possibly DDS ...

formatting link
Don Lancaster also used to talk about somethign similar in magic sinewaves ...

formatting link

Reply to
dan michaels

Sounds like it is an "internal drive" type, which means it generates a fixed tone. Sonalarms were originally built to emit a shriek loud enough to get you out of bed in the middle of the night from the other room. Driving a typical "external-drive" type piezo with a 5v mcu pin will generally not emit an excessively loud tone.

Reply to
dan michaels

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.