3

I am currently tinkering with an arduino, and am using a potentiometer to change the brightness of an LED.

I understand that usually, a resistor is added to the circuit to limit the current flowing through the circuit in order to prevent the LED from burning out.

However, as I am currently using a potentiometer to adjust the LED's brightness, AND as a potentiometer is basically a variable resistor, would I still need a resistor to prevent the LED from burning out? Currently, I do not see a difference between using a 220 ohm resistor and not using it, as the LED seems unaffected.

My code:

const int pot=A0;
const int led=11;
int potValue;

void setup(){
  Serial.begin(9600);
  pinMode(pot,INPUT);
  pinMode(led,OUTPUT);
  analogWrite(led,100);
}

void loop(){
  potValue = analogRead(pot);
  potValue=map(potValue,0,1023,0,255);
  analogWrite(led,potValue);
  Serial.println(potValue);
}

PS: My LED is hooked up to the arduino's PWM pin, and connected to ground on a breadboard.

4

Without a good quality picture of your setup or some schematics, it's hard to tell what's going on, but from your description, what you're doing is potentially harmful for the LED and the output pin D11.

Yes, LEDs almost always need series resistors to limit their current. They don't limit currents and will burn if you don't do it for them.

If you had the pot in series with the LED, which seems to be what you think is going on, you'd still need a series resistance so that when the pot is all the way to one side, effectively behaving like a 0Ω resistor or a short, you'd still be limiting the current with the 2nd resistor. One would usually use Ohm's Law to calculate that 2nd resistance so that it lets the maximum current the LED can take when the pot is at 0Ω position, usually 20mA for common LEDs.

But that's not how your circuit seems to be wired. The pot is indirectly controlling the LED through an analog input and a PWM output via MCU. So it's not limiting the LED current, in the traditional sense. The pot seems to be wired between 5V and GND with the middle lead (the cursor) hooked up to the analog input A0. That's a variable voltage divider configuration that let's you select a continuous voltage between 0 and 5V that is in turn converted to a value between 0 and 1023 by the MCU ADC (Analog to Digital Converter) - that's the result of the analogRead() call.

That value is then fed to a PWM analog output, through the analogWrite() call, that will output a square wave to the LED. The relative position of the pot will determine the duty cycle of the PWM, i.e., how long the square wave is HIGH or LOW. The problem here is that this circuit where the LED is wired should have its own series current limiting resistance.

To me, if you didn't burn the LED or the D11 pin yet, is pure luck. If you were to turn the pot all the way to maximum brightness (don't do it), the PWM output would act like a digital output put in HIGH level (5V continuously), and without a current limiting resistor, the D11 pin would exceed it's 40mA absolute maximum source current and burn. Unless there's another factor limiting the current that I don't know of, that is.

There are some exceptional cases in which you can control the LED voltage closely so you don't need to limit the current (multiplexing, constant-current supply etc.), but these are really advanced configurations for us newbies. So, from know on, do it like I do it: ALWAYS put a series resistor, until you become familiar with these advanced configurations.

Finally, below are some links that you may find helpful about the topic:

  • 1
    Thank you for the prompt and detailed reply, you were right in assuming that the pot is controlling the LED through an analog input, and an output via a PWM.I've turned the pot to max brightness momentarily(never more than 1 sec), and am sure glad i've never left it there for extended periods of time! – Kenneth .J Jun 2 '14 at 17:14

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.