analogWrite LED brightness

Hi, I'm just learning arduino and trying to use the analogWrite method in order to do pulse width modulation on an LED. The LED does correctly brighten and dim but it never gets very bright at its peak. Checking with a multimeter, the pin does indeed output around 5 volts at its peak but the LED is never as bright as it is when I use digitalWrite(5, HIGH);. Can someone explain why this is? Thank you.

Here's my code:

#define LED 5
int i = 0;

void setup() {
pinMode(LED, OUTPUT);
}

void loop() {
for(i = 0; i < 255; i++) {
analogWrite(LED, i);
delay(10);
}
for(i = 255; i > 0; i--) {
analogWrite(LED, i);
delay(10);
}
}

What's the size of the resistor you have on your LED?

I'm guessing that's going to be the biggest factor here. Could also be just that your LEDs aren't super bright? Hard to say. :stuck_out_tongue:

It's not your code, that parts fine. So it's hardware somewhere.:stuck_out_tongue:

Thanks, my resistor was too high (10k). What's a good value for it? 4700 ohms?

Checking with a multimeter

Not always trustworthy where "analogWrite" is concerned. :wink:

@wmmartin
It really depends on the LED forward voltage and how many MA it uses. You can find that information by looking at the data sheet.

But if I don't know what LED I'm grabbing, I'll usually use a 1k resistor. But some of the LEDs I have use only as low as 100 ohms, but they're actual "high brightness" LEDs.

You can always use Ohms law to figure out the resistance you need.

(Supply Voltage - Forward Voltage) / Forward Current
so I just used one of the LEDs I have for an example:
(5V - 2.2V) / 20MA = 140 Ohm resistance

But if you don't know values, I'd say 1k would be "safest" :stuck_out_tongue:

And I don't know anything about the Multimeter and PWM.:X

A good page for calculating LED resistors is:- http://ourworld.compuserve.com/homepages/Bill_Bowden/led.htm

A typical value is between 200 - 400 Ohms. Although for driving an LED at it's maximum current this can drop below 100R.

High brightness LEDs just refer to the current effeminacy, that is the amount of shine per mA, it does not refer to high current LEDs.