ESP32 KY-009 RGB Full Color LED SMD Module
The KY-009 is an RGB LED module that allows for the creation of various colors by adjusting the brightness of its red, green, and blue LEDs using PWM signals. It is suitable for projects requiring colorful visual displays.
🔗 Quick Links
🛒 KY-009 Price
ℹ️ About KY-009 RGB Full Color LED SMD Module
The KY-009 RGB Full Color LED SMD Module features a 5050 SMD LED capable of emitting a wide range of colors by mixing red, green, and blue light. Each color's intensity can be adjusted using Pulse Width Modulation (PWM), allowing for the creation of nearly any color in the visible spectrum. The module operates at a voltage of 5V, with forward voltages of 1.8V for the red LED and 2.8V for the green and blue LEDs. It is compatible with microcontrollers such as Arduino, Raspberry Pi, and ESP32.⚙️ KY-009 Sensor Technical Specifications
Below you can see the KY-009 RGB Full Color LED SMD Module Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensor’s datasheet.
- Type: module
- Protocol: PWM
- Operating Voltage: 5V
- Forward Voltage (Red): 1.8V
- Forward Voltage (Green/Blue): 2.8V
- Forward Current: 20mA
- LED Type: 5050 SMD
- Dimensions: 18.5 mm x 15 mm
🔌 KY-009 Sensor Pinout
Below you can see the pinout for the KY-009 RGB Full Color LED SMD Module. The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32!
Pin (-):
Common cathode (GND).Pin (R):
Red LED anode.Pin (G):
Green LED anode.Pin (B):
Blue LED anode.
🧵 KY-009 Wiring with ESP32
Below you can see the wiring for the KY-009 RGB Full Color LED SMD Module with the ESP32. Connect the VCC pin of the sensor to the 3.3V pin on the ESP32 or external power supply for power and the GND pin of the sensor to the GND pin of the ESP32. Depending on the communication protocol of the sensor (e.g., I2C, SPI, UART, or analog), connect the appropriate data and clock or signal pins to compatible GPIO pins on the ESP32, as shown below in the wiring diagram.
KY-009 Pin (-):
Connect to ESP32GND
.KY-009 Pin (R):
Connect to ESP32 PWM-capable GPIO pin (e.g.,GPIO18
) through a 180Ω resistor.KY-009 Pin (G):
Connect to ESP32 PWM-capable GPIO pin (e.g.,GPIO19
) through a 100Ω resistor.KY-009 Pin (B):
Connect to ESP32 PWM-capable GPIO pin (e.g.,GPIO21
) through a 100Ω resistor.
🛠️ KY-009 RGB Full Color LED SMD Module Troubleshooting
This guide outlines a systematic approach to troubleshoot and resolve common problems with the . Start by confirming that the hardware connections are correct, as wiring mistakes are the most frequent cause of issues. If you are sure the connections are correct, follow the below steps to debug common issues.
❌ LED Not Lighting Up
Issue: The LED does not emit light when expected.
Solutions:
- Ensure all connections are secure and correctly wired.
- Verify that the appropriate current-limiting resistors are used to prevent LED damage.
- Check that the microcontroller's GPIO pins are configured as outputs and are providing the correct PWM signals.
🎨 Incorrect Color Output
Issue: The LED displays unexpected colors or does not mix colors correctly.
Solutions:
- Confirm that the PWM signals are correctly set for each color channel.
- Ensure that the resistors used for each LED are of appropriate values to balance brightness.
- Check for any software errors in the code controlling the PWM outputs.
💻 Code Examples
Below you can find code examples of KY-009 RGB Full Color LED SMD Module with ESP32 in several frameworks:
If you encounter issues while using the KY-009 RGB Full Color LED SMD Module, check the Common Issues Troubleshooting Guide.

