Uno and 4-ohm speaker

Hi all,

I've got a small 4-ohm speaker and I've been looking up how to safely play wav files with an Uno (+sd card) without any shields. Eventually I've came across this PCMAudio library: Arduino Playground - PCMAudio

I don't understand the code entirely yet but after reading the comments in the code I conclude it essentially sends PWM signals to the speaker. After intensive reading about speakers I have few concerns about this:

  1. Only positive voltage. PWM signals (output by UNO) have a range of 0V - 5V, so this would drive the cone of the speaker in one direction. It will probably be enough to make sounds but wouldn't this damage the speaker in the long run? Also this doesn't allow the speaker to operate optimally.
  2. Power dissipation. Real life sound signals are for the most part continuous signals, and in comparison pwm signals have a higher power output for 'the same' audio signal.
  3. Constant DC voltage for a short moment on every pulse which supposedly is bad for the speaker (it stalls on the cone in one position?)
  4. Sound quality. PWM signals have a lot of harmonics distortion causing distorted and kind of 'robotic' sound.

Are these real shortcomings or did I miss some important information? Before reading up I knew not much about speakers and I kindly hope you guys can clear these points up either by reconfirming or pointing out why it's not something to worry about.

TLDR; is PCMAudio a viable and responsible way to drive a 4-ohm speaker with an Uno without any shields?

You require a 220 Ohm resistor in series with the Arduino pin to limit the current to a safe level.

If you think this will severely restrict the output volume you are dead right! This also means you have no concerns whatsoever about DC bias on the speaker.

You would be better off using 50 Ohm earphones - still with the same resistor and with a capacitor in series as well.

For audio, you need a PWM frequency exceeding 20 kHz.

hawkagent:
Hi all,

I've got a small 4-ohm speaker and I've been looking up how to safely play wav files with an Uno (+sd card) 1. Only positive voltage. PWM signals (output by UNO) have a range of 0V - 5V, so this would drive the cone of the speaker in one direction. It will probably be enough to make sounds but wouldn't this damage the speaker in the long run?ble and responsible way to drive a 4-ohm speaker with an Uno without any shields?

No, you won't ruin the speaker but the microcontroller on the long run.

An audio impedance of 4 Ohms means, that the Ohm resistance is about 2 Ohms.

So a PWM with a 5V HIGH would draw current accordingly to Ohms law:

U = R* I
I = U/R

I = 5V/ 2 Ohm = 2.5A = 2500 milliAmpere

Unfortunately the AVR Atmegas are rated at an absolute max. rating of 40 mA, so this means: If you try to draw more than 40mA from the Atmega, the voltage will drop significantly.

With a 2 Ohm resistance I'd say you create a "short circuit" wih your PWM output, the Atmega will perhaps provide up to 80mA in HIGH state, but the voltage may drop from 5V to perhaps 1.5V. And the Atmega signal path will overheat, due to dissipated power P= UI = 3.5V 80mA = 280 milliWatt

At the same time the speaker sees an average speaker power of 0.75V*80mA =60mW

So feeding your 4 Ohm speaker with a 5V PWM output will create (estimated):

  • 280 mW power dissipation in the Atmega
  • 60 mW audio power in the speaker

I'd think of using of a suitable amplifier if I were you.

Thanks Paul and jurs, so I shouldn't need to worry about blowing up the speaker or the microcontroller as long I limit the current with an 220 ohm in series.

So what I understand, only having the positive voltage of an audio signal won't damage the speaker. How would the sound quality suffer under this? Could a full audio signal (continuous sine waves) be achieved with for example an high pass filter?

Paul__B:
For audio, you need a PWM frequency exceeding 20 kHz.

Why is that? Does this have something to do with us only hearing up to 20 kHz? But why exceed?

[/quote]

jurs:
I'd think of using of a suitable amplifier if I were you.

I've looked up amplifier circuits, e.g. this LM358 amplifier, however would this amplifier be suitable for the 0V-5V pwm signals coming from the arduino?

I made a wav player for my son I while back. I output 8-bit samples through 8 digital pins (portd) and use a resistor ladder for digital to analog conversion. The analog signal is then buffered by opamp and low pass filtered to remove switching noise. The signal is then buffered again before sending it to power amp. I used TDA7052 because it sounded a lot better than the 386 which suffers from feedback problems. I can dig out the sematic tomorrow (writing this on my phone) if you're interested.

