Very basic resistors question

I am an old software guy who is trying to (re)learn all of this basic electronics and hardware with Arduino.

I have a pretty basic question, the answer to which will help me in all my future endeavours, it's about calculating which resistor(s) I need for any given sensor or output device I connect to my Arduino.

Let's say I'm plugging in to the 3.3V output on my Arduino...

I have a LED which says "Uf 2V lf 20mA" and another which says "Uf 3V lf 20mA"

How do I figure out what size resistor I need to plug in? What's the magic formula I need to apply?

And I always plug the resistor in to the GND connector of the LED (going back to the GND pin on the Arduino) right?

Many thanks.

When LEDs have enough voltage dropped across them (their "forward voltage"), they (effectively) turn into short circuits. So you are using the resistor to limit the current flowing to whatever the max current of the LED is (or what level of current you want).

So you use Ohm's law to calculate the resistor value. I explain here:
http://www.cmiyc.com/tutorials/led-basics/

Thank you for the tutorial. I learned a lot!

The first thing I learned is that the "lf" in my LED sticker stands for Forward Current.

Would you know what the "Uf" stands for?

...

I got a bit confused when we got to the actual formula part of your tutorial.

I see the +5V output and I see that we want to calculate R_LIMIT for 20mA.

I don't see how you jumped from the +5V above the R_LIMIT to the 3.0V in the R_LIMIT calculation rather than using 5V.

In your calculation 3.0V / 20mA = 150 Ohms. 3/20 = 0.15 so I assume that somehow 20mA gets converted to 0.02 in our calculation. We take 20 and divide it by 1000 as we're working with milliamps?

Why didn't we do 5.0V / 20mA to give us 250 Ohms as we have 5 volts coming out of the Arduino?

I therefore have a (red) wire going from the 5V of the Arduino to the (longer) Anode wire of my LED; a (black) wire going from the (shorter) Cathode wire of the LED to one end of the 150-270 Ohm resistor and another (black) wire going from the other end of the resistor to the GND pin of the Arduino.

My LEDs, except for the RGB ones, only have 2 pins. Where would I attach the wire going from the LED to the digital or analog output pin on the Arduino?

DerekErb:
The first thing I learned is that the "lf" in my LED sticker stands for Forward Current.

Would you know what the "Uf" stands for?

It's not "Uf", but "Vf", and stands for the forward voltage (Volts, forward).

DerekErb:
I don't see how you jumped from the +5V above the R_LIMIT to the 3.0V in the R_LIMIT calculation rather than using 5V.

When components are in series their voltage drops add up while their current is equal. --There are only so many electrons.

The circuit in this case is an Arduino Pin, Resistor, and LED.

So if your source (like the Arduino pin) has a voltage of 5V and the LED will drop 2V (its forward voltage), that leaves a 3V drop for the resistor.

Since the parts are in series and you want 20mA to flow through the LED, you use Ohm's Law to calculate the resistance value knowing that WHATEVER the resistor value is, it is going to drop 3V.

Ohm's law says that Resistance is equal to Voltage divided by Current. We know the voltage drop of the resistor (3V) and the current (20mA). That gives 150ohms.

DerekErb:
I am an old software guy who is trying to (re)learn all of this basic electronics and hardware with Arduino.

I have a pretty basic question, the answer to which will help me in all my future endeavours, it's about calculating which resistor(s) I need for any given sensor or output device I connect to my Arduino.

Let's say I'm plugging in to the 3.3V output on my Arduino...

I have a LED which says "Uf 2V lf 20mA" and another which says "Uf 3V lf 20mA"

It's Vf on Uf, for forward voltage drop value.

How do I figure out what size resistor I need to plug in? What's the magic formula I need to apply?
It's (voltage source minus Vf) / If = resistor ohms, so for you two leds:
(3.3 - 2) / .02 = 65 ohms
(3.3 - 3) / .02 = 15 ohms

And I always plug the resistor in to the GND connector of the LED (going back to the GND pin on the Arduino) right?

It's a series circuit (led/resistor) so it doesn't matter if the resistor or led wires to ground, same current flows in only one path. However the polarity of the LED does have to be correct or it won't conduct current
at all.
Lefty

Many thanks.

I understand that Uf should be Vf. But on the LEDs I get they all say Uf

