LED Circuits for Dummies

by John J. Smith on Saturday September 27th, 2014 02:21 AM

OK... so the "dummies" part of the title is a little extreme. You really don't need to be a dummy to forget about the basics of one of the simplest of all circuits. The problem is that the concept is too simple. Often enough, an LED circuit is done badly, even though the very same engineer has done a bang-up job on an extremely complicated circuit on the very same board.

I've seen so many goofy LED circuits that have come from so many competent, experienced engineers that I thought it worthy of a little online advice. On this page, you will find some extremely simple designs, with a few caution flags thrown up around some of the more common mistakes.

Your First LED Circuit

Simple LED Circuit
Figure 1: A basic LED power indicator

Simple isn't it? It's just voltage applied to the LED, with a resistor to limit the current. No rocket science here. All of the calculations can be done using Ohm's law and a 4-function calculator. If you're good enough, you can do it in your head.

The arrangement of the components in this circuit is not important. If we put the resistor between the LED and ground instead of between the LED and V+, we will get the same results. The only important things in the design are that the current must flow through the LED in the correct direction, and that the resistor must restrict the flow of current. Everything else is just a personal preference.

The simplicity of Figure 1 can be deceptive. Most people would be surprised at how often it is done horribly wrong. The most common error is to connect the LED backward. The next most likely error is to ignore the voltage drop across the LED when calculating the value of R1. Another common mistake is to make assumptions about the value of the diode drop and desired current. Years ago, these assumptions wouldn't cause too many problems. Nowadays, the they can be fatal. More on that later.

The correct way to calculate the value of R1 is to look up the value of the forward voltage drop (usually referred to as Vf) for our chosen LED and subtract it from V+. This value is the amount of voltage that will need to be dropped across the resistor. Next, you will need to determine the amount of current through the LED that will result in the desired brightness. If unsure, it is always safe to use the value listed as "typical" by the manufacturer. Finally, we use Ohm's law and plug the voltage value into the formula R=V/I. Done... next problem.

To use a real world example, lets set up an LED as a power indicator light for a +3.3V system. The circuit in Figure 1 is all that is needed. We'll use a green LED with a Vf of +1.8V and a typical current of 10mA. Just for the sake of argument, lets say that the brightness of this LED at 10mA is 8 mcd.

So... in our theoretical circuit, what is the value of R1? Easy:

R1 = (3.3V - 1.8V) / 0.01A
R1 = 1.5V / 0.01A
R1 = 150 Ohms

But a green light is so 80's. All of the cool kids are using blue LED's for their power indicators. Lets look up the values for a similar blue LED. A quick trip to the online catalog gives us a suitable blue LED with a typical operating current of 20mA, a brightness of 6mcd, and a VF of 3.5.

R1 = (3.3V - 3.5V) / 0.01A
R1 = -0.2V / 0.01A
R1 = -20 Ohms

Oops. It looks we can't use this blue LED with a Vf of 3.5V as a power indicator for a 3.3V system. The truth is that the LED will probably light up if you use 0 Ohms for R1. Unfortunately, it may be dim, and it's brightness can fluctuate with slight changes in voltage. Because we really can't control the current through the circuit without a resistor, it's a good idea to stick to red or green for 3.3V and save blue or white for 5V and higher... Unless we know someone who will sell us a -20 Ohm resistor.

This is the reason why we shouldn't make assumptions. Historically, the Vf of red, green, and yellow LED's were in the same 1.7V ballpark. Many circuits were designed so that the colors were interchangeable on a whim. Since the variations were small, nobody noticed the difference. The recent addition of white and blue LED's with Vf values above 3 volts mean that it is now vital to check the specs more closely, and to specify the colors and part numbers of the LED's.

Beyond the power indicator

Power indicators are nice, but LED's are useful for lots of other applications. Most of these applications can be thought of as lighting the LED when someone or something completes the circuit. The pushbutton circuit in Figure 2 is a good way to represent this concept.

Switched LED Circuit
Figure 2: A basic switched LED circuit

When the pushbutton of Figure 2 is open (not pressed), the circuit is not completed, there is no current flow, and the LED is off. When the pushbutton is closed (pressed), it completes the circuit, and everything behaves exactly like it does in Figure 1.

