Two-color LED (KY-011)

A red and a yellow-green LED under one 5 mm lens, sharing a leg. Aliases: bicolor LED, dual color LED, KY-011 (5 mm), KY-029 (3 mm).

Light one leg and you get red or green. Light both and the eye adds them into orange or yellow, and PWM on the two legs walks the color anywhere in between. It is the status light on chargers and routers, and the "dual color LED" lesson in the sensor kits.

Pins

Pin What it does
R Anode of the red die.
C The common, the middle leg: both dice's cathodes (or anodes, see below).
G Anode of the yellow-green die.

Properties

common: cathode (the usual part, and the KY-011's), where C goes to ground and a high leg lights its die, or anode, where C goes to the supply and a low leg lights.

While it runs

The lens shows the mix the two currents make: red, orange, yellow or green, and milky white while both are dark.

Wiring it

Two resistors, one per colored leg, and the common to ground:

const int RED_PIN = 9, GREEN_PIN = 10;   // both PWM pins

void setup() {
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
}

void loop() {
  analogWrite(RED_PIN, 255);   // red full
  analogWrite(GREEN_PIN, 80);  // a little green: orange
}

The KY-011 and KY-029 modules have no resistors on them, whatever the tutorial's photo suggests; put 220 ohm in each leg.

What the model gets right

Two dice, two currents. Each die is the same Shockley-equation LED as the LED, conducting on its own between its leg and the common, so one die on does not change the other's current.

The drops of this part. The KY-011 sheet gives 644 nm red and 571 nm green, both at 2.0 to 2.5 V and 20 mA. 571 nm is the yellow-green GaP die, not the 3 V InGaN green of a modern single-color LED, so the model uses 2.0 V for red and 2.2 V for green. On 220 ohm from 5 V they run at about 13.4 and 12.5 mA, nearly even, which is why one resistor value suits both legs here when it does not on an RGB LED.

Perceived color. The brightness is an 8 ms average, the plain LED's, so PWM reads as the mixed color rather than a flicker between red and green.

What it does not model

The two-lead bipolar kind, whose two dice sit back to back across two legs and change color with the direction of the current. Reverse breakdown, heat, and the small differences in brightness between a red and a green die at the same current: here 20 mA is full brightness for either.

Common mistakes

One resistor in the common leg instead of one per die: with both lit, the two dice then share that resistor's current, and turning one off brightens the other.

Wiring a common-anode part like a common-cathode one: nothing lights, because both dice are reverse biased. Set common to match the part.

See it in action

Level light turns a knob into red, orange, yellow and green. Open it at /templates.