Common anode vs common cathode: meet the RGB LED twins
Every RGB LED is three tiny LEDs sharing one leg. Share the plus and a color lights when its pin goes LOW. Share the minus and it lights on HIGH. Here's why, what a mix-up looks like, and how to tell yours apart.

An RGB LED looks like one light, but it's really three tiny LEDs — red, green and blue — sharing one dome. Three LEDs should need six legs. Yours has four, because the colors share one of them.
Which end they share splits RGB LEDs into two types: common anode and common cathode. They look identical, cost the same, and behave exactly opposite in code. Let's meet them.
Anode and cathode in one breath
Every LED is a diode: a one-way street for current. Current goes in at the anode (+) and comes out at the cathode (−). Push it the other way and nothing happens: no current, no light.
Need a memory hook? Try ACID: Anode Current Into Device. On a plain single-color LED, the longer leg is the anode, and the flat spot on the rim marks the cathode.
Meet the twins
Now squeeze three LEDs into one package and tie one end of each together. Which end you tie is the only difference between the two types.

Common anode (+): they share the plus
The three anodes are joined into one leg, and that leg connects to the positive supply. Each color leg is a cathode, wired through a resistor to a pin.
The shared leg is always offering current. A color lights when its pin goes LOW and gives that current somewhere to go. Set the pin HIGH and both ends of that LED sit at the same voltage. Nothing flows, so the color rests.
Common cathode (−): they share the minus
The three cathodes are joined into one leg, and that leg connects to GND. Each color leg is an anode, wired through a resistor to a pin.
Now the pin does the pushing. A color lights when its pin goes HIGH and sends current through. Set the pin LOW and both ends sit at 0 V, so the color rests.

The cheat sheet
- Common anode (+): the shared leg goes to the positive supply. A color turns on when its pin is
LOW. - Common cathode (−): the shared leg goes to GND. A color turns on when its pin is
HIGH.
Same color, opposite code
In code, the whole difference fits in one flag. Think in on and off, and let a tiny helper choose the pin level:
// true for common anode (+), false for common cathode (−)
const bool COMMON_ANODE = true;
// RED_PIN, GREEN_PIN and BLUE_PIN are whichever pins you wired.
void setChannel(uint8_t pin, bool on) {
// Common anode lights on LOW; common cathode lights on HIGH.
bool high = COMMON_ANODE ? !on : on;
digitalWrite(pin, high ? HIGH : LOW);
}
void showYellow() {
setChannel(RED_PIN, true); // red + green = yellow
setChannel(GREEN_PIN, true);
setChannel(BLUE_PIN, false);
}Brightness flips the same way. With analogWrite, 255 is full brightness on a common cathode and fully off on a common anode, so the anode version writes 255 - level:
// level: 0 = off, 255 = full brightness, for either type
void setBrightness(uint8_t pin, uint8_t level) {
analogWrite(pin, COMMON_ANODE ? 255 - level : level);
}Wrong twin? Every color flips
Here's the classic mix-up. Run code written for one type on the other, and every channel goes backwards. Each color comes out as its opposite on the color wheel:

Ask for blue, get yellow. Ask for white, get darkness. If your LED keeps showing the exact opposite of what you asked for, nothing is broken. Flip COMMON_ANODE.
That trick assumes the shared leg is on the right rail. Wire a common cathode's shared leg to the positive supply, or a common anode's to GND, and every color is reverse-biased. Nothing lights, whatever the code says.
One resistor per color
Give each color leg its own resistor, between the pin and the LED, and run the shared leg straight to its rail.
One resistor on the shared leg looks tidier, but then the colors split a single current. Turn on a second color and the first one dims. Red grabs the biggest share, because it needs the least voltage: about 2 V, where green and blue want closer to 3 V.
Even with three resistors, equal values won't give equal brightness. That's normal. Tune it with resistor values, or scale each channel in code.
Which twin is in your hand?
They look the same, so ask the LED itself:
- Check the listing or datasheet. It usually says common anode (CA) or common cathode (CC).
- Find the longest leg. On most four-leg RGB LEDs that's the shared one, but length alone won't tell you which type it is.
- Connect the longest leg to GND, and one other leg through a 220 Ω resistor to 3.3 V. If a color lights, you're holding a common cathode.
- Still dark? Swap them: longest leg to 3.3 V, the other leg through the resistor to GND. If it lights now, it's a common anode.
Blue and green can be dim at 3.3 V, so try more than one leg before calling it dark. A multimeter in diode mode runs the same test: treat its red probe as + and its black probe as GND.
So which one should you buy?
Either. They're equally good at being an LED. Common cathode reads more naturally in code, since HIGH means on. Common anode suits LED driver chips that can only sink current, such as the TLC5940, which is why it turns up in bigger LED projects.
Pick one, check which you got, and set the flag. The twins only cause trouble when you mistake one for the other.