-2
\$\begingroup\$

This question already has an answer here:

I am new to electronics and ohms law is confusing. When I power the led with analogWrite and give it only 3 volts do I have to still use a resistor? When I power the led with 5 volts does it matter if I put a resistor before or after the led?

\$\endgroup\$

marked as duplicate by Dmitry Grigoryev, Voltage Spike, Wesley Lee, DoxyLover, uint128_t Mar 15 '17 at 0:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ This LED stuff is being discussed over and over again here. I can't believe you didn't find anything. \$\endgroup\$ – Dmitry Grigoryev Mar 13 '17 at 9:42
  • \$\begingroup\$ analogWrite is a really confusing name for the function as it doesn't just output a voltage proportional to the input value. What analogWrite actually does is to toggle a pin between high (5 V) and low (0 V) hundreds of times (490 IIRC) each second, with the function parameter determining how much time is spent with a high output relative to a low output. For example, analogWrite(10, 153); wouldn't output 3 V to the LED, it would output 5 V for 60% of the time and 0 V for 40% of the time. This technique is known as pulse-width modulation. \$\endgroup\$ – jms Mar 13 '17 at 9:43
0
\$\begingroup\$

You always need to use a resistor with an LED (unless you're powering it from a current source where different rules apply as stated by jms or unless you have a special LED that has a resistor built into it but I highly doubt you have it and it's bad for learning about LEDs anyways). It does NOT matter if the resistor is before or after the LED, though in practice, you mainly see circuits with the resistor behind the LED.

To check what resistor value you need if you don't know or wasn't given any instructions with the specific LED you are using, use this calculator.

IMPORTANT: You should also note that analogwrite doesn't really output 3V, but rather outputs 5V that switches on and off rapidly to average on 3V. So honestly you should treat it like a 5V source. Treating the analogWrite as a 3V source can be risky.

\$\endgroup\$
  • \$\begingroup\$ Thanks! Does that mean that even with 3 volts too many amps go trough the led and thats why i need a resistor? \$\endgroup\$ – abanana Mar 13 '17 at 9:30
  • \$\begingroup\$ @abanana Well think of an LED as a diode. You would be creating a short circuit if you just connect an LED without a series resistor. It also depends on your LED's forward voltage (Vf) which is a characteristic of the LED. If the LED's Vf over 3V, it won't turn on and nothing will happen. If it's under 3V and there's not a resistor, lots of current will go through, likely burning it. Also if this answers your question make sure to mark the answer as correct with the tick below the score. \$\endgroup\$ – Bradman175 Mar 13 '17 at 9:33
  • \$\begingroup\$ You always need a (current limiting) resistor if you are powering the LED from a voltage source. Arduino outputs are voltage sources by nature. If you are powering the LED from a current source set to the appropriate current, you won't need a resistor. Many dedicated LED driver chips act as current sources, and don't need resistors. \$\endgroup\$ – jms Mar 13 '17 at 9:51

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