Theoretically, the pushbutton can be used to open/close the circuit at any point. However, this isn't always a good idea. A pushbutton can leave it's leads exposed to possible accidental connections, especially if it is not mounted directly to the board. Putting the pushbutton in the circuit as it is in Figure 2 exposes only the ground and a power lead that is protected by a reverse-biased diode (the LED) and a resistor. Both of these are far better than exposing an open power supply line. An additional reason is that Figure 2 can be used as a conceptual model for more advanced circuits.

Computer controlled LED's

Figure 3 is our first attempt to control an LED with a computer. Lets assume an LVTTL register driving the input, a V+ of 3.3V, and the same green LED used for Figure 1. Since we are relying on the output of a digital device for our input we'll have to make assumptions about the characteristics of the register. For now, we'll assume a VOL ('0') of 0.3V, and a VOH('1') of 3.0V. We'll also make the unrealistic assumption that the pin can supply more current than we need.

Register Controlled LED Circuit
Figure 3: A register controlled LED circuit

When a '1' (3.0V) is applied to the input, the voltage differential across R1 amd D1 (.3V) is not enough to overcome D1's Vf (1.8V). Under these conditions, no current will flow, and the LED is off. If a '0' (i.e. 0.3 V) is applied to the input, The differential across R1 and D1 is now 3.0V. This allows current to flow through the circuit and the LED turns on.

Of course, you still need to calculate the value of R1. This is easily done using Ohms's law as we did for Figure 1.

R1 = (3.0V - 1.8V) / 0.01A
R1 = 1.2V / 0.01A
R1 = 120 Ohms

Note that the difference here is that we need to change the voltage value to account for VOL. The small 0.3V difference is enough to make a difference in the value of R1. If we would have assumed that a '0' is the same as GND, we would have ended up with a current of 1.2V / 150 Ohms, or 8 mA. Though this would not have made the design invalid, it could have an impact on the brightness of the LED.

Even though this circuit is found on a great number of digital designs, it should be used with caution. Small variations in VOL can result in large variations in brightness. This is especially true when working with a low voltage supply. If your design requires a combination of a consistent LED brightness and a low voltage supply, this circuit should be avoided.

The most common mistake that an engineer will make when implementing Figure 3 is to ignore the maximum load current on the pin. If you are attached to a GPIO pin on a CPU chip, you might be limited to 2ma of current, resulting in a dim LED. In extreme cases, it is even possible to overload the GPIO pin enough to destroy it's output driver.

Another common problem is forgetting to check what a 1 or 0 value really means. Often enough, a GPIO pin will be capable of delivering enough current to drive the LED, but it will not be able to reliably pull the pin low enough. This will result in a lower current and possibly an inconsistent brightness. If you know the exact output voltage of the pin at a given current, you can try to compensate using a different resistor value. Unfortunately, the rare occasion when a chipmaker specifies an output curve, it is given as a wide range.

Another consideration is the effect that driving current through the LED will have on the reliability of the output pin. In you are using a stand-alone GPIO register that is designed for this purpose, you are probably safe. If you are using the GPIO pin on a CPU chip, you may want to consider giving the pin a little help driving the required current by using a boost transistor. Figure 4 shows how a NPN bipolar transistor can be used to do this.

Register controlled LED Circuit with current boost transistor
Figure 4: A register controlled LED circuit with current boost transistor

From a high level perspective, this circuit is really just a combination of the circuits in Figure 3 and Figure 2. Q1 takes the place of the pushbutton in Figure 2. When the register output is '0' (0.3V), the transistor is off, no current flows, and the LED is off. When the register value is at '1' (3.0V), the transistor is turned on shorting the collector to the emitter (well, almost), current flows through the circuit, and the LED is on.

For our purposes, we'll be assuming a really wimpy 2mA register output that has a Voh of 3.0V nad a Vol of 0.3V. A pin with such specifications would justify the addition of a boost transistor, and you can find a few real-world examples with similar numbers.

Choosing Q1 takes a few steps. First of all the, the transistor must be able to handle the amount of current we will be asking it to sink. It's good to leave a margin of safety for this of at least a factor of 2. We'll be requiring 10mA through the LED, so we need something with an Ic max of > 20mA.

