Skip to main content

RGB LEDs

There are 2 types of RGB LEDs:

  • "Old" style are in fact 3 standard LEDs of each primary color packed in one component, with a common cathode or anode. You need to control each color like a simple LED, with a digital or analog (PWM) signal. This will use 3 pins on a microcontroller or on a dedicated LED controller IC.
  • "Addressable" style, which have a tiny digital controller embedded in the LED, and that you control with only one serial style signal. This type of LED typically needs only 1 pin to control intensity of all the 3 components, and so will use only 1 pin on your microcontroller. There's also an output pin which reproduces the input signal with a shift, so you can chain a lot of LEDs without needing more pins on your microcontroller. Although controlling this type of LED is more complex, you can control a huge amount of "pixels" with just one microcontroller pin, so these LEDs have become very popular.

Let's start with a simple example. Clear the project and add a Software Timer, a RGBStatus and a FastLed modules. Connect them together and configure the FastLed module with 1 LED and with the pin on which you connected the RGB LED (you can connect several LEDs, only the first one will be used). On the ElectroSeed SamD21 WB board for example, you can use the D12 pin, around which you'll find Gnd and 5v pins.

You should have something like this:

Unplug the board, plug your LED(s) on the board, and then plug the board again:

Upload the project, you should see the RGB LED blinking between red and green.

You should always unplug boards when you connect something to them, because there's always a risk of doing a short circuit when plugging a new device, which could damage the board or even the USB port of your PC. Always check your wiring twice.

RGB LEDs are supposed to be powered with 5V, especially if you have a lot of them in series, and/or if you want a lot of brightness, but they usually will work with 3.3V too. But be careful, the current you can draw from 3.3V pins on boards is limited by the on-board regulator, whereas 5V is limited by USB supply (500 mA on USB 2.0 ports, 900 mA on USB 3.0 ports). For example on ElectroSeed SamD21 WB board, the 3.3V regulator can output 500 mA max, on which 100 mA can be taken by the SamD21 MCU. This leaves 400 mA for the LEDs and other devices.

So if your project is USB powered, you should use 5V to power RGB LEDs, and if the project is wireless and not using a 5V booster, you can use 3.3V but with care.

Let's continue with a more complex example. Unplug the board, and connect several LEDs to the board (for example a 3, 8, 15 or 16 LED bar). You can chain several RGB LEDs/LED bars as long as they are using the same chipset (most common chipset is WS2812B). Connect Dout to Din between each module. The first module should have the Din connected to the board. For example:

Be careful, as you can see all the RGB modules don't have the same pin layout.

Remove the Software Timer and RGBStatus modules, and replace them with a Generator and a RGBLevel modules. Connect them together, and configure the FastLed module with the number of LEDs connected and with the pin on which you connected the RGB LED. Open the RGBLevel module, it should have the same number of LEDs that you've set in FastLed. Set the Generator frequency to 0.2 Hz, so you have time to see what happens. The project should now look like this:

Explore all the options of the RGBLevel. As you can see, it can be used as a level meter in many situations.

We will now continue our exploration of modules and explore digital inputs and outputs.