Maximum current from a data pin?

Hey,

I was having a problem driving a relay from an Atmega328 (see http://arduino.cc/forum/index.php/topic,90600.0.html) and discovered that I'm only getting 13ma out of digital pin 4.

According to the Arduino docs,

"Each pin can provide or receive a maximum of 40 mA..."

In my test circuit, when I set pin 4 high (in OUTPUT mode) I see 4.96v at the pin. If I connect a 180 Ohm resistor between pin 4 and GND, I expect to see (5/180) 27mA. I actually only see 13mA.

Does anyone have any ideas what my cause this? I started out using an UNO, now I have an Atmega328 running on my own board/power supply. FWIW, I have isolated my power supply by driving my board completely off an UNO's power with the same results.

Any suggestions would be greatly appreciated.

TIA, -Mitch

That is normal. The AVR datasheet does NOT guarantee +5vdc output when sourcing 40ma of current. I'm looking at a graph in the AVR 328p datasheet showing the pin output voltage (when set HIGH) Vs current flow to the external circuit. It shows +5vdc at 0ma output pin current, down to 4.45vdc when sourcing 20ma of output pin current. So measure the output pin voltage while it's sourcing your measured 13ma current draw and see if the pin voltage is around 4.65 volts or so. Your simply going to have to factor in this output voltage decreases with current flow amount when you calculate the proper current limiting resistor size. By the way the AVR max current of 40ma is a maximum safety rating before chip damage is likely. AVR recommends that maxium normal pin current be limited to 20ma or less, although your desired 27ma is OK most likely.

According to the Arduino docs, "Each pin can provide or receive a maximum of 40 mA..."

This is a bit wrong it should say "Each pin should not provide or receive a current above a maximum of 40 mA.

Point is that the output is not a steady 5V when you start drawing current out of it. If you draw 20mA the the voltage you get out is within the limits given in the processor's data sheet. As you draw more the voltage drops below these limits. As you draw 40mA or more you damage the arduino pin.

Does anyone have any ideas what my cause this?

Yes it is designed like this. It is an output pin not a power supply.

Got it…that makes sense.

Clearly I need to rethink my design.

It sounds like the Atmega output pin should drive the base of a (low-side NPN) transistor which switches on the relay coil (no need for an optocoupler).

Great stuff guys…thanks.
-Mitch

It sounds like the Atmega output pin should drive the base of a (low-side NPN) transistor which switches on the relay coil (no need for an optocoupler).

That is the more popular method. Opto-isolators should be used only when there is a requirement for galvanic isolation (no sharing of common ground or source voltage) between two circuits.

Don't forget that you will still require a series current limiting resistor between the transistor's base and the arduino output pin (not ciritical for your case, 200-1K ohm should work fine) and if you are not using the arduino's voltage source for the relay you must tie the arduino ground pin to the negitive terminal of the external relay's voltage source.

Lefty

According to the Arduino docs,

“Each pin can provide or receive a maximum of 40 mA…”

And the whole chip should not draw current above a absolute maximum of 200 mA.

Here's some details on current maximums:

ARDUINO PIN CURRENT LIMITATIONS: Be Nice to your Arduino! (Thanks to @CrossRoads !)

http://arduino-info.wikispaces.com/ArduinoPinCurrent