Light Emitting Diodes (LEDs)

Update: Feb 21st, 2010

Introduction

Often time circuits need some kind of simple visual indicator, for this LEDs are very common. They run on relatively low power levels, 5V and below, with a small amount of current. However if they aren’t used properly they can cause problems, or burn out. This guide will cover all the common things you need to know for using LEDs and seven-segment displays.

What is an LED?

An LED, or Light Emitting Diode, is a semiconductor device that emits light when current flows, much as the name suggests. As the name also suggests it has the same function and characteristics of a diode, including only allowing current flow when forward biased, and have a relatively fixed voltage drop across the component.

What can I use them for?

They are commonly used as indicators on electronic circuits, or assembled in to patterns to display letters and numbers (See seven-segment displays). They can also be used with a photodiode or photoresistor to make sensors that respond to objects passing in between the components. Many home alarms use an infrared LED with an infrared detector, so that an intruder walking by will “break the beam”, blocking the IR light from reaching the sensor, indicating the presence of something there. Optical encoders are based on a similar principle, by detecting when the beam is interrupted by a spinning wheel or gear, the rotation rate of that item can be calculated, and the amount of rotation measured.

Why do they only work in one direction?

As mentioned earlier, LEDs are in fact still diodes. While they sometimes may have a higher voltage drop than common diodes, they otherwise behave exactly the same. Diodes must be forward biased to conduct current, meaning that the voltage on the anode (positive) side of the diode must be higher than the voltage on the cathode (negative) side. The minimum amount the anode voltage needs to be above the cathode voltage is the diode voltage drop.

Why do my LEDs keep burning out? (Current Limiting Resistors)

Since the voltage drop of the diode is relatively fixed, it needs to force the input voltage down to that level. According to Ohm’s Law, the resistance multiplied by the current flow of the circuit is directly related to the voltage drop, so the LEDs will pull the current needed to drop the voltage down to it’s drop voltage across the resistance of the wire connecting the LED to power. Since wires are by definition, very low resistance devices, this oftens leads to very high current flow. Oftentimes the power supply cannot supply the current, and the voltage drops as a result of a load on the power supply. This is still likely too much current for the LEDs and without something to restrict it, it will get damaged rapidly, if not immediately. By putting a resistor in line, you limit the current flow to whatever is needed to make the resistor drop the voltage down to the LEDs drop voltage. To select the proper resistor, Ohm’s Law can be used in conjunction with the LEDs documented parameters. For example, for an LED on a 5V circuit, that has a maximum current of 80 mA, with a 1.5V drop, you calculate the resistance as follows:

R_{LED} = \frac{5V - 1.5V}{0.08} = \frac{3.5V}{0.08} = 43.75 \Omega

In this case you’re unlikely to find a 43.75 ohm resistor, so you’ll need to round to next available value. I recommend rounding up each time, because then you’re staying within the tolerances of the device. While the LED could likely handle a bit more current than the specified 80 mA, it is unlikely your power source is exactly 5V, likely it is a little above, which would cause greater current flow, so leave your safety margin for that. In this case I’d select a 47 ohm resistor, this is also a specification for a Super Bright LED I have on hand, so the values are higher for drop voltage and current than most LEDs. Once again, always check the datasheets!

Anodes, Cathodes, what is this nonsense?

Anode and Cathode are terms to indicate the terminals on a semiconductor device that current enters and leaves the device respectively. In the case of LEDs these are the positive and negative leads. Many LEDs have one lead shorter than than the other to distinguish, however there is no standard for which leg is shorter, once again defer to the datasheet!

How big an LED should I get?

LEDs come in many shapes and sizes, but the most common are the cylindrical dome kind and they tend to come in 3mm, 5mm and 10mm sizes. There is a general trend in brightness, and current consumption increasing with size but that is not a hard rule. Always check your LED datasheets for the relevant values. For most projects 5mm tends to work well. Experiment with a few different types.

Typical 5mm Red LED

Typical 5mm Red LED

What about those number things? (Seven segment displays and decoders)

Many devices have seven segment displays, these display numbers and often some letters using 7 LED bars arranged in a pattern like a digital number 8. This allows it to show 0 to 9, and A through F, as well as a few other things. They tend to come in two flavors, common anode and common cathode.

Common Anode Displays

These displays have 8 pins on them, one for the cathode of each segment of the display, and the final anode for each of them. These can be controlled to illuminate any of the segments, and a decoder chip can convert a 4-bit BCD number in to a 7-bit control signal to drive the digits.

Common Cathode Displays

These are basically the same as the Common Anode Display, but the first 7 pins are the anode instead, and one cathode for each. There are also decoder chips designed to drive these displays in a similar way.

Decoder Chips

Decoder chips, such as the common 74LS47 and 74LS48 take in a 4-bit BCD number and output the necessary control signals. These chips are usually capable of sourcing or sinking the current needed to drive the segments as well as decoding the numbers in to the appropriate control signals. These chips are very useful for interfacing a micrcontroller to a seven-segment display because it reduces the current strain on the microcontroller as well as the GPIO pins needed.

74LS47 Diagram

74LS47 Diagram (from Datasheet)

How do I use them? (Example circuits)

There are many different types of circuits that can be used, but here I’m going to outline some of the most common. Each circuit example will have a schematic and a brief explanation of how it works. While they’re all based around a microcontroller, any logic device with digital output pins could be substituted.

Microcontroller sinking current

Microcontroller sinking current from LED

In this circuit the microcontroller (an ATmega8 in this case) is sinking the current from the LED in to one of it’s GPIO pins. Sinking current means it holds the pin voltage low and the current flows from VCC, through the resistor, the LED and in to the microcontroller, which dumps it to ground. When the microcontroller drives the pin high, the voltage difference across the diode becomes nearly 0V which is not enough to bias it, so no current will flow and it will not light.

Microcontroller driving LED with transistor

Microcontroller driving LED with transistor

In this circuit the microcontroller (another ATmega8) is sourcing a small amount of current in to the base of a 2N2222 NPN transistor, which is being put in to saturation and conducting a large amount of current through the resistor and LED to ground. In this case the LED lights when the microcontroller drives the pin high instead of low. This circuit is useful if your microcontroller can neither source nor sink the current needed to drive the LED. Also, if using a common cathode seven segment display, the microcontroller must be able to source the current either directly or through this transistor to control it directly if a decoder is not used.

Microcontroller driving Seven-Segment Display with 74LS47 decoder

Microcontroller driving seven segment display with decoder

In this circuit the microcontroller (the ever popular ATmega8) is driving 4 outputs in to a 74LS47, which decodes the 4 bit BCD number and drives the 7 segment common anode display. You could use a 74LS48 as a drop in replacement to drive a common cathode display as well.

  1. MattKrass.com » Next guide!
    Feb 21st, 2010 at 05:17
    #1

Switch to our mobile site