Next, we need to make sure that the transistor is driven into saturation (turned on "hard") when we want the LED to go on. We can insure this by choosing a transistor with a HFE value that would be sufficient to amplify our base current (2 mA) to five times the amount of current that we would need. Using this simple rule-of-thumb, the formula works out to HFE = (5 * IC) / IB. In our case:

HFEmin = (5 * 0.01A) / 0.002A
HFEmin = 0.05A / 0.002A
HFEmin = 25

There are two things to make note of here. First of all, driving the transistor into saturation is going to have a significant impact on its switching speed. If this circuit were used in some sort of signalling application where output latency is important, we would want to re-calculate all of the values to keep the trnsistor in its linear region. Since we just want the LED to wink at humans, switching speed is unimportant.

The second thing is that Hfe is generally specified as a range. We will be looking for the specified minimum Hfe. Also, once saturation occurs, Hfe is out of the picture. For our purposes, we are just using it to determine our boundary conditions.

Next, we consult our online catalog and find something that fits our requirements. We're looking for something with minimum HFE > 25, maximum IC > 20mA, max voltage > 3.3V, and whatever packaging and cost constraints we need to worry about. Since all of these numbers are extremely reasonable, there are hundreds of choices available. For our example, lets say we chose one with an IC max of 100mA and a minimum HFE of 110.

Now that we know the gain of our transistor, we can use it to calculate the required base current (IB). With an IC value of 10ma, and a minimum HFE of 110, our IB is (5 * IC) / HFE or:

IB = (5 * 0.01A) / 110
IB = 0.45 mA.

If we've followed the plan so far, we've chosen a transistor that will have no trouble with this base current.
Just to make sure, check the specs again.

To complete the calculations, we can plug the new current value into the formula R = (Vsupply - VBE) / IB to determine the value of R2:

R2 = (3.3V - 0.7V) / 0.00045A
R2 = 2.6V / 0.00045A
R2 = 5778 Ohms

Looking at our trusty online catalog, we find that the closest 5% tolerance values are 5.6K and 6.2K. Either one should work just fine, since we have allowed ourselves a reasonable safety margin.

It isn't difficult at all to design a proper LED circuit if we pay attention to a few details. It isn't rocket science, and it is far more simple than trying to set up a high-speed bus. Unfortunately, many engineers run through the LED design so quickly that the resulting circuit is embarassingly bad. Don't let yourself be one of them.

There are 2 comments

Sunday September 27th, 2015 09:35 AM by Krnnichi

With every Arduino project that aciteatvs a relay which is connected via a TIP120 transistor to a 12 volts psu, the base resistor suggested is 1K. Using your calc:collector current=5 amphfe=1000supply voltage=12vvbe=2.5vthen base resistor=1.9kWhy? Am I doing something wrong? Should I use a 2k instead?Best regardsKenneth

Wednesday October 28th, 2015 10:57 AM by Ojieyan

Dear electronic,I wtnaed to build your own Variable Regulator 0-30V 5A by LM723, CA3140, 2N3055 but there are inconsistencies between the PCB and the schema, namely:1) R11 = 150 ohms connected to pin 4 or pin 6 of CA3140?2) P1 (current) = 50k (scheme) or 5k (PCB)?3) R7 = 100k (scheme) or 10k (PCB)?4) pin 5 of the mass of uA723 18V with pin 7 (schema) or only R14 and R17 (PCB)?5) R13 = 1.5 ohms (schema) or 1.5 k (PCB)?Many thanks to those who answer me solve my doubts.Thank you sincerely.

Add Your Comment

Note: This is an anonymous comment page, so we've taken drastic measures to eliminate spamments. Any comment that looks like it contains a link (href=[anything]) or a URL ([anything]://[anything]) will be shunted to a secondary page, where you will have the opportunity to remove the unallowed text.

General references to web sites or pages that would not result in an SEO-friendly link (i.e. www.example.com/index) are allowable. All tags will be automatically stripped

Name (optional) :

Email (optional, not publicly displayed, but available to post author for offline discussion):