ESP32 KY-009 Arduino IDE Code Example
Fill in your main
Arduino IDE sketch file with the following code to use the KY-009 RGB Full Color LED SMD Module:
int redPin = 9;
int greenPin = 10;
int bluePin = 11;
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
setColor(255, 0, 0); // Red
delay(1000);
setColor(0, 255, 0); // Green
delay(1000);
setColor(0, 0, 255); // Blue
delay(1000);
setColor(255, 255, 0); // Yellow
delay(1000);
setColor(0, 255, 255); // Cyan
delay(1000);
setColor(255, 0, 255); // Magenta
delay(1000);
setColor(255, 255, 255); // White
delay(1000);
}
void setColor(int red, int green, int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
This Arduino code defines pins 9, 10, and 11 for controlling the red, green, and blue channels of the KY-009 module, respectively. The setColor()
function sets the brightness of each color using PWM, allowing the LED to display various colors. The loop()
function cycles through several colors with a one-second delay between each.
Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP32 KY-009 ESP-IDF Code ExampleExample in Espressif IoT Framework (ESP-IDF)
If you're using ESP-IDF to work with the KY-009 RGB Full Color LED SMD Module, here's how you can set it up and read data from the sensor. Fill in this code in the main
ESP-IDF file:
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#define RED_PIN GPIO_NUM_18
#define GREEN_PIN GPIO_NUM_19
#define BLUE_PIN GPIO_NUM_21
#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
#define LEDC_CHANNEL_B LEDC_CHANNEL_2
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_10_BIT,
.freq_hz = 1000
};
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_color(uint32_t red, uint32_t green, uint32_t blue) {
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);
ledc_set_duty(LEDC_MODE, LEDC_CHANNEL_B, blue);
ledc_update_duty(LEDC_MODE, LEDC_CHANNEL_B);
}
void app_main(void) {
configure_led_pwm(RED_PIN, LEDC_CHANNEL_R);
configure_led_pwm(GREEN_PIN, LEDC_CHANNEL_G);
configure_led_pwm(BLUE_PIN, LEDC_CHANNEL_B);
while (1) {
set_color(1023, 0, 0); // Red
vTaskDelay(pdMS_TO_TICKS(1000));
set_color(0, 1023, 0); // Green
vTaskDelay(pdMS_TO_TICKS(1000));
set_color(0, 0, 1023); // Blue
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
This ESP-IDF code configures the KY-009 RGB LED module using PWM on GPIO18 (red), GPIO19 (green), and GPIO21 (blue). The configure_led_pwm()
function sets up PWM for each LED channel, and set_color()
controls the brightness levels. The main loop cycles through red, green, and blue colors with one-second intervals.
Update the I2C pins (I2C_MASTER_SDA_IO
and I2C_MASTER_SCL_IO
) to match your ESP32 hardware setup, Use idf.py build to compile the project, Use idf.py flash to upload the code to your ESP32.

ESP32 KY-009 ESPHome Code Example
Fill in this configuration in your ESPHome YAML configuration file (example.yml
) to integrate the KY-009 RGB Full Color LED SMD Module
output:
- platform: ledc
pin: GPIO18
id: red_led
- platform: ledc
pin: GPIO19
id: green_led
- platform: ledc
pin: GPIO21
id: blue_led
light:
- platform: monochromatic
name: "KY-009 RGB LED"
output: red_led
gamma_correct: 2.8
- platform: monochromatic
name: "KY-009 RGB LED"
output: green_led
gamma_correct: 2.8
- platform: monochromatic
name: "KY-009 RGB LED"
output: blue_led
gamma_correct: 2.8
This ESPHome configuration sets up the KY-009 RGB LED module using LEDC PWM on GPIO18, GPIO19, and GPIO21. Each color is controlled separately using monochromatic light components, allowing color mixing through software.
Upload this code to your ESP32 using the ESPHome dashboard or the esphome run
command.

ESP32 KY-009 PlatformIO Code Example
For PlatformIO, make sure to configure the platformio.ini
file with the appropriate environment and libraries, and then proceed with the code.
Configure platformio.ini
First, your platformio.ini
should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
ESP32 KY-009 PlatformIO Example Code
Write this code in your PlatformIO project under the src/main.cpp
file to use the KY-009 RGB Full Color LED SMD Module:
#include <Arduino.h>
#define RED_PIN 18
#define GREEN_PIN 19
#define BLUE_PIN 21
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop() {
analogWrite(RED_PIN, 255);
analogWrite(GREEN_PIN, 0);
analogWrite(BLUE_PIN, 0);
delay(1000);
analogWrite(RED_PIN, 0);
analogWrite(GREEN_PIN, 255);
analogWrite(BLUE_PIN, 0);
delay(1000);
analogWrite(RED_PIN, 0);
analogWrite(GREEN_PIN, 0);
analogWrite(BLUE_PIN, 255);
delay(1000);
}
This PlatformIO code configures the KY-009 RGB LED module with PWM signals on GPIO18, GPIO19, and GPIO21. It cycles through red, green, and blue colors with one-second intervals.
Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload
command.

ESP32 KY-009 MicroPython Code Example
Fill in this script in your MicroPython main.py file (main.py
) to integrate the KY-009 RGB Full Color LED SMD Module with your ESP32.
import machine
import time
RED_PIN = machine.PWM(machine.Pin(18), freq=1000)
GREEN_PIN = machine.PWM(machine.Pin(19), freq=1000)
BLUE_PIN = machine.PWM(machine.Pin(21), freq=1000)
def set_color(r, g, b):
RED_PIN.duty(r)
GREEN_PIN.duty(g)
BLUE_PIN.duty(b)
while True:
set_color(1023, 0, 0) # Red
time.sleep(1)
set_color(0, 1023, 0) # Green
time.sleep(1)
set_color(0, 0, 1023) # Blue
time.sleep(1)
This MicroPython script configures GPIO18, GPIO19, and GPIO21 as PWM outputs to control the KY-009 RGB LED module. The set_color()
function sets the brightness of each LED channel, cycling through red, green, and blue colors.
Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy
.
Conclusion
We went through technical specifications of KY-009 RGB Full Color LED SMD Module, its pinout, connection with ESP32 and KY-009 RGB Full Color LED SMD Module code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.