Visual Signaling: The ESP32 2-Color LED Module Manual

The 2-Color LED Module (commonly found as KY-011 or KY-029) is a versatile component containing two different colored light-emitting diodes—usually Red and Green—housed in a single 3mm or 5mm package. Unlike standard LEDs, this module allows for three distinct visual states: pure Red, pure Green, or a blended 'Yellow/Amber' hue created by activating both internal diodes simultaneously.

How it Works: Dual-Channel Emission

Most 2-color modules use a Common Cathode design. This means the negative terminals of both the Red and Green LEDs are tied to a single ground pin, while the positive terminals (anodes) are broken out into separate signal pins. By sending independent Pulse Width Modulation (PWM) signals to each anode, the ESP32 can control the specific brightness of each color, effectively 'mixing' them to create transitional shades.

Wiring the Bi-Color Circuit

Because Red and Green LEDs have different forward voltages (typically ~2.0V for Red and ~2.1V for Green), it is essential to use current-limiting resistors to prevent the ESP32's 3.3V logic from damaging the module. For the KY-011/KY-029, the middle pin is usually the ground (GND).

Module PinFunctionESP32 GPIO Pin
Pin (R)Red LED AnodeGPIO 18
Pin (G/Y)Green LED AnodeGPIO 19
Pin (-/Middle)Common CathodeGND
Resistor100Ω - 220ΩIn series with each Anode

Programming: Smooth Color Transitions

Using the ESP32's LEDC peripheral, we can create a smooth transition between Red and Green. This code initializes two PWM channels to fade the Red LED out while fading the Green LED in.

// ESP32 2-Color LED PWM Control
const int redPin = 18;
const int greenPin = 19;

void setup() {
  // Configure LEDC Channels (Channel, Freq, Resolution)
  ledcSetup(0, 5000, 8); // Red Channel
  ledcSetup(1, 5000, 8); // Green Channel

  ledcAttachPin(redPin, 0);
  ledcAttachPin(greenPin, 1);
}

void loop() {
  // Fade from Red to Green
  for (int i = 0; i <= 255; i++) {
    ledcWrite(0, 255 - i); // Red decreases
    ledcWrite(1, i);       // Green increases
    delay(10);
  }
  delay(1000);
}

IoT Status Indicators

2-color LEDs are the industry standard for providing compact visual feedback. Common use cases for ESP32-integrated systems include:

  • Network Connectivity: Solid Green when WiFi is connected; blinking Red when the connection is lost.
  • Battery Management: Green for 'Charged', Red for 'Low Battery', and Orange (both ON) for 'Charging'.
  • Industrial Safety: Using the module as a simple 'Go/No-Go' indicator on control panels.
  • Security Systems: Red to indicate the system is Armed and Green for Disarmed.

Common Pitfalls

  • The 'Yellow' looks too Red: Green LEDs are often less bright than Red ones at the same current. Adjust the PWM duty cycle in your code to favor the Green channel for a more balanced yellow mix.
  • Dim Output: Ensure you aren't using high-value resistors (like 10kΩ). For maximum visibility at 3.3V, use values between 100Ω and 220Ω.
  • Module Not Lighting: Some modules are 'Common Anode' (shared 3.3V/5V) rather than 'Common Cathode'. If GND doesn't work, try connecting the shared pin to 3.3V and pulling the signal pins LOW in code.

Final Summary

Mastering the 2-Color LED Module is a gateway to understanding hardware-level color mixing. By leveraging the ESP32’s precision PWM timers, you can move beyond simple blinking and create professional-grade visual indicators that communicate complex system states with a single component.