How to Drive Multicolor LEDs
Original Title：How to Drive Multicolor LEDs
Light emitting diodes (LEDs) are an easy and cost-efficient means of providing status information. However, for some projects, one single-color LED may not be sufficient, while multiple LEDs can be impractical due to space, cost, or power constraints. For these situations multicolor LEDs provide an effective solution provided they are properly interfaced to a microcontroller.
This article will explain the basics of LEDs and discuss the advantages of multicolor LEDs before introducing suitable multicolor LED solutions. Finally, it will show how the LEDs can be interfaced to a microcontroller to produce up to 16 million different colors.
Treat LEDs as diodes
When designing a circuit with an LED, it’s important to remember that these devices are not incandescent light bulbs, but semiconductor devices—diodes—that happen to emit light. As diodes, they typically only permit current flow mostly in one direction (diodes are not ideal, so they do exhibit some small amount of current flow when reverse biased).
The light emitting portion of a common LED is a simple semiconductor diode at the center of the assembly, composed of a single p-n junction (Figure 1). Current flows from the LED’s anode, which is connected to the p-type silicon, to the LED’s cathode, which is connected to the n-type silicon. In common diodes the p-n junction is usually germanium (Ge) or silicon (Si). However, for LEDs, the junction is typically transparent gallium arsenide phosphide (GaAsP) or gallium phosphide (GaP) semiconductor material.
Figure 1: An LED assembly houses the semiconductor p-n junction die, which allows current to flow from the anode to the cathode. A clear housing with a lens allows the resulting emitted light to be easily seen by the user. (Image source: Wikipedia)
With transparent GaAsP or GaP, the forward voltage applied across the p-n junction releases photons from the semiconductor. The p-n junction is mounted on a reflective cavity that focuses the photons toward the lens of the LED. The lens and body of the LED are composed of a clear epoxy that can optionally be colored to match the color of the emitted light.
The reflective cavity rests on a leadframe called the anvil, and the cathode is connected by a bond wire to a lead frame called the post. The anvil and post are shaped so that they form a strong connection with the LED epoxy body so that the anode or cathode pins can’t be pulled out of the LED epoxy body, destroying the LED.
LEDs are available in many colors, including red, green, yellow, amber, cyan, orange, pink, purple, and more recently white and blue. Single-color LEDs have a semiconductor die composed of a material that generates the desired wavelength of light, with the LED epoxy housing assembly often having the same color. While having the lens the same color as the emitted light isn’t necessary, it is important for easy identification of the color of the LED component to prevent confusion with other LEDs.
For some systems where space, cost, and power are constraints, it is an advantage to have one LED that can transmit more than one color. Usually these multicolor LEDs have three LEDs, a red, a green, and a blue (RGB) inside a single clear epoxy housing. A good example is Adafruit Industries’ 2739 RGB LED (Figure 2). Designed for multicolor indicator lights, it has a rectangular lens emitting surface measuring 2.5 mm wide by 5 mm high and comes with four radial leads for through-hole mounting on a pc board.
Figure 2: The Adafruit 2739 RGB LED has a clear epoxy rectangular lens measuring 2.5 mm wide by 5 mm high. It comes with four radial leads for through-hole mounting on a pc board. (Image source: Adafruit Industries)
Typically, any of the three internal LEDs can be used individually or in combination with the others to produce different colors.
Multicolor RGB LEDs are commonly available in three pinouts:
One common anode for all the LEDs, with each individual cathode available for a total of four pins
One common cathode for all the LEDs, with each individual anode available for a total of four pins
Each individual anode and cathode are pinned out for a total of six pins
Designing with multicolor LEDs
The Adafruit 2739 RGB LED has a common anode with each of the cathodes for the red, green, and blue LEDs individually pinned out for a total of four pins (Figure 3). The common anode is connected to the positive power supply, while each of the individual red, green, and blue LEDs are switched on by connecting them to ground.
Figure 3: The Adafruit 2739 RGB LED has a common anode with a separate cathode for the red, green, and blue LEDs. (Image source: Adafruit Industries)
Generating many colors
If an application only needs to display one of three states, then the simplest way to use the 2739 RGB LED is to just turn on one LED at a time, giving the user a selection of red, green, or blue.
For a greater variety of colors, a designer can simply combine two colors together, giving the following six color options:
Yellow (Red + Green)
Cyan (Green + Blue)
Magenta (Red + Blue)
For clear project documentation the colors displayed should be distinct, easy to recognize, and easy to verbally identify. For example, a green LED with full current may be documented in an LED data sheet as “lime.” However, when the LED is lit, most consumers and developers when asked, would identify the color as “green”. Regardless of the actual name of the color, users should be able to easily distinguish between the different colors both visually and by label. Few people can readily identify the difference between “green” and “lime”, and if both colors are presented side by side, may instead identify lime as “green”, and identify green as “dark green”.
For more complex applications, the RGB combinations can be varied in intensity to generate up to 16 million colors. A reliable method of doing this is by applying a pulse width modulated (PWM) signal to each of the LEDs, where the duty cycle corresponds to the intensity. The human eye can identify flicker that is 200 hertz (Hz) or slower, so to avoid flicker, a PWM frequency of 1000 Hz or faster should be used.
Colors can be easily selected by their RGB color code. This is based on the RGB additive color model where red, green, and blue light are individually varied in intensity and combined to reproduce almost any color. This model applies to light and is the basis for color reproduction in televisions and displays. It is also used to represent colors on web pages.
The shorthand for an RGB color code is represented as (R,G,B) where R, G, and B are the decimal values for the red, green, and blue intensity of the color ranging from 0 to 255. For example, the decimal RGB color code for blue is (0,0,255), purple is (128,0,128), and silver is (192,192,192). When determining the PWM duty cycle for each color, these values are divided by 255, so the duty cycle values for blue would be (0,0,100%), purple is (50%,0,50%), and silver is (75%,75%,75%).
Theoretically, white light is represented by (255,255,255) and can be generated by simultaneously turning on the red, green, and blue LEDs with full intensity. However, in practice, the color produced by this method is usually white with a bluish tint. This tinting occurs because the LED colors generated are not an exact match for the precise wavelengths of perfect red, green, and blue.
The required PWM signals are easily generated by a microcontroller. A suitable example is the ATSAMC21J18A from Microchip Technology (Figure 4). This is a low-power device for IoT endpoints and is part of the company’s SAM C21 microcontroller family. It has a 48 MHz Arm® Cortex®-M0+ core and supports 5 volts for I/O.
Figure 4: The ATSAMC21J18A microcontroller has timer/counter units capable of auto-generating three synchronous PWM signals. (Image source: Microchip Technology)
To drive the LEDs, the ATSAMC21J18A has timer/counter units capable of auto-generating the three synchronous PWM signals. The SAM C21 family has a high sink option that allows four I/O pins to each sink a maximum of 20 milliamps (mA).
When using an LED, it is important to select the correct series resistor to limit current flow. A resistor with a value that is too low can destroy the LED, while a resistor with too high a value can result in dim or no light. The value of the series resistor is determined by each LED’s forward voltage and the desired current flow.
LEDs are current controlled semiconductors. Also, it’s important to note that due to the physics of the materials, the operating voltage of the LED increases as the wavelength of the emitted light decreases. This is an important factor to consider when using multiple LEDs.
With a forward current of 20 mA for the Adafruit 2739 RGB LED, the specified typical LED forward voltages from Adafruit’s charts are 2 volts for red, and 3.2 volts for both green and blue.
If the common anode is connected to 5 volts, then the resistor values between the LEDs and the I/O pins are determined by the equation:
Equation 1 Equation 1
VDD = 5 volts
VOL = Output low voltage for the ATSAMC21J18A = 0.1 x VDD = 0.5 volts
VF = forward voltage (typical)
I = forward current in amps
R = resistor value in ohms (Ω)
Applying this formula for I = 20 mA results in RRED (VF = 2 volts) = 125 Ω, and RGREEN = RBLUE (VF = 3.2 volts) = 65 Ω.
If a calculated resistance is not available as a standard resistor value, the developer could either choose the next lower value, or the next higher value (preferred). Care must be taken if selecting a lower value so as to not exceed the maximum forward voltage for that LED or the maximum current sink capability of the ATSAMC21J18A’s I/O port. While the LED may still operate if these maximums are exceeded, there is a risk of decreasing the life of the LED, or over time degrading or destroying the I/O port. Optionally, the forward current can be decreased, provided the dimmer light is still acceptable to the application. For example, at a forward current of 15 mA, the specified forward voltages for the Adafruit 2739 RGB LED drops to 1.9 volts for red, and 3.1 volts for green and blue. This results in resistor values of RRED = 173.3 Ω, and RGREEN = RBLUE = 93.3 Ω.
As the ATSAMC21J18A would be controlling the LEDs by controlling the connection to ground, an individual LED is on when the I/O port is a logic low, and off when at a logic high. For this reason, the calculated RGB color code duty cycles must be inverted. For example, if a color requires a 25% duty cycle, the PWM must generate a 75% duty cycle for the LED to be on 25% of the period time. In addition, if the LED must be off on power up, the microcontroller startup code must enable the three pins to a logic high.
The ATSAMC21J18A comes with 256 Kbytes of flash memory, 32 Kbytes of RAM, and a variety of analog peripherals. The microcontroller also has six serial communication modules (SERCOMs), each capable of acting as a USART, SPI, LIN slave, or I2C interface.
Smart RGB LED
An alternate way of generating multiple colors with an RGB LED is to program it. Smart LED is a term used to describe this type of multicolor LED that comes with a programmable serial interface. A good example is American Bright Optoelectronics' BL-HBGR32L-3-TRB-8, a 5 mm square RGB LED that can be programmed to generate any color using an 800 kilohertz (kHz) I2C interface (Figure 5).
Figure 5: American Bright’s BL-HBGR32L-3-TRB-8 is a 5 mm square six-pin digital RGB LED with an I2C pass-through pinout that allows multiple devices to be daisy chained on the same I2C interface. (Image source: American Bright Optoelectronics Corp.)
The convenience of the I2C interface greatly simplifies design by saving board space and simplifying microcontroller code. One of the SERCOM ports on the ATSAMC21J18A can be configured as an I2C serial interface to easily interface to the BL-HBGR32L-3-TRB-8. Referring to the pinout in Figure 5, the I2C data signal from the ATSAMC21J18A microcontroller is connected to the pin 1 Data In signal, and the I2C clock to pin 2 Clock In.
The color of the BL-HBGR32L-3-TRB-8 LED is programmed by sending four bytes representing the global brightness setting and the RGB color codes as one 32-bit word. The smart LED has data output pass through on pin 6, as well as an I2C clock pass through on pin 5. This allows multiple LEDs to be daisy chained together so that each LED can display a different color.
With an understanding of how to drive them, multicolor RGB LEDs can save space, cost, and power, while enhancing the aesthetics and user interface of an end system, device, status indicator, or lighting system. Developers can select between standard RGB LEDs that allow complete control over each of the LEDs, or smart LEDs that provide programmable control of the colors. Also, there are many low-power, low-cost options when it comes to the microcontrollers typically used to generate PWM control signals.
KEY COMPONENTS TABLE
1.The content, data, charts, etc. of this article come from network reference or other public materials, and the copyright belongs to the original author and the original published source. If the copyright owner has any objection to the quotation of this article, please contact ICZOOM "marketing(at)iczoom.com" and we will deal with it in a timely manner.
2.The quotes in this article are for readers' learning exchange only, and do not involve commercial purposes.
3.The content of this paper only represents the author's point of view. ICZOOM cannot gurarante and assure the accuracy, reliability or integrity of the content. The decision or behavior made by readers after reading this article is based on their own will and independent judgment. Please clarify the relevant results before reading this article.
4.Please contact ICZOOM "marketing(at)iczoom.com" with the reason of reproducing if you want to reproduce the articles that ICZOOM owns the copyright. Without permission to reproduce, ICZOOM will reserve the right to pursue the legal liability.
5. If there is any inconsistency between the English and Chinese versions, the Chinese version shall prevail.
ICZOOM has the final right to interpret this statement.