I have got a simple system using a hall sensor to detect the opening of a door and trigger a speaker to play a small jingle.
However I am concerned about the speakers current draw. From my understanding the Uno can safely supply a max of 40mA, but 20mA is ideal.
When measuring current through the dc port, it sits at 25mA idle and shoots up to about 80mA when the speaker is making noise, so the speaker is drawing 55mA.
The speaker is being powered by the ToneAC library however, and so is connected through 2 pins, as shown.
If its a Piezo, it should technically work. If its a speaker, the MCU cant provide enough current over its pins for it. A simple Transistor circuit should work. Something like this:
Oh, I see. But wouldn't it be 55mA since 25mA is being used by the Arduino itself? I am measuring total current draw in the whole system.
A piezo doesn't have anywhere near the volume of the speaker I currently have hooked up
It seems a transistor with an external power source is necessary.
Yes, same chip, same limitations. Other chips usually have even lower limits, for example most 32-bit chips like SAMD21 and ESP8266 have limits of only around 10~12mA
Those are electromagnetic speakers. What is the coil resistance? Generally you would place a resistor in series with the speaker if driving directly from Arduino pins. This would reduce the volume but avoid damaging the Arduino pins.
Maybe, but @Caelanj is using the ACtone library, which achieves higher volume by giving the speaker/piezo an AC square wave signal, moving the cone or diaphragm through a larger range of positions. A simple transistor circuit like the one shown can only move the cone in one direction, but move it further by using more current. With that circuit, @Caelanj might as well use the standard tone function, there is no point using the AC tone library with such a simple circuit.
Ohm's Law says Current = Voltage / Resistance.
5V / 8-Ohm = 625mA.
But what's happening is that the Arduino can't put-out that much current. It's being "stressed" and it's not able to put-out 5V with the low-impedance load.