LEDs play a vital role in the design of interactive systems. Nearly all smart devices use LEDs in one way or another as part of their user interface. This can range from a simple power-on indicator to more complicated functions such as a notification LED on a smartphone. Discrete LEDs come in many different shapes and forms:
- Monochromatic LEDs emit a single color of light. They are available in a wide range of different colors, though their color is fixed. LEDs are polar components; they only conduct electricity in one direction.
- Bicolor LEDs contain two LEDs inside a single component. Red/green is a common color pair. Some bicolor LEDs have two leads, whereas others have three. Two-lead LEDs can only light one color at a time, whereas three-lead LEDs can light both at the same time.
- RGB LEDs are components that contain a red, green, and blue LED in the same package. By mixing these colors together, a wide range of colors can be displayed. RGB LEDs have four leads: one common lead plus one lead for each color. Two types exist: common-anode, where all the positive sides are connected to a common pin; and common-cathode, where all the negative sides are connected together.
- RGBA/RGBW LEDs add a fourth color to the component; amber and white respectively. This is done to improve the color spectrum of the LED. RGBA LEDs have improved warm tones, whereas RGBW LEDs have improved cool/pastel tones.
There are many different ways to drive LEDs. The simplest solution is use a single current-limiting resistor, whereas in lighting applications, LEDs are often controlled through a dedicated constant-current driver. However, in indicator applications, LEDs are often controlled directly from a GPIO pin of a microcontroller. Indicator LEDs can either be turned fully on/off, or pulse-width modulation (PWM) can be used to dim the LED. In recent years, companies have experimented with more complex LED animations, such as the breathing LED in Apple laptops or the LED ring animations on the Nest Protect.
The simplest, most cost-effective way to dim and animate LEDs is to use the PWM-capable pins of a microcontroller directly. However, PWM-peripherals are a valuable resource, and RGB LEDs can quickly eat through the available GPIO pins. For this reason, it can make sense to use addressable RGB LEDs instead. Addressable LEDs are LEDs with an integrated controller. They communicate through a bus system, so that many different LEDs can be addressed through the same microcontroller pins. Of course, addressable LEDs cost more than regular LEDs, but the simplicity of the built-in controller can be worth it in some cases.
The WS2812B LED is a popular family of addressable LEDs. Adafruit sells these LEDs under the NeoPixel brand name. They are available in various form factors, such as LED strips, rings, and breakout boards. Each WS2812B LED has a data-in and a data-out pin; these pins can be chained together from data-out to data-in to form a LED chain. By sending a specific control signal, each LED can be controlled individually. However, the WS2812B protocol requires a timing-specific control signal, which may pose problems in some cases (e.g. interrupts). Another option is to use the APA102-family of addressable LEDs, sold under the DotStar brand. These LEDs support a much higher data rate and are controllable through the SPI bus, which is a standard microcontroller peripheral. For Arduino-compatible microcontrollers, the FastLED library can be used to control various types of addressable LEDs, including WS2812B and APA102.