📋 Overview
An RGB LED is three separate LEDs — red, green, and blue — built into a single package with four leads. By independently controlling the brightness of each color, you can mix virtually any color in the visible spectrum from a single component. The longest lead (Lead 2) is the common anode, which connects to your positive voltage supply. The three shorter leads are the individual color cathodes.
This particular LED uses a diffused (foggy) lens in the 3mm nipple package. The diffused lens scatters the light from all three elements so the colors blend smoothly together rather than appearing as three distinct spots — making it ideal for applications where you want even, uniform color output. The nipple (dome) shape is the standard form factor for per-key backlighting in mechanical keyboards, as it seats neatly into the switch opening.
With PWM (Pulse Width Modulation) outputs from an Arduino or similar microcontroller, you can fade each channel from 0 to full brightness and mix them in any ratio — giving you full dynamic control over both color and intensity.
🖼️ LED Diagram

3MM 4-Pin Common Anode Diffused Nipple-Package RGB LED Pinout
⚙️ How It Works — Additive Color Mixing
RGB LEDs work on the principle of additive color mixing. When you combine light from two or more colors, you add them together to create a new color — unlike mixing paint, where adding colors together makes them darker. The three primary colors of light are red, green, and blue, and combining them in different ratios produces every other color:
- Red + Green = Yellow
- Green + Blue = Cyan
- Red + Blue = Magenta
- Red + Green + Blue (all equal) = White
- All off = Black (no light)
With PWM, each channel can be set to any brightness level between fully off and fully on, giving you millions of possible color combinations from a single LED.
Understanding Common Anode Logic
This LED is common anode, meaning all three internal LEDs share a single positive (+) connection — the anode — on Lead 2. Each color is controlled by its own cathode lead.
This has an important consequence when using a microcontroller: the control logic is inverted compared to what you might expect:
- To turn a color ON: set its output pin LOW (0V) — this creates a voltage difference across the LED and allows current to flow.
- To turn a color OFF: set its output pin HIGH (5V or 3.3V) — this removes the voltage difference and stops current flow.
For PWM brightness control: analogWrite(pin, 0) = full brightness; analogWrite(pin, 255) = off. The sample code in this guide includes a helper function that handles this inversion automatically so you can use intuitive 0–255 values.
Common Anode vs. Common Cathode: If you have a common cathode RGB LED, the logic is the opposite — the shared pin is GND, and you drive the color pins HIGH to turn them on. Always check which type you have before wiring. See the comparison section later in this guide.
📊 Specifications
| Parameter | Red | Green | Blue |
|---|---|---|---|
| Forward Voltage (Vf) at 20 mA | 1.9 – 2.1V (typ. 2.0V) | 3.1 – 3.3V (typ. 3.2V) | 3.0 – 3.2V (typ. 3.1V) |
| Dominant Wavelength | 620 – 625 nm | 520 – 525 nm | 460 – 470 nm |
| Luminous Intensity at 20 mA | 600 – 1000 mcd | 3000 – 4000 mcd | 600 – 800 mcd |
| Parameter | Value |
|---|---|
| Package Type | 3mm Nipple (Dome) |
| Lens Type | Diffused (frosted) |
| Number of Leads | 4 (Common Anode + R, G, B cathodes) |
| Maximum Working Current | 20 mA per color channel |
| Viewing Angle | 30° |
| Base Dimensions (excluding nipple) | Approx. 6.5 × 2.35 × 3.3 mm (0.26 × 0.09 × 0.13 inches) W × D × H |
| RoHS Compliant | Yes |
| Envistia Mall P/N | EM-LEDLI-0005-DI |
Note: Green is significantly brighter than red or blue at the same current (3000–4000 mcd vs. 600–1000 mcd). When mixing colors to create "white" or balanced hues, you may need to reduce the green PWM value relative to red and blue to achieve a neutral result.
📌 Pinout
Hold the LED with the flat side of the base facing you and the leads pointing down. From left to right, the leads are numbered 1 through 4. Lead 2 is the longest — this is the common anode (+).
| Lead # | Function | Notes |
|---|---|---|
| Lead 1 | Red cathode (−) | Connect to GND through a current-limiting resistor (or to a PWM output through a resistor for variable brightness). |
| Lead 2 | Common anode (+) — longest lead | Connect to your positive supply voltage (5V or 3.3V). This is the shared positive for all three color elements. |
| Lead 3 | Green cathode (−) | Connect to GND through a current-limiting resistor (or to a PWM output through a resistor). |
| Lead 4 | Blue cathode (−) | Connect to GND through a current-limiting resistor (or to a PWM output through a resistor). |
Tip: This is an RGB LED (Red → Anode → Green → Blue, leads 1–2–3–4). Some LEDs are wired as RBG (Red → Anode → Blue → Green). These look identical but have green and blue swapped. See the RGB vs. RBG section later in this guide — this matters especially for mechanical keyboard builders.
🔋 Current-Limiting Resistors
Each color channel requires its own current-limiting resistor wired in series between the cathode lead and ground (or the microcontroller output pin). Never connect an LED directly to a voltage source without a resistor — without one, there is nothing to limit current and the LED will draw excessive current, overheat, and fail immediately.

