Whyt tone() function don't burn the port with a 8 ohms speaker?

ON this link -> https://www.arduino.cc/en/Tutorial/DigitalPins

says:
"...Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state. This means that they can provide a substantial amount of current to other circuits. Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits..."

and on this link -> "https://www.arduino.cc/en/Tutorial/ToneMelody?from=Tutorial.Tone"

shows a code that has the following comment:
"...
circuit:

  • 8-ohm speaker on digital pin 8..."

So, using ohms' law, why this function don't burn the aurdino port used as output?

Likely because that's for "steady state" - that is, when the pin is HIGH or LOW; when you are using the tone library, the output is (essentially) a PWM signal - alternating high and low, which (based on the duty cycle) will look like a lower voltage - and so the current pulled isn't as much.

Now - had you the speaker connected, and set the pin HIGH - that probably would've caused an issue (then again, people abuse the Arduino all the time and it seems pretty robust - though I bet with the proper tools you would be able to find the pins damaged, if not disabled).

So, using ohms' law, why this function don't burn the aurdino port used as output?

It WILL damage the port. Unfortunately, the Arduino site sometimes provides some very bad advice and you should not follow it. Use a 220 ohm resistor to limit the current.

If you want a louder sound, you will need an amplifier.

That page should be edited or removed.

An 8ohm speaker connected to a pin is ~100mA pin current. Well above the 40mA absolute limit.
Even a piezo should be current limited, because a piezo is electrically mostly a capacitor (~2-10nF).
That is a dead short for the pulses of a PWM signal.
In both cases, 125ohm absolute minimum should be used between pin and speaker. 220ohm is better.
If you want more volume, use amplified speakers.
Leo..

Ohm's Law is a law of nature and it's always true.

And, you can usually rely on the ATmega datasheet (which says 40mA absolute maximum).

You may not fry your Arduino, but it will probably get hot and your sketch may crash or it may behave erratically. And, the output voltage will likely drop so I'd expect something greater than 40mA but less than the 650mA calculated.

I had an accidentally shorted an output pin and it stayed shorted for at-least several minutes while I troubleshooted. The Arduino survived, but I would NOT recommend that (or an 8-Ohm load or an LED without a resistor).

cr0sh:
Likely because that's for "steady state" - that is, when the pin is HIGH or LOW; when you are using the tone library, the output is (essentially) a PWM signal - alternating high and low, which (based on the duty cycle) will look like a lower voltage - and so the current pulled isn't as much.

Now - had you the speaker connected, and set the pin HIGH - that probably would've caused an issue (then again, people abuse the Arduino all the time and it seems pretty robust - though I bet with the proper tools you would be able to find the pins damaged, if not disabled).

Thanks for the answer cr0sh.

jremington:
It WILL damage the port. Unfortunately, the Arduino site sometimes provides some very bad advice and you should not follow it. Use a 220 ohm resistor to limit the current.

If you want a louder sound, you will need an amplifier.

That's exactly what I think! But, i wanted another opinion.

Wawa:
An 8ohm speaker connected to a pin is ~100mA pin current. Well above the 40mA absolute limit.

Why not (5v/8ohms)A ? Why ~100mA?
Just curiosity

Because of imaginary party of the impedance of the speaker ?

cemf:
Why not (5v/8ohms)A ? Why ~100mA?
Just curiosity

Because of imaginary party of the impedance of the speaker ?

Arduino pins already have a ~40ohm internal impedance.
So total resistance is ~50ohm.
Leo..

"the output is (essentially) a PWM signal - alternating high and low, which (based on the duty cycle)"
To be technical, tone() produces a square wave, at chosen frequencies, not Pulse Width Modulation. All the high states are the same width as the low states. The duty cycle is 50%, irregardless of the frequency.

The DC resistance of an 8 ohm speaker is less than 8 ohms.
8 ohms is for an AC signal withing the range of signals
the speaker can respond to.
A square was tone into a 8 ohm speaker is not the same
as a DC HIGH into an 8 ohm speaker.
Dwight

dwightthinker:
The DC resistance of an 8 ohm speaker is less than 8 ohms.
8 ohms is for an AC signal withing the range of signals
the speaker can respond to.
A square was tone into a 8 ohm speaker is not the same
as a DC HIGH into an 8 ohm speaker.
Dwight

Sure. Impedance of an 8ohm speaker varies wildly.
It can vary from ~6ohm DC to ~60ohm at resonance, and goes steadily up with frequency.
It could reach 30ohms or more at high frequencies.
But all these values are to low for an Arduino pin.
Leo..

dwightthinker:
The DC resistance of an 8 ohm speaker is less than 8 ohms.

dwightthinker, maybe some 8Ω speakers have a series resistance lower than 8Ω, but all the (small) ones that I've measured have been 8Ω +- 0.5Ω series resistance, (DC).
That increases with frequency of course, due to inductive reactance, but can't get any lower.

