Resistors with LED's

I am following the arduino starter kit and confused with using resistors with LED's. In chapter 1 there is a resistor before LED's. There was even reasoning to do it because of ohms law(V=I*R). Basically LED's can only accept 23mA and since input voltage is 5V we need to add a 220 ohms resistor.

However in chapter 2 the 220 ohms resistor is added after the LED(pictures below). The only difference is current is passed through pins 3,4 and 5 programmatically using digitalWrite.

Wondering what's the difference in 2nd setup. Thx!

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original as it not an Introductory Tutorial

It makes no difference whether the current limiting resistor is "before" or "after" the LED as long as the current passing through the LED also passes through the resistor

Thanks for the response. The resistor would reduce voltage in the circuit, It makes sense now to me.

One follow up question: Wouldn't there be big surge of current to LED initially after turning on the switch and before hitting the resistor that could damage the LED?

TY!

I am not sure what you mean by this. Which voltage are you referring to ?

There will be no initial surge of current. The current has to pass through the resistor and, hence, is limited at all times

No. Electrical current is not like water flowing into an empty pipe. There will be no delay before the current arrives at the resistor. It's more like water flowing into a pipe already full of water. As soon as the flow begins, the rate of flow is the same along the whole length of the pipe.

So you know Ohm’s Law? Then you know it makes no difference where you put resistor before or after, right?

Never mind, you answered it here ^^^

Your images show two ways to control an LED, as follows:
+5 --- resistor ---- LED ----- Digital output
and
Digital output ---- LED ---- resistor ---- GND

In the first case, you must output a "LOW" signal to light the LED, in the second case, you must output a "HIGH" to light the LED. Two approaches, functionally the same except that the signal you output is opposite.

No. It would reduce current in the circuit.

Since you asked, there are actually three (3) voltage drops to consider:

V1) the output gate junction within the uC (sink or source)
V2) the LED junction, color based (materials & doping)
V3) the resistor drop based on current.

V1 + V2 + V3 = rail voltage, Positive to Ground (for most cases)

Reference:

Logic signal voltages for various technologies

It is always wise to consult the technical reference of the microcontroller when contemplating voltage drop of output gates within the uC.

There is absolutely no difference in these two circuits:
series

The resistor in series with the LED is not for voltage, it is to limit the current through the LED. When conducting, an LED has a resistance of nearly zero. Without a current-limiting resistor you would smoke the LED. The value of the series resistor would be 5V/.023A = 217Ω (Ohm's law). 220Ω is the nearest standard value.

Personally, in my projects I use a series resistor of 2KΩ because when using a 220Ω resistor, the LED is blindingly bright.

The brightness at any given current is a function of the LED's design. Since 1980 I've used LEDs, and over that time the light output at any given current has increased dramatically as technology changed. It's wisest to either use the specification for the LED you purchased, if you have that info, or to actually test with your LED. I have LEDs in my parts drawers that are marginal at best at 20 mA, but there are others that, as you say, are blinding.

I reiterate the last line of Steve Mann. Better to use more than 2kOhm in place of 220 Ohms. That is because an LED is bright enough at 1 or 2mA for what you are doing, and it is gentler to the circuitry within the arduino to aim for that. A sensible way to get an LED to max brightness above 10mA, which can be rather startlingly bright, is to use an npn or an nfet.

This makes lot more sense now. TY!

I thought wrong. Resistor actually reduces current flow, not voltage(from the comment below from aarg)

No, the voltage and current while often compared to water pressure and flow, they have no inertia. So for all intent and purposes the current happens instantly seeing the resistor and led at the same time.

Be aware, this changes when one adds capacitors to the circuit.

series

One thing to consider.

Assume you are mounting the LED on the chassis.

You would need to take 2 (two) wires from your PCB/breadboard out to where the LED is mounted, let’s say the distance is 12 inches.

If we used the LED2 circuit, it means we take Vcc (say 5v) off the PCB 12 inches to the anode of the LED.

As a general rule, we try to avoid long wire runs of Vcc.

Using the LED1 circuit for our chassis LED wiring, GND is taken to the LED instead; Vcc stays at the PCB.

Hence, LED1 might be considered preferable.

Why is that ?

Because it can cause a short.
Because a wire costs money (to buy, but also to tie).
Because chassis connection is for free.

A GND wire can short just as easily
The length of wire used will be the same either way
Who said anything about a chassis ?