Correct calculation of resistor value when connecting LED?

Hi,
this is a newbie question, but I would really appreciate some help or indication if I am thinking about this in the right way.
I have actually studied digital electronics, but my memories are very vague and I am much more of a software guy nowadays.

My question:
How do I calculate the correct value for the resistor when connecting an LED from 5V to a digital pin on the Arduino?

Background:
Many examples either just short circuit from 5V over the LED to the pin, or say something sweeping like "... any resistor between 330Ohm and 2KOhm should do the trick". I have a feeling that the first is not really best practice and that there is a proper way to come to the second conclusion.

So, I know the basic formula V=R*I.

In this case I guess we have:
V = 5
R = (to be calculated)
I = ? (what should I plug in here? 0.55A?, The max source current of the Arduino?

So, two more questions arises:
- What current do I calculate with?
- Do I need to take the forward voltage drop of the LED into consideration?

Any help would be much appreciated!

Hey,

The shorting LED way was certainly incorrect.

Here is typically how you calculate the "current-limiting resistor" for an LED.

You will need to know ahead of time:

  1. Supply voltage Vdd, in case of the typical 5V arduino dev boards, Vdd=5V

  2. Typical forward bias voltage of the LED Vfb, read the spec sheet. My personal experience is that more powerful LEDs have higher value of Vfb.
    Take this one for example:

A range of 3.0 to 3.6V is given. I would try to use the average of 3.3V. Some other spec sheets give typical values and you will use that value.

  1. Current rating i_m. The above LED is said to have 20mA current rating. It's the maximal sustained current you want it to have. Again some other spec sheets give you current at typical forward bias voltage and you can use that value.

Now to calculate the current-limiting resistor, just do this:

Vdd=Vfb+Vr, where Vr is the voltage dropped on the current-limiting resistor. So Vr=i_m*R. Where i_m is the LED current rating.

So R=(Vdd-Vfb)/i_m

For the above LED, R=(5V-3.3V)/0.02A=85ohm. That is when you are pushing a little bit. Plus, arduino pins can only supply 20mA and the entire ATMEGA chip can supply 200mA. So to be safe, I would use a 150ohm resistor. Then the LED will be less bright. If you use the LED for lighting purpose, its brightness is relevant to you. But you use it as an indicator instead of illumination, make it not that bright by using larger resistors.

So, I know the basic formula V=R*I.

In this case I guess we have:
V = 5
R = (to be calculated)
I = ? (what should I plug in here? 0.55A?, The max source current of the Arduino?

So, two more questions arises:

  • What current do I calculate with?
  • Do I need to take the forward voltage drop of the LED into consideration?

First your voltage term needs to account for the forward voltage drop of your specific led. Red leds have a nominal 1.5vdc forward voltage drop, so that has to be subtracted from the source driving voltage, of 5vdc for a arduino digital output pin. So E=3.5vdc for a red led.

I is a value you select that you want to drive the led at. .02 amps is a nominal value, but useful light will be had from anywhere from 1ma to 20ma. Lets stick with .02amps

So R= E/I or 3.5/.02 or 175 ohm current limiting resistor. In reality anything from 175 to 1,000 ohms will protect the digital output pin and give you usable light. It's not important that the led is run at exactly 20ma.

Lefty

To add to what Lefty correctly told you - in very few cases is it necessary to drive a LED to it's rated current capacity. You will be surprised how bright it can be at a small fraction of that. Most red LEDs are plenty bright enough at 2 or 3 ma or even less.

Only 3 LEDs each at around 6mA in a dark bedroom. 20mA will hurt your eyes if you stare at it.

What all these guys are trying to tell you is that although Ohm's law states that R = V/I you can't just apply the values indiscriminately.

Mr. Ohm was very careful to state that this relationship only applies to certain devices, those that ultimately came to be called 'resistors'. You can't legitimately apply Ohm's law to an LED or to a group of components that contains an LED (such as a resistor in series with an LED). In your application you must apply Ohm's law to the resistor alone.

Basically you decide what current you want through your LED and you look at the data sheet for the LED to find out it's forward voltage at that current. If you don't have a data sheet you can use typical values such as 0.7 V for a red LED. You subtract that voltage from the supply voltage to determine the voltage across the resistor. You apply Ohm's law to the resistor (using the voltage you just determined and the current that you previously decided that you wanted) to determine the required resistance. You choose a resistor near that value, put it in the circuit, and measure the current. If the current is too high you raise the resistance and if it is too low you lower the resistance. Remember you are dealing with more than one approximation. The data sheet gives you values for a 'typical' LED, yours may be different. The marked resistance on a resistor is a 'nominal' value, yours may be different.

Don

Thank you all!

Very good and enlightening answers and explanations!

This is such a great forum, made up from a lot of great people. When I gain more experience, I'll make sure to pass the spirit on.

Thanks again!

Very simple xD

Better lately than never :wink: