# Do I need a resistor on a 40 mA pin when all I need is 40 mA?

I have an Arduino Uno and I am going to be using the analog pins to do two sets of runner lights. Each pin will be hooked up to two 20 mA blue LED's in parallel. I know that the IO pins on the Uno only supply up to 40 mA, so do I still need a resistor if its max output is the exact output I want?

Yes.
The output of an Arduino Uno is 0V or 5V. When it is 5V, and a led is connected without resistor, there might be a current of more than 40mA. So the Arduino and led could be blown.
I would not try to find the limit to damage the Arduino. You better use two pins, each with a led.

You can use 100 ohm or higher.

jardane:
I know that the IO pins on the Uno only supply up to 40 mA,

Sorry, but no you don't know any such thing.

I suggest you go read the datasheet instead of "instructables". While a bit daunting, the information in question is near the top.

Hi,

There is a limit of 100mA on each “port” and a total limit of 200mA for the whole Arduino. All the analog pins are on the same port. Digital pins 0 to 7 are on another port and digital pins 8 to 13 are on a third port.

If I were you, I would look at using a uln2803 or tpic6c595 chip for your leds.

Paul

Interresting, but when reading the dataseet for the ATMega 328p i can clearly read in the Electrical Characteristics in the Absolute Maximum Ratings :

DC Current per I/O Pin ................................................ 40.0mA
DC Current VCC and GND Pins................................. 200.0mA

So, not sure what Arduino type you are using, maybe one of the newer ones, but for a standard Arduino (uno or so) there is a stated maximum of 40mA per I/O pin and no more then 200mA for all I/O pins and the logic together.

Have fun,
Guido

Why don't you just put your meter in current mode/400mA and put it in series with an output pin and ground. Then you can see for yourself exactly how much current it will draw. Set it up as an output and turn on that output and put the meter from the output pin in HIGH state to ground with the RED lead on the output and the black lead on ground. Your meter will read how much current is SOURCED.
Then turn the output OFF (to the LOW state) and put the red lead on +5V and black lead on GND, to measure how much current it will SINK.
Mind you, I wouldn't do this myself but if you are that sure that it maxes out at 40mA and don't believe us you can check it yourself.
I won't take any responsibility for the consequences.

DeepZ:
Interresting, but when reading the dataseet for the ATMega 328p i can clearly read in the Electrical Characteristics in the Absolute Maximum Ratings :

DC Current per I/O Pin ................................................ 40.0mA
DC Current VCC and GND Pins................................. 200.0mA

Precisely. but do you comprehend what "Absolute Maximum Ratings" actually means?

For example if the "Absolute Maximum Ratings" includes 6.0V as the supply voltage, does that mean you can supply it with 12V and say "but the rating says it will not let the voltage go over 6V, so how come I can measure 12V across its terminals"?

This is a common cause of confusion amongst beginners.
A value of 40mA is not the maximum current it will supply it is the maximum current it should be allowed to supply.
The two things are totally different.
You can get a pin to supply much more than 40mA like by putting an LED across it without a resistor.

If you want to power two LEDs you not only need a resistor but you need two resistors.

Grumpy_Mike:
If you want to power two LEDs you not only need a resistor but you need two resistors.

Not necessarily. You can use a single resistor. The issue will be that when both are on
each will not be as bright as when it is on individually.
Depending on the application, this may or may not be acceptable.
In some cases it is perfectly fine.
For example, suppose you have a RGB led and will only need to have
a single color on at a time. In that case, you could use a single resistor

--- bill

"Absolute Max: This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the
operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability."

The datasheet also says that with 5V VCC, the voltage out is only guaranteed for 4.2V at up to 20mA, and will degrade as the current rises.

Current limit for the device also varies with the number of VCC/GND pins.
SMD 328Ps have 2 VCC pins, 2 GND pins, vs the DIPs with just 1.
The limit is 200mA/VCC pin. If you add up the currents listed under Table 29-1, you'll see the ports will actually support up to 300mA total. This is only achievable with SMD package:

Note 3. Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state
conditions (non-transient), the following must be observed:
ATmega48A/PA/88A/PA/168A/PA/328/P:
1] The sum of all IOH, for ports C0 - C5, D0- D4, ADC7, RESET should not exceed 150mA.
2] The sum of all IOH, for ports B0 - B5, D5 - D7, ADC6, XTAL1, XTAL2 should not exceed 150mA.
If IIOH exceeds the test condition, VOH may exceed the related specification. Pins are not guaranteed to source current
greater than the listed test condition.

Note 4. Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state
conditions (non-transient), the following must be observed:
ATmega48A/PA/88A/PA/168A/PA/328/P:
1] The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100mA.
2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100mA.
3] The sum of all IOL, for ports D0 - D4, RESET should not exceed 100mA.
If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater
than the listed test condition.

bperrybap:

Grumpy_Mike:
If you want to power two LEDs you not only need a resistor but you need two resistors.

