RGB LED Reference
Three LEDs (red, green, blue) in one package sharing a common cathode.
Pin names
| Name | Description |
|---|---|
| R | Red anode |
| G | Green anode |
| B | Blue anode |
| COM | Common cathode (negative) |
Attributes
This component has no configurable attributes.
Usage
Connect each of R, G, B through a 220 Ω current-limiting resistor to a PWM-capable
GPIO pin, and COM to GND. Use analogWrite() on each channel to mix colours — 0 is off,
255 is full brightness.
const int PIN_R = 9;
const int PIN_G = 10;
const int PIN_B = 11;
void setColor(int r, int g, int b) {
analogWrite(PIN_R, r);
analogWrite(PIN_G, g);
analogWrite(PIN_B, b);
}
void setup() {
pinMode(PIN_R, OUTPUT);
pinMode(PIN_G, OUTPUT);
pinMode(PIN_B, OUTPUT);
}
void loop() {
setColor(255, 0, 0); delay(500); // red
setColor(0, 255, 0); delay(500); // green
setColor(0, 0, 255); delay(500); // blue
setColor(255, 255, 0); delay(500); // yellow
}
Examples
| Description | Attrs |
|---|---|
| Default RGB LED | {} |