Driving LEDs on higher voltage

For various reasons it is often necessary to control LEDs supplied by a voltage higher than the micro-controller can supply or withstand. In these cases the most common solution is to use an NPN transistor as a switch or driver to buffer between the two parts of the circuit – the low-voltage control circuit and the high-voltage load circuit.

NPN transistor switch.
An NPN transistor can be used to act as a switch controlled by a low-voltage micro-controller switching a high voltage or high-current load.

When there is no current flowing into the base (b) of Q1 the transistor is off and no current flows from the collector (c) to the emitter (e). As we increase the current into the base of the transistor the transistor starts to turn on and its resistance falls allowing current to flow from Vss, through R2, D1 and Q1 to ground.

Small signal transistors have a “current gain” of 50 to 300. This means that for 0.1 mA into the base we should be able to get 5 to 30 mA to flow through the collector. The relationship is given by the equation \( I_C = h_{FE}I_B \) where \( I_C \) is the collector current, \( h_{FE} \) is the current gain and \( I_B \) the base current.

At first glance it seems that we could control the LED current to any value we wanted by controlling the base current. Unfortunately there is enough variation between transistors and the fact that this parameter is temperature dependent that this would not be a good reliable and repeatable design. (It might be OK for a one-off project provided you were confident you would never have to replace the transistor.)

Instead we inject more than enough current into the base to turn the transistor “hard” into saturation: the collector voltage drops as low as it can go – typically below 0.2 V.

Example 1 (NPN driver)

  • Our micro-controller output is a 5 V signal.
  • Vss is 12 V.
  • The LED, D1 requires 100 mA and will have a forward voltage of 2.8 V at that current.
  • Q1 has a \( h_{FE} \) of somewhere around 100.

R1

We want to ensure that the transistor saturates to give minimum voltage drop between the collector and emitter. In saturation we’ll assume that a current gain of 10 to 20 is likely. To guarantee saturation we should design for a base current of 5 to 10 mA. This will be fine for most micro-controllers (but always check the specification). The base voltage will rise to about 0.6 V when forward biased so the voltage across R1 will be 5 – 0.6 = 4.4 V. We can calculate (from Ohm’s Law) \( R_1 = \frac {V}{I} = \frac {4.4}{0.005} = 880\,\Omega \) and it would be half of that at 10 mA. We can go somewhere in-between with a 560 Ω or 680 Ω resistor.

R2

\( \begin{align} V_{R2} & = V_{SS} – V_{LED} – V_{Q1} \\ & = 12 – 2.8 – 0.2 \\ & = 9\,V \end{align} \)

 

\( \begin{align} R2 & = \frac {V}{I} \\ & = \frac {9}{0.1} \\ & = 90\,\Omega \end{align}\)

 

High-side versus low-side switching

Simplified logic output.
Figure 1. Simplified logic output stage showing the high-side and low-side switches.

Most micro-controllers and logic families have output stages which can connect the output to the positive supply or to ground. This allows the micro to put a definite ‘high’ (+5 V in this example) onto the output or a definite ‘low’ (ground) rather than let it float which could cause problems if the output is feeding into another device. Naturally, only one of the switches should be closed at any time. In this article we look at high-side versus low-side switching.

GPIO sourcing current for LED.
Figure 2. To power an LED connected to ground the micro simply connects the output to positive supply. In this configuration we use the upper transistor in the output stage to supply current to the output – much in the same way as S1 in the equivalent circuit.

Most micros can now source 10 to 20 mA safely on their GPIO1 pins. This is ample current to light an LED brightly. All that is require is to decide whether to source current for the LED or sink current.

Micro sinking current from LED.
Figure 3. To power an LED connected to positive supply the micro simply connects the output to ground. In this configuration we use the lower transistor in the output stage to sink current from the LED to ground – much in the same way as S1 in the equivalent circuit.

 

Some more detail

The switches in real devices will be constructed with transistors. These are imperfect and have various limits that we have to be aware of, such as maximum current and source resistance. For example, the ATmega328P used in the Arduino Uno states that the IO pins can handle up to 40 mA subject to a maximum total of 200 mA for the whole chip.

ATmega328 maximum current ratings.
Figure 4. The absolute maximum current handling capability of the ATmega328 and 328P micro.
At 20 mA the ATmega328P output is pulled up to 0.9 V above zero when low and about 0.8 V below positive supply when high.
Figure 5. At 20 mA the ATmega328P output is pulled up to 0.9 V above zero when low and about 0.8 V below positive supply when high.

Note on Figure 5 the \(V_{OL}\) voltage – the actual voltage measurable on the output pin (red) – when switched low and sinking 20 mA that the voltage won’t be zero as might be expected but could be as much as 0.9 V above ground. This is due to the voltage drop across the low-side transistor switch in the output.

Similarly, when the output is switched high and sourcing 20 mA the output won’t be +5 V (the test condition power supply voltage) but could be as much as 0.8 V below that.

It’s worth being aware of this as it could be significant in some low-voltage applications where there isn’t much “headroom” between the voltage required by the LED and that of the power supply.

Example 1 – 5 V supply

LED IV curve and calculation.
Figure 3. Using the LED IV curves to find the required R value for a green LED at 20 mA.

Figure 6 shows that the LED at 20 mA will have a forward voltage drop of about 2.2 V. If the supply voltage is 5 V then the resistor has to drop \(5 – 2.2 = 2.8\,\mathrm V \). The required value is \( R = \frac {V}{I} = \frac {2.8}{0.02} = 140\,\Omega \). The nearest standard value of 150 Ω will do fine.

The resistance calculation will be the same for the current sinking option of Figure 2.

Example 2 – 3.3 V supply

When running from a 3.3 V supply the headroom becomes substantially limited.

As the supply voltage is decreased to 3.3 V the "headroom" for driving an LED is reduced and, when output droop is taken into consideration, the device may not be able to provide enough current.
As the supply voltage is decreased to 3.3 V the “headroom” for driving an LED is reduced and, when output droop is taken into consideration, the device may not be able to provide enough current.

Here we can see that the LED is still requiring 2.2 V leaving 3.3 – 2.2 = 1.1  V for the resistor. If this 3.3 V chip’s output were to droop by, say, 0.5 V then that leaves us with only 0.6 V for the resistor: \( R = \frac {V}{I} = \frac {0.6}{0.02} = 30\,\Omega \).

The problem with this is that a low-value resistor is not a very good constant current source. If the forward voltage, \( V_F \) of the LED decreased by 0.1 V due to temperature or batch to batch variation then the voltage would go to 0.7 V and I would increase from 20 mA to \( I = \frac {V}{R} = \frac {0.7}{30} = 23\,\mathrm mA \). This might push the device a little closer to the absolute maximum ratings.

See all GPIO tricks.