Using LEDs with Arduino

This site has been great fun, but it has run its course, and it is time to move on. Please get what you want from the site before January 1, 2020. Some pages will move to another site but most will go away.

Arduino LED tutorial.

An LED is not a little light bulb. It is a diode, which allows current to flow generally in only one direction. It happens that when the current is flowing the LED emits light. The light is incoherent, but narrow band, meaning it is mostly the same frequency but not al all marching in step, like a laser would be. Still, that is why LEDs have such intense colors.

You don't just hook them to a battery because they will instantly melt. They have no significant resistance to current flow, so lots of current will flow. To use an LED you must do two things. You must connect them to a source of voltage that is equal to or higher than their forward voltage. Forward voltage is the voltage across the LED when you hook up the power supply through a resistor. The forward voltage varies with the type of LED, and therefore the color of the LED. You must also connect a current limiting resistor in series with the LED to prevent it from allowing too much current to flow.

For a list of many LED's Vf and mcd@20mA, see the OkSolar LED Color Chart. It is the most comprehensive list I've seen.

All LEDs require a series resistor

You can directly drive an LED with an Arduino. Let's look at what happens when a red LED is connected between an output pin and ground. We'll assume the LED has a forward voltage of 2.1V, and is rated at 20mA. It is pretty common to see those numbers. But the output of the Arduino is 5V. The output of the Arduino is current limited at around 67mA. The current limit on the Arduino pin lowers the output voltage to 2.28V. Although the LED is lit, and very brightly, both the LED and the Arduino are operating far above their design limits. Either one could fail at any time.

Calculating the series resistor

LED for Arduino and Breadboards

The series resistor is chosen so that it drops the required voltage at the desired current. If you want to drive the LED with 10mA, the LED forward voltage is 2.1V, and the power supply is 5V, you have to drop 2.9V across the resistor:

2.9V ÷ 10mA = 290Ω

Calculating the series resistor for different LED efficiencies

It seems like many designs have a low value resistor in series with every LED. The result is a bunch of flashlights pointing in your eyes. A hypothetical high-efficiency red LED with a forward voltage of 2.1V, when connected to a 220 Ohm resistor with a Vcc of 5V will draw 13mA, and shine at 145mcd (milli-candles). Use that as a standard. Then take a blue LED with a forward voltage of 3.2V. Same 220 Ohm resistor and 5V supply will yield 8.1mA. Much less. But the blue LED is more efficient - 3000mcd at 20mA, or 1227mcd at 8.1mA - almost ten times as bright.

To size the resistor for multiple LEDs, you need to know a few things. Forward voltage is one. Candles/mA is another, and lastly, the applied voltage. Use the least efficient LED as the standard. Decide how bright you want the LED. Is it a solid-state flashlight? Is it used for illumination or for indication? Experiment. When you get that one right, the rest are a simple calculation away.

Although LEDs have a non-linear light output vs. forward current, below the specified current they are generally linear enough to use simple arithmetic to determine the resistor size.

Using the red and blue LEDs from above, we use the lower efficiency red as our baseline, and decide with a 5V supply we like it with a 330 Ohm resistor. The forward voltage is 2.1V, the current is 2.9V / 330 = 8.8mA. At 8.8mA, the output is

(220mcd/20mA) x 8.8mA = 96.8mcd

To calculate the resistor for the blue LED, we first find the brightness per mA,

3000mcd / 20mA = 150mcd

We only want 96.8mcd, so we divide the target brightness, 96.8mcd, by the brightness per mA, 150mcd/mA, to get the current, which is 0.65mA. The forward voltage of our blue LED is 3.2V, so the voltage across the resistor is 1.8V. The resistor required to drop 1.8V at 0.65mA is

1.8V / 0.65mA = 2.7k.

The two LEDs, even though they vary greatly in efficiency, are now the same brightness. That does not mean they appear to be the same brightness, though. The human eye is less sensitive at the blue end of the spectrum, and nearly as much at the far red end. You may want to adjust the numbers by 10% or so in favor of the blue brightness. You'll have to experiment, since not all blue LEDs are equally blue.

As an Amazon Associate I earn from qualifying purchases.
Arduino Board Logo


Arduino-Board is the go-to source for information on many available Arduino and Arduino-like boards, tutorials and projects.

Help and Support


Stay updated

Sign up if you would like to receive our once monthly newsletter.