I use a 180Ω series resistor, to limit the absolute maximum current to just over 20mA. The total resistance seen by the chip is 180Ω + 40Ω(internal) + 8Ω = 228Ω.

(I just measured an 8Ω 1W speaker that I have sitting here and it's series resistance is 7.8Ω.)

What does your DMM read when you connect the testpins together.
0.3-0.5ohm?
Subtract that (meter lead resistance) from the reading.

Better to send a known (small) current through the coil, and measure the voltage across the speaker.
Leo..

While it makes no difference in this case, according to the m328p datasheet the internal pin resistance is close to 26.25 ohms at 20 mA / 25°C.

In the extremely rare case that I care, I assume 25 ohms to cover a bit lower temperature (and it's a nice number to do the math in my head). 20 ohms is guaranteed to cover the minimum operating temperature of -40°C. 25 ohms seems to be a popular value to quote. The highest value is close to 31.25 ohms at 20 mA / 105°C. I suspect values above that are indicative of a damaged pin driver.

Right, thanks for that 'Coding Badly'. I was just quoting 40Ω because here on the forums I often see the resistance claimed to be 40Ω to 60Ω. (I should have looked at the datasheet, shouldn't I? :smiley: )

Wawa:
What does your DMM read when you connect the testpins together.
0.3-0.5ohm?
Subtract that (meter lead resistance) from the reading.

0.05Ω (I use a low-ohms meter.)

Better to send a known (small) current through the coil, and measure the voltage across the speaker.
Leo..

That's true, but it's a moot point really - if a 180Ω or larger series resistor is used, the actual speaker resistance is irrelevant anyway.
Even if the speaker was 0Ω, the resistance seen by the chip would still be ~40 ~25Ω (internal) + 180Ω, 205Ω total, so the current wouldn't exceed 24mA, just over half the safe maximum per pin.

just over half the safe maximum per pin.

NO!
The safe maximum for a pin is NOT 40mA, it is the point where damage starts to occur, in the data sheet there is no mention of a safe maximum.

Grumpy_Mike:
NO!
The safe maximum for a pin is NOT 40mA, it is the point where damage starts to occur, in the data sheet there is no mention of a safe maximum.

Oh, right. Noted. Thanks Mike.
It's my interpretation, or my choice of words at least. The datasheet says "Absolute maximum", which I interpreted as 'safe maximum'.
(Either way, it's too much to draw.)

Personally, I usually like to use a transistor or other driver for anything over about 10mA anyway, whether I'm using an Arduino or a PIC, although I admit that when playing with tones I just connected direct, through a 180Ω resistor, because it's not continuous.

At least one reason there is not a safe-per-pin value is that there is a per-port limit that sets an overall lower threshold. If I have PORTB1 through PORTB7 sourcing 28.57mA then the maximum for PORTB0 is nearly zero ((200-28.57*7) = 0.01 mA).

Yep, that makes sense. That's why I generally use a driver for anything over about 10mA. It keeps the overall current for the port / device down to a nice, happy level.

OldSteve:
dwightthinker, maybe some 8Ω speakers have a series resistance lower than 8Ω, but all the (small) ones that I've measured have been 8Ω +- 0.5Ω series resistance, (DC).
That increases with frequency of course, due to inductive reactance, but can't get any lower.

I use a 180Ω series resistor, to limit the absolute maximum current to just over 20mA. The total resistance seen by the chip is 180Ω + 40Ω(internal) + 8Ω = 228Ω.

(I just measured an 8Ω 1W speaker that I have sitting here and it's series resistance is 7.8Ω.)

Please go measure a power speaker. A 100W speaker with a DC resistance of 7.8 ohms
would make a nice fire starter.
It is true that, as another had stated, the impedance of a speaker varies quite a bit with
frequency. Some of that depends on the enclosure it is in as well.
For a 1 watt speaker, rated at 8 ohms, and having 7.8 ohms DC resistance, would only mean
that it was a really inefficient speaker. It's efficiency of converting electrical signals to sound
could never be better than 2.5% if driven at a frequency that it was 8 ohms impedance.
Dwight

dwightthinker:
Please go measure a power speaker. A 100W speaker with a DC resistance of 7.8 ohms
would make a nice fire starter.

I did say "small". We're not talking about 100W power speakers here. We're discussing little 1/4W, 1W etc speakers that are likely to be connected to an Arduino. And as I said, I've never measured one that wasn't about 8 ohms. I also said "maybe some 8Ω speakers have a series resistance lower than 8Ω". I never once said that ALL 8 ohm speakers have 8 ohms series resistance.

This is irrelevant anyway, if a series resistor is used as it should be. The speaker's series resistance barely comes into the equation.