RGB LED
An RGB LED is three LED dies — red, green and blue — sharing one 5 mm package and one common leg. It costs $2 and gives you any colour you can mix with three PWM pins: status colours, a mood light, or a "traffic light" that needs only one part. Because the dies are wired together at the common leg, each colour still needs its own series resistor.
Pins
| Pin | What it is | Type |
|---|---|---|
| R | Red | passive |
| COM | Common (longest leg): cathode or anode | passive |
| G | Green | passive |
| B | Blue | passive |
| Setting | Type | Range | Default |
|---|---|---|---|
common | enum | cathode, anode | cathode |
COM is the shared leg (the longest one); the other three are the individual dies. Which way the dies point is the common setting: RGBLED("cathode") (the default) turns a die on with a HIGH pin, while RGBLED("anode") needs the pin LOW. common is positional and can also be written RGBLED(common="anode").
Wiring it in circuit.py
from wiring import *
pi = Pi()
rgb = RGBLED("cathode") # use RGBLED("anode") for a common-anode part
pi.GPIO17 >> Resistor(220) >> rgb.red
pi.GPIO27 >> Resistor(220) >> rgb.green
pi.GPIO22 >> Resistor(220) >> rgb.blue
rgb.common >> pi.GNDEach colour is wired like a single LED: one resistor from the GPIO to the die, then COM to the rail. With a common-anode part, wire rgb.common >> pi.V3_3 and let the GPIOs sink the current instead.
Driving it in main.py
from gpiozero import RGBLED
from time import sleep
led = RGBLED(red=17, green=27, blue=22) # active_high=False for a common-anode part
while True:
for colour in [(1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 1, 1), (0, 0, 1), (1, 0, 1)]:
led.color = colour
sleep(0.4)led.color takes values from 0 to 1 per channel and gpiozero drives each pin with PWM, so partial values mix smoothly.
Electrical notes
- Forward voltages at 20 mA: red 2.0 V, green 3.1 V, blue 3.1 V. The dies share a 12 Ω slope resistance and a 30 mA absolute maximum each.
- 220 Ω per channel is a good default from 3.3 V. Red then runs at about 6 mA; green and blue sit almost at the supply rail, so
(3.3 − 3.1) / 220 ≈ 0.9 mA— dim, and realistically why RGB LEDs want 5 V or a driver for full brightness. In the simulator they simply come out dimmer in the mix. - A common-anode part is on when its colour pin is LOW: tell gpiozero
active_high=False, or sink the pins yourself with RPi.GPIO. - Equal duty on all three channels seldom looks white, because the dies differ in efficiency; tune the mix.
- One die over 30 mA raises an
overcurrentwarning that fails the judge's damage check. Unlike the single LED, the RGB model has no burn-out option — it warns and keeps working.
Simulator vs real hardware
- Three independent piecewise-linear diodes, each with its own fixed forward-voltage offset within ±0.1 V.
- Red, green and blue glow layers are added on the canvas, so overlapping colours mix visually the way the real dies do — but with no phosphor or wavelength data behind it.
- PWM duty sets each die's average current, and the state (
red,green,blue) tracks it for objectives. - Real parts often have a common cathode or anode and different pin orders; the simulator's four pins map to one part in the shop, so check the settings if you swap in a real one.
Going deeper
- Primers: PWM and voltage, current and Ohm's law.
- Single-colour sibling: LED; the resistors still belong to resistor.
- Finished module: RGB LED module.
- The traffic light kit is the same idea with three separate LEDs.
Further reading
- Kingbright LED components — the manufacturer behind the 5 mm RGB part the datasheet models.
- gpiozero: RGBLED —
color,active_highand PWM mixing. - Adafruit: RGB LEDs — common anode vs cathode and per-colour resistors.