RGB LEDs with Current-Limiting Resistors Schematics
How to Calculate the Resistor Value
Use Ohm's Law:
R = (Vs − Vf) / If
Where:
- R = resistor value in ohms (Ω)
- Vs = supply voltage (e.g., 5V or 3.3V)
- Vf = forward voltage of the LED color channel (from the Specifications table)
- If = desired forward current in amps (e.g., 0.010 for 10 mA, 0.020 for 20 mA)
Always choose the nearest standard resistor value that is equal to or higher than the calculated value — rounding down would allow more current than intended.
Recommended Resistor Values
The table below uses typical Vf values (Red = 2.0V, Green = 3.2V, Blue = 3.1V). Running at 10 mA rather than the 20 mA maximum is recommended for general use — it extends LED life and stays well within the current limits of most microcontroller output pins.
| Supply Voltage | Target Current | Red (Lead 1) | Green (Lead 3) | Blue (Lead 4) |
|---|---|---|---|---|
| 5V | 20 mA (maximum) | 150Ω | 100Ω | 100Ω |
| 5V | 10 mA (recommended) | 300Ω | 180Ω | 180Ω |
| 3.3V | 10 mA | 130Ω | 33Ω ⚠️ | 33Ω ⚠️ |
⚠️ 3.3V Systems — Important Note: The forward voltage of green (3.1–3.3V) and blue (3.0–3.2V) is very close to 3.3V. This leaves very little headroom for a resistor to work with. At 3.3V, always use at least a 33Ω resistor on green and blue as a minimum safety measure. Green and blue brightness may be noticeably lower than at 5V. For full brightness on all three channels, a 5V supply is strongly recommended.
🔌 Wiring
Standalone Static Color (No Microcontroller)
For a fixed color with no microcontroller — for example, always-on red — simply wire the anode to +V, connect the desired color cathode through a resistor to GND, and leave the unused cathodes unconnected (or connect them through resistors to GND to turn on multiple colors simultaneously).
| LED Lead | Connection |
|---|---|
| Lead 2 (Anode, longest) | 5V (or 3.3V) |
| Lead 1 (Red) | 150Ω resistor → GND (for red at 5V/20mA) |
| Lead 3 (Green) | Leave unconnected for no green, or 100Ω resistor → GND for green |
| Lead 4 (Blue) | Leave unconnected for no blue, or 100Ω resistor → GND for blue |
Wiring to Arduino (Uno, Nano, Mega) for PWM Control
Connect the anode (Lead 2) to the Arduino's 5V pin. Connect each cathode through its current-limiting resistor to a PWM-capable output pin. On the Arduino Uno and Nano, PWM pins are marked with a tilde (~): pins 3, 5, 6, 9, 10, and 11.
| LED Lead | Arduino Connection |
|---|---|
| Lead 2 (Anode, longest) | 5V |
| Lead 1 (Red cathode) | 150Ω resistor → PWM Pin 9 (or any ~ pin) |
| Lead 3 (Green cathode) | 100Ω resistor → PWM Pin 10 (or any ~ pin) |
| Lead 4 (Blue cathode) | 100Ω resistor → PWM Pin 11 (or any ~ pin) |
Tip: If you only want a fixed color with no brightness control, you can use non-PWM digital pins instead, or connect the resistors directly to GND. PWM pins are only needed for variable brightness and color mixing.
💻 Sample Code
Arduino — Color Cycle Demo
This sketch cycles through seven colors, demonstrating basic color mixing. The setColor() helper function accepts intuitive brightness values (0 = off, 255 = full brightness) and automatically handles the common-anode inversion internally.
// 3MM Common Anode RGB LED — Color Cycle Demo
// Envistia Mall — EM-LEDLI-0005-DI
// Wiring: Lead 2 (Anode) → 5V
// Lead 1 (Red) → 150Ω → Arduino Pin 9
// Lead 3 (Green) → 100Ω → Arduino Pin 10
// Lead 4 (Blue) → 100Ω → Arduino Pin 11
const int RED_PIN = 9; // PWM pin — Red cathode
const int GREEN_PIN = 10; // PWM pin — Green cathode
const int BLUE_PIN = 11; // PWM pin — Blue cathode
// Common Anode: analogWrite(pin, 0) = ON, analogWrite(pin, 255) = OFF
// This helper takes intuitive values: 0 = off, 255 = full brightness
void setColor(int red, int green, int blue) {
analogWrite(RED_PIN, 255 - red);
analogWrite(GREEN_PIN, 255 - green);
analogWrite(BLUE_PIN, 255 - blue);
}
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
setColor(0, 0, 0); // Start with LED off
}
void loop() {
setColor(255, 0, 0); // Red
delay(1000);
setColor(0, 255, 0); // Green
delay(1000);
setColor(0, 0, 255); // Blue
delay(1000);
setColor(255, 255, 0); // Yellow (Red + Green)
delay(1000);
setColor(0, 255, 255); // Cyan (Green + Blue)
delay(1000);
setColor(255, 0, 255); // Magenta (Red + Blue)
delay(1000);
setColor(255, 255, 255); // White (all on)
delay(1000);
setColor(0, 0, 0); // Off
delay(500);
}
Arduino — Single-Color Fade (Red)
This sketch fades a single color in and out using a loop. Change setColor(brightness, 0, 0) to any color combination to fade a different color. The same setColor() helper from the first sketch is used.
// 3MM Common Anode RGB LED — Red Fade Demo
// Envistia Mall — EM-LEDLI-0005-DI
const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;
void setColor(int red, int green, int blue) {
analogWrite(RED_PIN, 255 - red);
analogWrite(GREEN_PIN, 255 - green);
analogWrite(BLUE_PIN, 255 - blue);
}
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop() {
// Fade red in from off to full brightness
for (int brightness = 0; brightness <= 255; brightness++) {
setColor(brightness, 0, 0);
delay(5);
}
// Fade red out from full brightness to off
for (int brightness = 255; brightness >= 0; brightness--) {
setColor(brightness, 0, 0);
delay(5);
}
delay(300);
}
🎨 Color Mixing Reference
The table below shows PWM values (0–255) to pass into the setColor() function from the sample code above. A value of 0 is off and 255 is full brightness for that channel.
Green brightness adjustment: Green is 3–6× brighter than red or blue at the same current. When aiming for neutral white or balanced colors, try reducing the green value to around 100–150 while keeping red and blue at 255. Adjust to taste for your specific lighting conditions.
| Color | Red (0–255) | Green (0–255) | Blue (0–255) |
|---|---|---|---|
| Red | 255 | 0 | 0 |
| Green | 0 | 255 | 0 |
| Blue | 0 | 0 | 255 |
| Yellow | 255 | 255 | 0 |
| Cyan | 0 | 255 | 255 |
| Magenta | 255 | 0 | 255 |
| White (nominal) | 255 | 255 | 255 |
| White (green-adjusted) | 255 | 120 | 255 |
| Orange | 255 | 165 | 0 |
| Purple | 128 | 0 | 128 |
| Pink | 255 | 20 | 147 |
| Off | 0 | 0 | 0 |
💡 Tips — Common Anode vs. Common Cathode
RGB LEDs come in two configurations. They look identical from the outside, so it is important to know which type you have before wiring.
| Feature | Common Anode (this product) | Common Cathode |
|---|---|---|
| Shared pin connects to | +V (positive supply) | GND (ground) |
| Shared pin identification | Longest lead | Longest lead (or second-longest on some packages) |
| To turn a color ON | Drive the cathode pin LOW (0V) | Drive the anode pin HIGH (+V) |
| PWM: full brightness | analogWrite(pin, 0) |
analogWrite(pin, 255) |
| PWM: off | analogWrite(pin, 255) |
analogWrite(pin, 0) |
If you wire a common anode LED as though it were common cathode (or vice versa), the LED will either not light up at all or will behave with inverted color logic. The sample code in this guide is written specifically for common anode LEDs.
⌨️ RGB vs. RBG — Mechanical Keyboard Compatibility
If you are using this LED for per-key backlighting in a mechanical keyboard, there is an important compatibility issue to be aware of: not all keyboard PCBs use the same pin order.
What Is the Difference?
Both RGB and RBG LEDs have four leads in the same positions. The only difference is which lead carries green and which carries blue:
- RGB (this product): Lead 1 = Red, Lead 2 = Anode, Lead 3 = Green, Lead 4 = Blue
- RBG: Lead 1 = Red, Lead 2 = Anode, Lead 3 = Blue, Lead 4 = Green
The green and blue leads are swapped between the two types.