Not necessarily. You can use a single resistor. The issue will be that when both are on
each will not be as bright as when it is on individually.

For a start the OP was talking about two LEDs on one pin so they can not be controlled separately.
With only one resistor and two LEDs in parallel the two LEDs will not share the current equally. This means that one LED will have more current than you designed it to have thus stressing it beyond what you intended.
Put simply with two LEDs in parallel you are not in control of what happens, it is in the lap of the gods, and that is very bad, not to say stupid, design to save a \$0.005 component.

In some cases it is perfectly fine.
For example, suppose you have a RGB led and will only need to have
a single color on at a time. In that case, you could use a single resistor

Yes in that case this will be slightly less stupid but as each colour of LED has a different forward voltage then each LED will draw a different current when turned on. So again you are not in complete control of things.
Secondly it is a rare application that has an RGB LED and you only want three colours out of it.

"Precisely. but do you comprehend what "Absolute Maximum Ratings" actually means?:

Hello Paul__B

Yes, I know exactly what that means.
I was replying to PaulRB who stated (unless i misread) "There is a limit of 100mA on each "port" and a total limit of 200mA for the whole Arduino" which i wanted to counter with the info from the datasheet as we do not want to mislead anyone.

BTW, there is very little to not understand, as the datasheet also explicitly states " Stresses beyond those listed under “Absolute
Maximum Ratings” may cause permanent damage to the device".

Thanks,
Guido

BTW, i assume PaulRB was pointing at the notices like "The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed .." in the data sheet.

I believe so - not quite a clean 1:1 mapping.

Well, I thought I had an easy to remember set of rules to abide by. Now I'm a little confused!

Suppose I want to sink 160mA through a mega328 PDIP/Uno R3, using 8 pins to sink 20mA each. What way(s) can I safely spread the load across the pins? Would the answer be any different for an SMD '328/Pro Mini/Nano?

Thanks!

The only way to know for sure is to check each led with a 220 ohm resistor and measure the voltage drop across the led, which means the resistor needs to be connected at the Vcc side of the led and the led from the resistor to ground. Measure and record the voltage. Then calculate the resistor value to obtain 20 mA. The forward voltage does not change. It is what it is. So if it is 2.2V
then the correct resistor to get 20 mA through the led is 140 ohms (5V -2.2V)/0.020 A= 140 ohms.
Using this formula and method you will always know how much current a led is drawing.

The forward voltage does not change.

Well yes it does, it changes with current, temperature and age.

The forward voltage does not change.

Well yes it does, it changes with current, temperature and age.

Well, let’s see how much:
Let Vcc = 5.02 V
Test Objective: Compare Delta Vforward to Delta Iforward
CASE-1
Let R = 220 ohms
Let led = standard red led
VfCL =1.987 V
ILED= Vf/ILed = 1.987/220 ohms = 0.00903 A = 9.03 mA

CASE-2
Let R = 100 ohms
VfCL =2.095 V
ILED = Vf/ILed = 2.095/100 ohms = 0.02095 A = 20.6mA
I-1 = 9.03 mA
I-2 =20.6 mA
V forward case-2-V forward case-1 = 2.095 V - 1.987 V =0.108 V = 108 mV
I case-2 - Icase-1= 20.6 mA - 9.03 mA = 11.57 mA

Observations:.

Delta Vforward/Delta Iforward= 108mV/11.57 mA = 9.33 mV/mA

With a Vcc of 5.02 V dc
the led had a forward voltage of just under 2 V dc and drew 9 mA using a 220 ohm resistor.
Using a 100 ohm resistor, the same led had a forward voltage almost 110 mV higher and drew almost 21 mA

Conclusions:

The forward voltage of a standard garden variety red led varies 9.33 mV / per mA of forward current.

I guess you could say it does change, but it only varies by 96.4 uA /per ohm of resistance of the current limiting resistor
(220-100=120 ohms)
(11.57 mA /120 ohms = 0.0964166 mA / per ohm => 96.4 uA / per ohm of change in the current limiting resistor.
That doesn’t sound like something that you need to worry about.

Suppose I want to sink 160mA through a mega328 PDIP/Uno R3, using 8 pins to sink 20mA each. What way(s) can I safely spread the load across the pins? Would the answer be any different for an SMD '328/Pro Mini/Nano?

There are 3 groups of pins, each group can sink 100mA.
Can use 5 from group 1, and 3 from group 2.
Or 3, 3, 2.
Or 4, 4.
Or ...
Same 328P die in the chip on all boards. Each board type has at least 2 Gnd pins (32-pin surface mount have 3), so can use all the same code/connections.

1] The sum of all IOL, for ports C0 - C5, ADC7, ADC6 should not exceed 100 mA.
2] The sum of all IOL, for ports B0 - B5, D5 - D7, XTAL1, XTAL2 should not exceed 100 mA.
3] The sum of all IOL, for ports D0 - D4, RESET should not exceed 100 mA.

(Why are ADC6, 7 even listed here? They are listed else where as Analog Input only pins).