An RGB LED has four pins: one common pin (either common cathode or common anode) and three color pins for red, green, and blue. The common pin connects to ground (common cathode) or to the positive supply (common anode), while each color pin connects through a current-limiting resistor to a microcontroller output.
That is the short answer, but the details matter enormously in practice. The pin order is not standardized across parts, the resistor values depend on the LED’s forward voltage and your supply, and mixing up common anode and common cathode will make the LED appear to do nothing or stay permanently on. This guide walks through the physical layout, the electrical behavior, how to identify pins you cannot see, and the mistakes that cost beginners the most time.
What the Four Pins Actually Do
Inside a single RGB LED package there are three separate light-emitting diodes: a red die, a green die, and a blue die. Each has its own anode and cathode. To keep the package to four pins, the three anodes (or the three cathodes) are tied together internally. That shared connection is the common pin.
- Common cathode: the shared pin is the cathode (negative side). You connect it to ground. Each color pin is an anode and lights when you drive it high (positive).
- Common anode: the shared pin is the anode (positive side). You connect it to your positive supply. Each color pin is a cathode and lights when you pull it low (to ground).
- Red pin: controls only the red die.
- Green pin: controls only the green die.
- Blue pin: controls only the blue die.
Because the three dies are independent, you can produce any color by mixing their brightness. Driving red and green together yields yellow-orange; green and blue yield cyan; all three at full brightness approximate white. This is additive color mixing, and it is the entire reason RGB LEDs exist as a category.
Common Cathode vs Common Anode: The Most Important Distinction
Before you connect anything, determine which type you have. The two are not interchangeable without changing your code and your wiring.
With a common cathode part, the shared pin goes to ground. A microcontroller pin set HIGH sources current into the LED. With a common anode part, the shared pin goes to the positive rail, and a microcontroller pin set LOW sinks current out of the LED. If you wire a common anode LED as if it were common cathode, all three colors will be on whenever the pins are low and off when high, which looks like inverted behavior rather than a broken part.
A quick test with a multimeter in diode-test mode will reveal the type: probe pairs of pins and note which orientation causes a faint glow. The pin that lights the LED when probed against each color pin in the same orientation is the common pin. Many multimeters supply enough test current to make the die visibly emit, though blue and green may be dim.
Identifying the Pins Without a Datasheet
The single most common frustration with RGB LEDs is that the pin order is not standardized. Two parts that look identical may have completely different arrangements. Never assume; verify.
- Look for the longest lead. On many through-hole RGB LEDs the longest pin is the common pin, but this is a convention, not a rule.
- Check the flat side of the lens. On some parts the flat edge marks the common pin or the red pin, again by convention only.
- Use the datasheet if you have it. The manufacturer’s pinout diagram is authoritative.
- If no datasheet exists, use a multimeter in diode-test mode and a resistor in series to limit current, then map each pin by observing which color lights.
- For surface-mount parts, the package marking or a dot often indicates pin one, but the mapping from pin one to color varies by part.
Write the pinout down once you have determined it. A label on the part or a note in your code will save you from repeating the test later.
Resistors, Forward Voltage, and Why You Need Them
Each color die has a different forward voltage. Red is typically the lowest, while green and blue are higher. Because the dies are separate, each color pin needs its own current-limiting resistor. A single resistor on the common pin is a common mistake: it limits total current but does not prevent one die from hogging current when colors are mixed, and brightness will shift unpredictably as you change colors.
Choose resistor values from the LED’s datasheet forward voltage and your supply voltage, using Ohm’s law. If you do not have the datasheet, start with a relatively high value and reduce it while checking that the LED does not overheat. Do not connect an LED directly across a supply without a resistor; the current will rise until the die is damaged.
Microcontroller output pins also have current limits. Driving three dies at once can exceed what a single pin or the chip as a whole can supply. For anything beyond indicator-level brightness, use a transistor or a dedicated LED driver per channel.
Wiring an RGB LED to a Microcontroller
The basic circuit is straightforward once the pinout is known.
- Connect the common pin to ground (common cathode) or to the positive rail (common anode).
- Connect each color pin through its own resistor to a microcontroller output pin.
- In code, set the output pins as outputs and drive them high or low according to the LED type.
- For PWM dimming, use pins that support pulse-width modulation so you can vary brightness per channel.
If colors appear wrong — for example, asking for red produces blue — the pin mapping is wrong. Swap the connections or correct the pin definitions in your code rather than assuming the LED is faulty.
Common Problems and Misconceptions
“The LED does nothing.” Check the common pin first. A common anode LED with its common pin grounded will not light. Also verify resistor values are not so high that current is negligible.
“All colors are on at once.” This usually means the common pin is connected to the wrong rail, or the microcontroller pins are floating rather than driven. Floating inputs can cause erratic behavior.
“The colors are inverted.” You likely have a common anode part wired as common cathode. Reverse the logic in code or rewire the common pin.
“One color is much dimmer.” The red die has a lower forward voltage and may need a different resistor value than green and blue to appear equally bright. This is normal and is corrected by choosing resistor values per channel.
“It worked, then stopped.” Check for a missing resistor or a short. LEDs driven without current limiting can fail permanently.
RGB LED vs Addressable LED Strips
A plain four-pin RGB LED is a discrete component: you control it directly with your own pins and resistors. Addressable LED strips and modules contain driver chips and use a serial data protocol, so a single data line can control many LEDs independently. The trade-off is complexity: discrete RGB LEDs are simple and cheap for single indicators, while addressable strips are far more practical when you need many independently colored lights. The pin configuration question applies to the discrete four-pin part; addressable modules have their own pinouts, usually marked on the board.
Frequently Asked Questions
How do I tell if my RGB LED is common cathode or common anode? Use a multimeter in diode-test mode. The common pin is the one that, when probed against each color pin in the same orientation, causes the LED to light. If the common pin is the negative side, it is common cathode; if positive, common anode. A datasheet is the fastest confirmation.
Can I use one resistor for all three colors? No. Each die needs its own resistor because forward voltages differ. A shared resistor causes uneven brightness and unpredictable color mixing.
Why does my RGB LED show the wrong color? The pin mapping is likely wrong. The order of red, green, and blue pins varies between parts, so verify with a datasheet or a multimeter test and correct your wiring or code.
Do I need a resistor if I use a microcontroller? Yes. Microcontroller pins can source or sink limited current, and an LED without a resistor can draw too much and damage either the LED or the pin. Always use a current-limiting resistor per channel.
What is the difference between a four-pin RGB LED and a three-pin one? A four-pin LED has separate connections for each color plus a common pin, allowing independent control. A three-pin part is typically a two-color or single-color LED with a common pin, or a different package type. Check the datasheet for the specific part.
Can I drive an RGB LED directly from a battery? Only with appropriate resistors and within the LED’s ratings. Without current limiting, the LED can be destroyed. For battery-powered projects, calculate resistor values from the supply voltage and the LED’s forward voltage, and check the datasheet for maximum current.