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?

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/

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?

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 currentat all.Lefty

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.

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:

Quote

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.orarduino 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.

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?

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:

Quote

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.

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?

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