http://snootlab.com/lang-en/leds-10-mm/57-led-10mm-green-diffused.html
http://snootlab.com/lang-en/leds-5-mm/51-led-5-mm-green-20-8x.html

The important thing is that I now understand that these values are forward voltage and what they are used for.

For an output pin of 5V with a LED of Vf 2V and an lf of 20mA I would use a resistor of 150 ohms
(5 -2) / 0.02 = 150

For an output pin of 3.3V with a LED of Vf 3V and an lf of 20mA I would use a resistor of 15 ohms
(3.3 - 3) / 0.02 = 15

As regards the circuit, if I've understood correctly and following the examples I've seen in the books, I run the power from the output pin on the Arduino (3.3V or 5V) to the anode wire of the LED, a wire from the cathode wire of the LED to the resistor (using the calculation above) and a wire from the other end of the reistor to the digital or analog output pin of the Arduino.

I think I am, very slowly but surely, getting there.

I've been following the examples in the books, and blindly plugging in the right components in the right holes, without really understanding why.

Thank you all so much for your explanations.

DerekErb:
I understand that Uf should be Vf. But on the LEDs I get they all say Uf

http://snootlab.com/lang-en/leds-10-mm/57-led-10mm-green-diffused.html
http://snootlab.com/lang-en/leds-5-mm/51-led-5-mm-green-20-8x.html

The important thing is that I now understand that these values are forward voltage and what they are used for.

For an output pin of 5V with a LED of Vf 2V and an lf of 20mA I would use a resistor of 150 ohms
(5 -2) / 0.02 = 150

For an output pin of 3.3V with a LED of Vf 3V and an lf of 20mA I would use a resistor of 15 ohms
(3.3 - 3) / 0.02 = 15

As regards the circuit, if I've understood correctly and following the examples I've seen in the books, I run the power from the output pin on the Arduino (3.3V or 5V) to the anode wire of the LED, a wire from the cathode wire of the LED to the resistor (using the calculation above) and a wire from the other end of the reistor to the digital or analog output pin of the Arduino.

I think I am, very slowly but surely, getting there.

I've been following the examples in the books, and blindly plugging in the right components in the right holes, without really understanding why.

Thank you all so much for your explanations.

Yes you appear to have the calculations all down correctly. However there appears to be an error on your wiring suggestion:

I run the power from the output pin on the Arduino (3.3V or 5V) to the anode wire of the LED, a wire from the cathode wire of the LED to the resistor (using the calculation above) and a wire from the other end of the reistor to the digital or analog output pin of the Arduino.

It should be one of the two following:

arduino digital output pin of your choice to led anode, led cathode to resistor, other end of resistor to arduino ground pin.
or
arduino output pin of your choice to resistor, other end of resistor to led anode, led cathode to arduino ground pin.

