All posts
Note

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.

Granrojo TeamPlatform
Hardware
Two smiling cartoon RGB LEDs on a breadboard. The common anode's long shared leg runs to a red plus rail; the common cathode's runs to a black minus rail.

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.

Two RGB LED schematics. In the common anode, the three anodes join into one shared leg that goes to +V, and each color's cathode is its own leg. In the common cathode, the three cathodes join into one shared leg that goes to GND, and each color's anode is its own leg.
Same three LEDs, same direction of current. Only the shared end changes.

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.

A two-by-two grid. Common anode with the pin LOW: current flows from +V through the LED into the pin, so it is on. Common anode with the pin HIGH: +V on both ends, so it is off. Common cathode with the pin LOW: 0 V on both ends, so it is off. Common cathode with the pin HIGH: current flows out of the pin through the LED to GND, so it is on.
Same pin level, opposite result. One color channel is shown; the other two work the same way.

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:

rgb-led.ino
// 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:

rgb-led.ino
// 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:

Five color pairs. Asking for red shows cyan, green shows magenta, blue shows yellow, white shows nothing, and off shows white, because every channel is inverted.
Each channel inverts, so each color turns into its complement.

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:

  1. Check the listing or datasheet. It usually says common anode (CA) or common cathode (CC).
  2. 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.
  3. 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.
  4. 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.