RGB LED(5mm)
This is a 4-pin RGB LED that expresses colors by adjusting the RGB values.
There are Cathode and Anode versions of the product; this document uses the Cathode version.
Specifications
- Operating Voltage [V]: Red (22.2), Green (33.2), Blue (3~3.2)
- Common Cathode type
Example Hardware Used
- Arduino board
- Jumper cables
- RGB LED
- Three 330-ohm resistors (100-ohm, 220-ohm resistors, etc., can also be used.)
Connection
The long leg is GND, and excluding the long leg, from left to right, it is R, G, B as shown in the image below.
Arduino | Resistor1 | Resistor2 | Resistor3 | RGB LED |
GND | GND | |||
D11 | Connected | |||
D10 | Connected | |||
D9 | Connected | |||
Connected | R | |||
Connected | G | |||
Connected | B |
Example Code
This code sequentially lights up six different colors.
#define ledR 11
#define ledG 10
#define ledB 9
void brightness(int r, int g, int b) {
analogWrite(ledR, r);
analogWrite(ledG, g);
analogWrite(ledB, b);
}
void setup() {
brightness(0, 0, 0);
delay(500);
brightness(255, 0, 0);
delay(500);
brightness(0, 255, 0);
delay(500);
brightness(0, 0, 255);
delay(500);
brightness(255, 255, 0);
delay(500);
brightness(255, 0, 255);
delay(500);
brightness(0, 255, 255);
delay(500);
brightness(0, 0, 0);
}
void loop() {
}