That way writing a digitalWrite(pin#, HIGH); will light the led and a digitalWrite(pin#,LOW); will turn it off.

Lefty

I now understand that the resistor can be connected on the cathode pin or the anode pin.

If I am running a wire from the digital, or analog, output pin on the Arduino to the cathode wire of the LED I assume it is the digital, or analog, output pin on the Arduino which is sending the current to the LED. If I am using one of these output pins, rather than the 5V or 3.3V pins, how do I know how many volts are going to the circuit and therefore which resistor calculation to use?

DerekErb:
I understand that Uf should be Vf. But on the LEDs I get they all say Uf

Source of the confusion is where the datasheet comes from. European countries tend to abbreviate voltage as "U" while the rest of the world uses "V". (Another abbreviation is "E".)

DerekErb:
I now understand that the resistor can be connected on the cathode pin or the anode pin.

If I am running a wire from the digital, or analog, output pin on the Arduino to the cathode wire of the LED I assume it is the digital, or analog, output pin on the Arduino which is sending the current to the LED. If I am using one of these output pins, rather than the 5V or 3.3V pins, how do I know how many volts are going to the circuit and therefore which resistor calculation to use?

For calculation purposes you can just assume a digital output pin set to HIGH will have the same voltage as the Vcc value powering the chip, so +5vdc for a 5 volt board and +3.3 volts for a 3.3 volt board.

Note your above:

If I am running a wire from the digital, or analog, output pin on the Arduino to the cathode wire of the LED I assume it is the digital, or analog, output pin on the Arduino which is sending the current to the LED.

Yes, however:

Normally one wires the led anode to the output pin and the cathode/resistor end to a ground pin so that a digitalWrite HIGH will turn on the led. If you wire the cathode to the output pin then the other end of the led/resistor must wire to the +5V pin and the led will only light if you set the digital output pin LOW.

Lefty

Thank you again for your detailed and helpful replies.

For calculation purposes you can just assume a digital output pin set to HIGH will have the same voltage as the Vcc value powering the chip, so +5vdc for a 5 volt board and +3.3 volts for a 3.3 volt board.

Is an Arduino Uno a 5 volt board or a 3.3 volt board?

Would all of this work the same if I go through an analog port instead of a digital port?

DerekErb:
Thank you again for your detailed and helpful replies.

For calculation purposes you can just assume a digital output pin set to HIGH will have the same voltage as the Vcc value powering the chip, so +5vdc for a 5 volt board and +3.3 volts for a 3.3 volt board.

Is an Arduino Uno a 5 volt board or a 3.3 volt board?

It's a 5 volt board.

Would all of this work the same if I go through an analog port instead of a digital port?

If you mean pin instead of port, then yes the analog input pins can be used as digital input or output pins. You just have to set the pin mode and output value using the pin mode and digitalWrite commands.
Lefty

I use these quick and easy calculators:

http://led.linear1.org/1led.wiz

http://led.linear1.org/led.wiz

Derek: You might want to look up Thevinin and Kirchoff.

Good luck and have fun

A standard EE does it so:

  1. Vcc is 3V3
  2. my LED lits fine at I=1.0mA
  3. My LED is red, red LEDs have Vf=1.5V (for example)
  4. R = (Vcc - Vf) / I = (3.3 - 1.5) / 0.001 = 1800 ohm = 1k8
    I do not understand who recommends to use 20mA current through an LED today (when used for indication purpose).. We used 20mA currents 40y ago. Today's LEDs lit fine at 300uA.. Unless you going to cut the steel with your LED gun :slight_smile:

pito:
A standard EE does it so:

  1. Vcc is 3V3
  2. my LED lits fine at I=1.0mA
  3. My LED is red, red LEDs have Vf=1.5V (for example)
  4. R = (Vcc - Vf) / I = (3.3 - 1.5) / 0.001 = 1800 ohm = 1k8
    I do not understand who recommends to use 20mA current through an LED today (when used for indication purpose).. We used 20mA currents 40y ago. Today's LEDs lit fine at 300uA.. Unless you going to cut the steel with your LED gun :slight_smile:

That's just what people want to do :wink:

I spent some time getting the right combination of LED and resistor for my LED boards to get the LEDs as bright as possible, because that's what people wanted. Now you can hardly look at the red and blue LEDs without searing your retinas, and people love them. The LEDs I use have a "rated" forward current of 20mA, an absolute maximum of 30mA. At If=20mA they're 150mcd.

That's not a patch on the white right-angle LEDs I use. 1300mcd at If=20mA. Three of them at 20mA (4V Vf each) will light the entire room. Just with a single one by itself you can't look straight at it. And if I were to pulse them I could run at up to 100mA with a 1/10 duty cycle. I haven't done that yet to see how insane they are, but I'll bet they hurt.

So yes, running at lower than the "rated" current is usually pretty bright anyway. People just "assume" 20mA as most LEDs have their visual data quoted at If=20mA.

Edit: Oh, all those LEDs I spoke of above are all 0805 SMD footprint.

@majenko: frankly, the first thing I do with my lovely boards I am getting from ie. ebay or from MCU vendors (kits) is - I replace those 270 and 330ohm resistors they are using because they saw it on a schematics from 1973 with such values, or, somebody told them "an LED needs 20mA"..
I did few measurements in past with a bunch of 3mm dia and 0805 smd LEDs and most of them lit fine (so you can watch the board without sunglasses) at 100-300uA (microamps). I am using 2k2-4k7 resistors with any color.. ]:slight_smile:

That's pretty high... I have traditionally used 1K with LEDs when just messing around, or 470? if I want them bright - mainly because I have thousands of those in ?W kicking around doing nothing. On boards though I tend to use lower values (usually whatever I have nearby spare on a 4 element array) as kids love the bright lights... It appeals to their simple natures. And some of my projects demand incredible brightness, as the LEDs are the main feature of it...

as the LEDs are the main feature of it.

yea, by DUE controlled 2Watts LED lightsaber :slight_smile: