I think the answer is yes, but I wanted to ask the question anyway for future common reference. And to check my understanding.

Say I want to power 10 LEDs with PWM with my Mega 2560. I have a bunch of 200 ohm resistors.

I know the Mega and most other Arduinos can safely provide a maximum of 200mA total current. 200mA / 10 is 20mA per LED maximum.

Using my 200 ohm resistors I can calculate how much voltage will supply 20 mA of current:

V = 200 ohms * 20mA
V = 4V

So I just need to make sure to analogWrite less than or equal to 4V to each of the ten LEDs and I won't cross the 200mA threshold. That's if PWM was true analog.

However, PWM is not true analog, and if I analogWrite 4V to each pin, they're going to spend most of the time at 5V and some of the time at 0V.

When every pin is at 5V the board has to supply

(5V / 200 ohms) * 10 = 250mA

Which is over the spec, so I am in danger of damaging my board. Right?

So if I want to calculate the maximum current draw of the 10 LEDS being powered simultaneously with PWM, I have to assume that they are all getting 5V regardless of what I analogWrite to them. I do not actually have control over the voltage, I only have control over the resistance.

Thus in order to be safe I need to get some new resistors with resistance:

5V / 20mA = 250 ohms

Is this all correct?

  • Just to check, are you intending to connect all 10 LEDs directly to a single PWM pin? That would be a very bad idea. At best, it simply won't work. At worst, you'll fry something. (Each individual pin is only capable of sourcing a small amount of current.) May 31, 2014 at 22:49
  • Nope, separate pins on a Mega, thanks though.
    – Aurast
    May 31, 2014 at 23:04
  • The Mega can support 800mA total current, spread across the ports per the notes listed under Table 30 or 31 (I don't have a data sheet handy). VCC and GND pins can support 200mA each, there are 4 of each.
    – CrossRoads
    Apr 3, 2018 at 15:00
  • For reference: answers here recommend that a filter inductor should be added after PWM, to make it effectively a buck converter, which actually lowers the voltage. This way you can eliminate the need of a resistor. More details on buck converter design here. Apr 25 at 13:16

2 Answers 2


It's... mostly wrong. For three independent reasons.

The LEDs themselves, like all diodes, absorb some of the electrovoltaic potential of the electricity passing through them, resulting in a voltage decrease in their circuit. This means that although 5V is being used to power the resistor and LED in a circuit, only some of that voltage is passing through the resistor. If we use a typical (for blue, white, and other exotic colors) forward voltage (Vf) of 2.8V, this means that the resistor only has 2.2V across it. For a 200ohm resistor, this means that only 11mA is passing through the circuit. If you want 20mA to pass through the LED you need to use a resistance of 110ohm instead.

Second, the voltage from the MCU pins themselves depend on the current passing through them. Section 32.7 of the ATmega2560 datasheet, "Typical Characteristics - Pin Driver Strength" has charts for voltage versus current for both sourcing and sinking current; at 20mA the voltage drops to about 4.5V, which means that the resistance required for a 2.8V LED drops from 110ohm down to 85ohm.

Third, although semiconductors (i.e. the MCU and LED) can be damaged when too much current passes through them, it is not the current itself that causes the damage. The current passing through the voltage drop results in a consumption of power, and this power subsequently turns into heat. This heat then causes the breakdown of the semiconductor material. Even a junky, third-hand LED can take bursts of current up to 35mA or so without being damaged, provided the duration is limited. With a PWM signal this duration is directly linked to both the frequency and the duty cycle of the signal. You will need to see the datasheet for the LED in question to figure out what the maximum safe current and duration are, but the implication is that if you keep the frequency high enough and the duty cycle low enough, you can get away without any resistor at all and both the MCU and LED will survive.

  • This goes deeper than I thought xD So the actual current being pulled from the Arduino is ((5V - forward voltage) / resistance)?
    – Aurast
    May 31, 2014 at 23:03
  • It will be close to that. See the second point. May 31, 2014 at 23:05

Note that PWM does not actually drop the output voltage. It generates variable length pulses of 5V at different "duty cycles" (percent on vs percent off).

For an LED you might get away with using PWM to vary the power that passes through the LED since it can probably tolerate over-current for brief intervals.

What you should really do is calculate resistor value based on LED voltage drop and maximum current:

Say you have a red LED with a 1.8V voltage drop.

5V supply - 1.8 LED voltage drop = 3.2 V If the LED can handle a max of 15 mA, that would be 3.2/.015 ≈ 213Ω. Round up to the nearest 10% resistor value, 220Ω. That would give you about 14.8mA through the LED, slightly less than it's max.

If you then power the LED through a PWM pin, running the analog output at max will drive the LED at max brightness, and lower analog output levels will make the LED appear dimmer. Note that the LED will actually be rapidly flashing between full intensity (limited by your current limiting resistor, assuming you have one) and off. Our eyes average out that flashing light and see it as being a dimmer, constant light.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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