KY-011 Two-Color LED Module

View on Amazon
Overview
About KY-011 Two-Color LED Module
The KY-011 Two-Color LED Module features a 3mm common cathode LED capable of emitting red and green light. By adjusting the intensity of each color using PWM, various colors can be achieved. The module operates at a forward voltage between 2.0V and 2.5V with a typical forward current of 20mA. It’s compatible with microcontrollers like Arduino and ESP32, making it suitable for visual feedback in projects.
Get Your KY-011
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
KY-011 Specifications
Complete technical specification details for KY-011 Two-Color LED Module
📊 Technical Parameters
KY-011 Pinout
The **KY-011** is a 3-pin two-color LED module (red/green common cathode):
Visual Pinout Diagram

Pin Types
Quick Tips
**Interface**: PWM control for each color channel,🌈 **Colors**: Red, green, and mixed colors (yellow/orange)
**Configuration**: Common cathode (shared ground),⚡ **Current**: 20mA per LED, 2.0-2.5V forward voltage
**Resistors**: Current-limiting resistors required for each LED,🎯 **Applications**: Status indicators, visual feedback, alerts, decorative lighting
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 Pin (G) | Power | Common cathode (ground) | Shared ground for both LEDs |
2 Pin (R) | Communication | Red LED anode | 2.0-2.5V forward voltage, 20mA |
3 Pin (Y) | Communication | Green LED anode | 2.0-2.5V forward voltage, 20mA (Y=Yellow marking) |
Wiring KY-011 to ESP32
To interface the **KY-011** with an **ESP32** for two-color LED control:
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| KY-011 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 Pin (G) Required | GND | Common ground | |
2 Pin (R) Required | GPIO18 | Red channel (via current-limiting resistor) | |
3 Pin (Y) Required | GPIO19 | Green channel (via current-limiting resistor) |
**Current-Limiting Resistors**: Use ~100-220Ω resistors for LED protection
**PWM Control**: Use PWM for color mixing and brightness adjustment
**GPIO Selection**: Use any PWM-capable GPIOs, shown pins are examples
**3.3V Logic**: ESP32's 3.3V output sufficient with proper resistors
KY-011 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: The LED does not illuminate when expected.
Solutions:
- Ensure the module is properly connected to the microcontroller.
- Verify that appropriate current-limiting resistors are used to prevent damage to the LEDs.
- Check the code to ensure the correct GPIO pins are being controlled.
Issue: The LED displays an unexpected color.
Solutions:
- Confirm that the correct GPIO pins are connected to the respective LED anodes.
- Adjust the PWM values in the code to achieve the desired color mix.
- Ensure that the common cathode is connected to ground.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
KY-011 Programming Examples
Ready-to-use code examples for different platforms and frameworks
int redPin = 10; // Pin for red LED
int greenPin = 9; // Pin for green LED
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop() {
digitalWrite(redPin, HIGH); // Red LED on
digitalWrite(greenPin, LOW); // Green LED off
delay(3000); // Wait for 3 seconds
digitalWrite(redPin, LOW); // Red LED off
digitalWrite(greenPin, HIGH); // Green LED on
delay(3000); // Wait for 3 seconds
}This Arduino code alternates the KY-011 module's red and green LEDs every 3 seconds. Pins 10 and 9 are configured as outputs for the red and green LEDs, respectively.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "driver/ledc.h"
#define RED_PIN GPIO_NUM_18
#define GREEN_PIN GPIO_NUM_19
#define LEDC_TIMER LEDC_TIMER_0
#define LEDC_MODE LEDC_HIGH_SPEED_MODE
#define LEDC_CHANNEL_R LEDC_CHANNEL_0
#define LEDC_CHANNEL_G LEDC_CHANNEL_1
void configure_led_pwm(gpio_num_t pin, ledc_channel_t channel) {
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_MODE,
.timer_num = LEDC_TIMER,
.duty_resolution = LEDC_TIMER_8_BIT,
.freq_hz = 5000,
.clk_cfg = LEDC_AUTO_CLK
};
ledc_timer_config(&ledc_timer);
ledc_channel_config_t ledc_channel = {
.gpio_num = pin,
.speed_mode = LEDC_MODE,
.channel = channel,
.intr_type = LEDC_INTR_DISABLE,
.timer_sel = LEDC_TIMER,
.duty = 0,
.hpoint = 0
};
ledc_channel_config(&ledc_channel);
}
void set_led_color(uint32_t red, uint32_t green) {
ledc_set_duty(LEDC_MODE, LEDC_CHANNEL_R, red);
ledc_update_duty(LEDC_MODE, LEDC_CHANNEL_R);
ledc_set_duty(LEDC_MODE, LEDC_CHANNEL_G, green);
ledc_update_duty(LEDC_MODE, LEDC_CHANNEL_G);
}
void app_main(void) {
configure_led_pwm(RED_PIN, LEDC_CHANNEL_R);
configure_led_pwm(GREEN_PIN, LEDC_CHANNEL_G);
while (1) {
set_led_color(255, 0); // Red on, Green off
vTaskDelay(pdMS_TO_TICKS(3000));
set_led_color(0, 255); // Red off, Green on
vTaskDelay(pdMS_TO_TICKS(3000));
}
}This ESP-IDF code configures the KY-011 two-color LED module using the ESP32's LEDC PWM hardware. GPIO18 controls the red LED, and GPIO19 controls the green LED. The configure_led_pwm() function initializes PWM for each LED channel, allowing brightness control. The LEDs alternate between red and green every 3 seconds.
output:
- platform: ledc
pin: GPIO18
id: red_led
- platform: ledc
pin: GPIO19
id: green_led
light:
- platform: monochromatic
name: "KY-011 Red LED"
output: red_led
gamma_correct: 2.8
- platform: monochromatic
name: "KY-011 Green LED"
output: green_led
gamma_correct: 2.8This ESPHome configuration sets up the KY-011 two-color LED module with LEDC PWM on GPIO18 for red and GPIO19 for green. The LEDs can be controlled individually to create different color effects.
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduinomain.cpp
#include <Arduino.h>
#define RED_PIN 18
#define GREEN_PIN 19
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
}
void loop() {
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
delay(3000);
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
delay(3000);
}This PlatformIO code sets up GPIO18 and GPIO19 as outputs to control the KY-011 module. The red and green LEDs alternate every 3 seconds.
import machine
import time
RED_PIN = machine.Pin(18, machine.Pin.OUT)
GREEN_PIN = machine.Pin(19, machine.Pin.OUT)
while True:
RED_PIN.value(1)
GREEN_PIN.value(0)
time.sleep(3)
RED_PIN.value(0)
GREEN_PIN.value(1)
time.sleep(3)This MicroPython script configures GPIO18 and GPIO19 as outputs for the KY-011 module. It alternates the red and green LEDs every 3 seconds.
Wrapping Up KY-011
The ESP32 KY-011 Two-Color LED Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the KY-011 into your ESP32 project and bring your ideas to life!