What Happens if You Use the Wrong Type?
- The LED will physically fit in the keyboard switch and will light up.
- Red will display correctly — its position is the same in both types.
- Green and blue will be swapped: when your keyboard firmware requests blue, you will get green, and vice versa.
- This causes incorrect colors across all mixed hues — cyan will appear as yellow, magenta will appear as red, and so on.
Before You Buy for a Keyboard Build
- Check your keyboard PCB's documentation or silkscreen markings for LED type.
- Search for your keyboard model in enthusiast forums or build guides — LED type is frequently documented.
- When in doubt, contact the PCB manufacturer or keyboard designer directly.
Note: Most keyboard PCBs are designed for RGB LEDs, but a significant number of older or specialized designs use RBG. Envistia Mall sells this product as an RGB LED (Red → Anode → Green → Blue). If your keyboard requires RBG LEDs, this product will produce incorrect colors without firmware modification.
🎯 Applications
- Mechanical keyboard backlighting — Per-key RGB illumination in custom keyboard builds
- Status indicators — Display system state using different colors (red = error, green = OK, blue = standby)
- Mood and ambient lighting — Low-power decorative lighting with color control
- Arduino and microcontroller projects — Color-mixing demonstrations, learning PWM, and interactive displays
- Prototype panel indicators — Multi-state indicators for DIY enclosures and control panels
- Night lights and decorations — Battery-powered color-changing accent lights
- Signal and alert systems — Color-coded alarms and notification lights
⚠️ Important Notes
- Always use a current-limiting resistor in series with each color cathode. Connecting an LED cathode directly to GND or a digital output without a resistor will burn out the LED immediately.
- Do not exceed 20 mA per color channel. Running at 10 mA is recommended for general use and significantly extends LED lifespan.
- Each color channel requires its own separate resistor — do not share a single resistor across multiple color channels.
- The three color channels have different forward voltages. Do not use the same resistor value for all three channels without calculating each one individually.
- At 3.3V supply voltages, green and blue channels have very limited headroom above their forward voltage. Use at least 33Ω and expect reduced brightness on those channels. A 5V supply is preferred for full brightness.
- Green is substantially brighter than red and blue at equal currents. When mixing to white or balanced hues, reduce the green PWM value accordingly.
- The LED leads are not pre-trimmed. Trim leads to the appropriate length after inserting into your circuit or PCB.
🛠️ Troubleshooting
| Symptom | Likely Cause | Solution |
|---|---|---|
| LED does not light up at all | Anode not connected to +V; or LED inserted backwards | Confirm Lead 2 (longest) is connected to +V. Verify polarity — the anode must connect to the positive supply, not GND. |
| Only one or two colors light up | Missing or incorrect resistor on a channel; or that cathode pin is not connected | Check that each color cathode has a resistor to GND (or to its PWM output pin). Verify all connections with a multimeter. |
| Colors are inverted or wrong (on/off reversed) | Using common cathode code logic with a common anode LED | For common anode: analogWrite(pin, 0) = ON, analogWrite(pin, 255) = OFF. Use the setColor() helper function from the sample code in this guide. |
| Green and blue are swapped in a keyboard | RGB LED inserted into an RBG-wired PCB (or vice versa) | Verify your keyboard PCB's required LED type. If the PCB requires RBG, this RGB LED will display incorrect colors. Some keyboards allow you to correct this in firmware settings. |
| LED dims or flickers during use | Insufficient power from the microcontroller output pin; or shared ground issues | Ensure the microcontroller GND and the LED circuit GND are connected. For multiple LEDs, use a transistor or LED driver rather than driving them directly from output pins. |
| White light looks greenish | Green channel is significantly brighter than red and blue | Reduce the green PWM value (try 100–140 instead of 255) while keeping red and blue at 255 to balance perceived white. |
| Green or blue very dim at 3.3V | Supply voltage is close to the forward voltage of those channels | Use a 5V supply if possible. At 3.3V, green and blue have minimal voltage headroom and will be noticeably dimmer than at 5V. |
| LED burned out quickly | Missing current-limiting resistor; or resistor value too low; or exceeded 20mA | Always use the correct resistor on every channel. Check your resistor calculation: R = (Vs − Vf) / If. Never omit resistors. |
🏪 Where to Buy the 3MM 4-Pin Common Anode Diffused Nipple-Package RGB LED
This 3mm RGB LED is available from Envistia Mall:
Buy the 3MM 4-Pin Common Anode Diffused RGB LED at Envistia Mall →
- 📦 Fast US Shipping
- 🔄 Hassle-Free Returns
- 📧 Responsive Customer Support
📄 Documentation & Resources
- A Simple Guide to RGB LEDs — Build Electronic Circuits
- Interfacing RGB LED with Arduino — Arduino Project Hub
- LED Series Resistor Formula — Wikipedia
- LED Resistor Value Calculator — DigiKey
This guide is provided by Envistia Mall for educational and technical reference purposes. The manufacturer and Envistia LLC (dba Envistia Mall) are not responsible for any damages or losses resulting from the use of this product. Always follow proper electrical safety practices when working with electronic components. Specifications are based on manufacturer data and are subject to change without notice.