So what I understand, only having the positive voltage of an audio signal won't damage the speaker.

No. But, at higher power the speaker would "bottom out" sooner if it's only working in one direction.

How would the sound quality suffer under this?

It won't sound any different at low levels where the speaker is moving linearly. You can't hear the DC bias and a speaker can't create DC (zero Hz) "sound" waves in the air.

Could a full audio signal (continuous sine waves) be achieved with for example an high pass filter?

With a low-pass filter you can convert square waves/pulses into sine waves. A high-pass filter (i.e. a series capacitor) will block DC (zero Hz) and the signal will swing between +2.5V and -2.5V.

Why is that? Does this have something to do with us only hearing up to 20 kHz? But why exceed?

At the normal PWM frequency (somewhere around 500Hz) you can hear the PWM on top of the sound you're trying to generate. You want to hear your audio, not the PWM clock...

The Nyquist theory says you need a sample rate of at least twice the signal frequency (at least one sample for the bottom half of the wave and one for the top half). i.e. CDs use a sample rate of 44.1kHz.

But, CDs are PCM. I don't know how the theory applies to PWM, and I think you need at least 10 times the audio frequency for high-quality audio.

Class D amplifiers use a kind of PWM and I assume they generally operate in the MHz range.

I've looked up amplifier circuits, e.g. this LM358 amplifier, however would this amplifier be suitable for the 0V-5V pwm signals coming from the arduino?

You should put a put (volume control) at the input because you don't need voltage gain (only current & power gain) and you might not want full-volume anyway. And of course, you should put a capacitor between the Arduino & amplifier to filter-out the DC component so the output swings both directions.

EDIT - PetriH is right... I misread that as LM386.

Btw the lm358 is an opamp. You need a power amp to drive a speaker.

hawkagent:
Thanks Paul and jurs, so I shouldn't need to worry about blowing up the speaker or the microcontroller as long I limit the current with an 220 ohm in series.

You could also put a small Farad capacitor in parallel to both attenuate noise and decrease the effects of the "robotic nature" of PWM signals. (i.e. it would round off the square waves of PWM into something more like a normal sound wave).

hawkagent:
So what I understand, only having the positive voltage of an audio signal won't damage the speaker. How would the sound quality suffer under this?

It changes the quality greatly. I would suggest looking up the Fourier Transform differences between a purely positive pulse train vs the Fourier Transform of a pulse train with 0 DC offset.

In order to output a signal that can span from negative to positive voltages, you will need a circuit with an opamp that determines if the output of the PWM output is above or below a certain value, and change the sign of the voltage if needed. The opamp circuit should also have a large voltage gain so you can hear the speaker.

hawkagent:
Could a full audio signal (continuous sine waves) be achieved with for example an high pass filter?

^No, a highpass will only attenuate low frequency signals and pass high ones. It does not cause the signal to span positive and negative voltages.

hawkagent:
Does this have something to do with us only hearing up to 20 kHz? But why exceed?

I'm not sure, but you will definitely need to observe the Nyquist Theorem that states that in order to gather the smallest amount of information about a signal, you must sample it at a frequency of at least twice the frequency of the signal being analysed. I imagine this is also true for playing a sampled version of the signal.

Does this help?

P.S.

If you want to find out what it sounds like before building an amplifer, hook it up to some powered computer speakers, or try it with headphones/earphones.

If you're using headphones/earphones, don't forget the resistor. And headphones/earphones might be very loud even with the resistor, so turn-on the sound before putting the headphones next to your ear!

Thanks everyone for replying. Today I've hooked up the speaker to the arduino, and although quiet and noisy it was able to output the desired wav files. Tomorrow I'll be going to the hardware store to pick up some capacitors hoping to at least a better quality.

PetriH:
I made a wav player for my son I while back. I output 8-bit samples through 8 digital pins (portd) and use a resistor ladder for digital to analog conversion. The analog signal is then buffered by opamp and low pass filtered to remove switching noise. The signal is then buffered again before sending it to power amp. I used TDA7052 because it sounded a lot better than the 386 which suffers from feedback problems. I can dig out the sematic tomorrow (writing this on my phone) if you're interested.

Yes that would be awesome, I'm quite interested in your project. I've read up about R2R DAC and this might be the solution I'm looking for.

Hi! I've attached the schematic of the wav player (actually a musical toy) to this post. I'll probably do a full write up about the project when I find some free time...