4

enter image description here

This is project 2 of their official arduino projects book called "Spaceship interface". I understand resistors normally reduce voltage so the LEDs don't burnout but here 5v is coming from either digital 3, 4, or 5 and it seems like it goes right into the LED before going through a resistor as it goes back to ground. This makes no sense to me.

  • A LED has no problem with 5V and the current. Purpose of the resistor in to not to burn the Atmega pin. – Juraj Feb 22 '18 at 14:38
  • resistors do not "reduce the voltage" ... resistors reduce the current .... if you put a 1k resistor across a 6V battery then the voltage across the resistor is 6V and the current through the resistor is 6mA .... if you use a 2k resistor, then the voltage is the same, and the current is 3mA – jsotola Feb 23 '18 at 17:40
8

It does not matter if a resistor is before or after a component, see the circuits below.

The resistor reduces the current, and this is true for the path where the resistor is in (until the interconnections before/after the resistor). In the examples there is only one path.

schematic

simulate this circuit – Schematic created using CircuitLab

  • but I think the example in the book is ugly. – Juraj Feb 22 '18 at 14:35
  • Because it is after the LED? Actually I also use it after the LED mostly, especially if I use a resistor array. – Michel Keijzers Feb 22 '18 at 15:34
  • because of button with pull-down and the line crossings. And I don't know, wouldn't be one resistor for all 3 LED pins enough? – Juraj Feb 22 '18 at 15:49
  • 1
    You need a resistor for each to keep the brightness the same. If you only used one resistor on the ground side then all three LED's would be sharing the same reduced current meaning that if only one was on it would be much brighter then if all three were on. – Chad G Feb 22 '18 at 16:07
  • 1
    1V? Really? When I tested a standard red LED it didn't illuminate under 1.8V. – Nick Gammon Feb 23 '18 at 2:04
3

It doesn't matter where the resistor is located (before and after are meaningless concepts). What is important is that the resistor is in series with the LED.

This produces an approximation to a constant current source (I = V/R). The actual current is lower due to the voltage drop across the LED, so is actually I = (V- VLED)/R. VLED varies; red LED is lower ~1.2V blue significantly higher.

The resistor serves 2 functions; to limit the current from the Arduino and to limit the current through the LED (either to limit brightness or protect the LED)

1

The resistor is to limit the current flow through the LED. A LED will burn itself out if given too much current and the maximum Arduino output current is 40 mA per leg (output). A quick calculation of V=I*R where V is 5 Volts, I = 40 mA leaves R = 5/.04 or 125 Ohms. You don't want to pull that much current from the Arduino so using 220 resistors is a safe bet at 22mA current draw per leg.

That 10K resistor keeps pin #2 at the ground potential until the button is pushed. Then the input to pin #2 is 5 Volts.

FWIW - that is an ugly drawing.

1

Most single or RGB LEDs can't take more than 20mA without risking overheating/burning up. Modern LEDs need as little as 5mA to be really bright. I use 1K resistors on boards where the LED is being used as an indicator (like Power, or Rx or Tx active, or for the L (SCK activity) LED. Sometimes 2.2K when 1K seems too bright still. Depends on the LED. Test first before soldering thinks up.

To calculate a resistor value for a desired current, use Ohms Law, V=IR, Voltage = current x resistance. Rearranged, Voltage/current = resistance.

If you know the Voltage, Vf, of the LED when it is on, and you are driving from an Arduino pin that outputs 5V, then: (5V - Vf)/current = resistor. With 5mA and say a Vf of 2.5V: (5V - 2.5)/.005A = 500 ohm.

You can determine Vf of an LED by using a 5V source and a 1K resistor. Connect the LED and resistor in series between 5V and Gnd. Measure the voltage across the LED, that is Vf. 5V - Vf = voltage across the resistor, Vr. 5V = Vf + Vr.

If you know the voltage across the resistor, Vr, you can calculate current flow: Vr/resistor ohms = current Amps. Say you measured Vr of 2.7V and used a 1K resistor. Then current = 2.7V/1000ohm = .0027A, or 2.7mA.

  • 1
    This is interesting and informative, but it doesn't answer the question of why the resistor is after the LED and not before it. This is probably why the answer has been voted down (it wasn't me!). – Nick Gammon Feb 23 '18 at 1:57
  • I figured the before/after had been discussed plenty already. Knowing the reason for selecting the resistor value is also important. – CrossRoads Apr 10 '18 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.