Pages: [1]   Go Down
Author Topic: Driving a speaker with an Arduino pin...  (Read 608 times)
0 Members and 1 Guest are viewing this topic.
Valencia, Spain
Online Online
Faraday Member
**
Karma: 118
Posts: 4536
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I want to drive a little speaker with an Arduino pin, is there anything I need to worry about?

I assume I need some sort of limiting resistor, how would I calculate the value?

The 'speaker' is actually from a headphone. A quick test shows it makes quite a loud beep when driven by an Arduino pin.

I measured the resistance as 40 Ohms with my multimeter (although that might not mean much on a coil).
Logged

No, I don't answer questions sent in private messages...

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 505
Posts: 31332
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Make the resistor keep the total current below 40mA and couple it with a capacitor about 1uF non polerised.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sounds very similar to common "magnetic" transducers used in place of piezos, eg
http://www.sparkfun.com/datasheets/Components/CEM-1203.pdf

They show a driver ckt there, but as GM says, you can probably use an Arduino pin
directly. I've used these quite a lot on PIC I/O pins, connected via a 10-uF cap, and
reverse diode across the transducer pins. No series-R.

Since they are "coils", if you use an NPN inverter as shown in the d/s, you need to
be certain the signal never sits high constantly, or else you'll be driving a continuous
current through the device - I also use that same ckt, but with a 10uF cap driving
the NPN base.

Logged

0
Offline Offline
Shannon Member
****
Karma: 159
Posts: 10409
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

150 ohms or above will protect the Arduino pin in most circumstances - limits current to 33mA which is
just within spec.

And the capacitor mentioned (which can be higher in value for more bass response BTW) prevents DC
offset current through the speaker which will distort the cone's resting position.
Logged

[ I won't respond to messages, use the forum please ]

Valencia, Spain
Online Online
Faraday Member
**
Karma: 118
Posts: 4536
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One thing I don't get...

Ideally a speaker should be driven backwards as well as forwards (ie. negative voltage across it) so the other wire on the speaker should really be at 2.5V.

Is that possible with a couple of components? Would it make much difference to sound quality? (I might try playing back an audio sample on it to see how it sounds)
Logged

No, I don't answer questions sent in private messages...

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
   You might be better off using an op-amp as a buffer, haven't tried any of the op-amp headphone driver circuits yet, but keep meaning to.

Duane B
Logged


the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The simple ckts described are good for "buzzing", not for audio quality. If you
want the latter, the minimum cktry will be an LM386 amplifier [not the best sound
quality], being fed from an Arduino PWM channel through a 2-stage low-pass filter
with maybe 10-Khz 6db cutoff.

And then you use high-freq PWM, at least 100 Khz and 7-bit resolution, and modulate
its duty-cycle using your audio waveform. Then, it might sound like something other
than buzzing.
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

My goto amplifier, there maybe better variations with filters as suggested by Fungus but this works well for me. Most of my breadboards have one at the end because once you start adding sound to projects you don't stop. The circuit is also small enough to leave on the breadboard when you are finished so its ready for the next project -

http://rcarduino.blogspot.com/2012/08/adding-audio-to-arduino-projects.html

Duane B

rcarduino.blogspot.com
Logged


Pages: [1]   Go Up
Jump to: