John L Errington MSc

John Errington's Experiments with an Arduino

Driving LEDs

I'm often asked "what is the right value resistor to drive an LED from a digital output on the arduino". Well "it depends". It depends on (1) the supply voltage, (2) the current you choose to run through the LED, and (3) the LED forward voltage. That in turn depends on the colour of your LED.

driving led

I measured the forward voltage of some cheap LED's at a current of 10mA; 3mm and 5mm sizes showed the same values. Here are the results:

NOTE: for use as indicators indoors, red, orange and yellow LEDs AND white ones are typically acceptable at currents of about 2mA. Blue need a little more.

While common 3mm and 5mm leds CAN be run at 20mA and more, a maximum of 10mA is generally sufficient, and limits your consumption, especially if you have several inicator lights. (See below for limit of consumption on output ports.)

Green LEDs are MUCH less efficient than red - yellow ones, and need a higher current if their intensities need to match.

Colour Vf at 10mA Comment
red 2.0 bright
amber 2.0 bright
green 1.9 very dim
blue 2.85 dim
white 2.80 bright

There are two ways of connecting an LED to a digital output, as shown here left; whichever you choose you can get a suitable value for R from the table (table 1) below.

The logic gate box is just depicting a single arduino digital ouput pin.

 

Table 1 - giving the "right" resistor value for your project:

Supply voltage Vcc
LED colour
Current mA
Resistor
3.3
red-green
2.5
470
3.3
red-green
10
120
3.3
blue, white
2.5
180
3.3
blue, white
10
39
5.0
red-green
2.5
1200
5.0
red-green
10
270
5.0
blue, white
2.5
820
5.0
blue, white
10
220

Further explanation

The table above gives some "rule of thumb" figures. If you want to know how these were calculated , read on.

LED forward voltage

Here is a table (Table 2) showing the forward voltage for different LEDs in the common 3mm or 5mm package. Its compiled from various manufacturer's data sheets. If you need precise values consult the data sheet for the device you are using.

LED characteristicsYou can see that LEDs in the "warm" end of the spectrum only need low forward voltages, while some types in the "cool" end - green onwards - may need over 3.3V so you could not drive these directly from a 3.3V model arduino.

 

We also need to bear in mind the electrical characteristics of the arduino chip; each output is capable of sourcing or sinking 40mA; however "the maximum current for each I/O port should not exceed 100mA".

(32U4 data sheet page 379)

 

If we connected 8 LEDs drawing 20mA each to a single port we could be drawing 8*20mA = 160mA.

What current do you need?

Assuming you are using the LEDs as indicators, rather then e.g. for a light show, modern LEDs work very well at currents of 2-10mA, and a maximum of 20mA. Higher power LEDs will take more current, but then its better to use a ready-made LED driver chip.

What is the supply voltage?

The voltage available to drive your LED from a digital output is the difference between the voltage on the digital output pin and the forward voltage of the LED. The data sheet for the ATMega 32U4 gives the following MAXIMUM values (29.0 -29.2) for Vcc = 3.0 or 5.0V. The values I measured gor Vol were typically much lower - around 0.1V

Vcc
Iol or Ioh
Vol
Voh
5.0
10mA
0.7
4.2
3.0
5mA
0.5
2.3
3.3 *
5mA
0.55
2.6

* not on data sheet - extrapolated.

And finally - the calculation

Suppose we wish to drive a red LED with a series resistor, connected between a digital output pin and ground on a 5V Arduino. We choose a current of 10mA.

The voltage available to drive current through the LED is Vcc -Voh = 4.2V (- 0V) and the LED forward voltage (from the data sheet) is 2.1V at 10mA.

The voltage across the resistor Vr will be 4.2 - 2.1 = 2.1V

By ohms law (V / I = R where V=volts, I=Amps, R=Ohms) we get

R = 2.1 / 10 * 10^-3 = 210 ohms.

The nearest preferred value is 220 ohms.

Reference: Table 2