ESP32 KY-029 Dual Color LED Module
Overview
The KY-029 is a dual-color LED module featuring a 3mm LED that emits red and green light. By adjusting the intensity of each color using PWM, various color combinations can be achieved. The module's common cathode design simplifies integration with microcontrollers for visual indicators in projects.
About KY-029 Dual Color LED Module
The KY-029 Dual Color LED Module features a 3mm LED capable of emitting red and green light. By adjusting the intensity of each color using PWM, you can create various color combinations. The module operates with a common cathode configuration, simplifying control with microcontrollers.
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Pinout Configuration
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 S (Signal):
Connects to the anode of the red or green LED.Pin middle (VCC):
Connects to the common cathode (GND).Pin - (GND):
Not connected.
Troubleshooting Guide
Common Issues
❌ LED Not Lighting Up
Issue: The LED does not emit any light.
Solutions:
- Ensure proper wiring connections between the module and the microcontroller.
- Verify that the microcontroller's GPIO pins are correctly configured as outputs.
- Check if appropriate current-limiting resistors are used to prevent LED damage.
🎨 Incorrect Color Display
Issue: The LED displays unexpected colors or brightness levels.
Solutions:
- Confirm that the PWM signals are correctly configured for both red and green LEDs.
- Ensure that the common cathode is properly connected to ground.
- Check for any short circuits or loose connections on the module.
Debugging Tips
🔍 Serial Monitor
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.
⚡ Voltage Checks
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
Code Examples
Arduino Example
int led_red = 11; // Pin for red
int led_green = 10; // Pin for green
void setup() {
// Initialization of output pins for the LEDs
pinMode(led_red, OUTPUT);
pinMode(led_green, OUTPUT);
}
void loop() {
digitalWrite(led_red, HIGH); // Red LED is switched on
digitalWrite(led_green, LOW); // Green LED is switched off
delay(3000); // Wait for 3 seconds
digitalWrite(led_red, LOW); // Red LED is switched off
digitalWrite(led_green, HIGH); // Green LED is switched on
delay(3000); // Wait for a further 3 seconds in which the LEDs are then switched over
}
This Arduino code alternates between turning on the red and green LEDs every 3 seconds. Pins 11 and 10 are configured as outputs for the red and green LEDs, respectively.
ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"
#include "driver/gpio.h"
#define LED_RED_PIN GPIO_NUM_16
#define LED_GREEN_PIN GPIO_NUM_17
#define LEDC_TIMER LEDC_TIMER_0
#define LEDC_MODE LEDC_LOW_SPEED_MODE
#define LEDC_CHANNEL_RED LEDC_CHANNEL_0
#define LEDC_CHANNEL_GREEN LEDC_CHANNEL_1
#define LEDC_DUTY_RES LEDC_TIMER_8_BIT
#define LEDC_FREQUENCY 5000
void app_main(void) {
// Configure timer for LEDC
ledc_timer_config_t ledc_timer = {
.speed_mode = LEDC_MODE,
.duty_resolution = LEDC_DUTY_RES,
.timer_num = LEDC_TIMER,
.freq_hz = LEDC_FREQUENCY,
.clk_cfg = LEDC_AUTO_CLK
};
ledc_timer_config(&ledc_timer);
// Configure LEDC channel for red LED
ledc_channel_config_t ledc_channel_red = {
.speed_mode = LEDC_MODE,
.channel = LEDC_CHANNEL_RED,
.timer_sel = LEDC_TIMER,
.intr_type = LEDC_INTR_DISABLE,
.gpio_num = LED_RED_PIN,
.duty = 0,
.hpoint = 0
};
ledc_channel_config(&ledc_channel_red);
// Configure LEDC channel for green LED
ledc_channel_config_t ledc_channel_green = {
.speed_mode = LEDC_MODE,
.channel = LEDC_CHANNEL_GREEN,
.timer_sel = LEDC_TIMER,
.intr_type = LEDC_INTR_DISABLE,
.gpio_num = LED_GREEN_PIN,
.duty = 0,
.hpoint = 0
};
ledc_channel_config(&ledc_channel_green);
while (1) {
printf("Red LED ON\n");
ledc_set_duty(LEDC_MODE, LEDC_CHANNEL_RED, 255);
ledc_update_duty(LEDC_MODE, LEDC_CHANNEL_RED);
ledc_set_duty(LEDC_MODE, LEDC_CHANNEL_GREEN, 0);
ledc_update_duty(LEDC_MODE, LEDC_CHANNEL_GREEN);
vTaskDelay(pdMS_TO_TICKS(3000));
printf("Green LED ON\n");
ledc_set_duty(LEDC_MODE, LEDC_CHANNEL_RED, 0);
ledc_update_duty(LEDC_MODE, LEDC_CHANNEL_RED);
ledc_set_duty(LEDC_MODE, LEDC_CHANNEL_GREEN, 255);
ledc_update_duty(LEDC_MODE, LEDC_CHANNEL_GREEN);
vTaskDelay(pdMS_TO_TICKS(3000));
}
}
This ESP-IDF code configures GPIO16 and GPIO17 as PWM outputs using the LEDC peripheral. It alternates between turning on the red and green LEDs every 3 seconds, simulating a simple traffic light effect.
ESPHome Example
light:
- platform: monochromatic
name: "KY-029 Red LED"
output: led_red
- platform: monochromatic
name: "KY-029 Green LED"
output: led_green
output:
- platform: gpio
pin: GPIO16
id: led_red
- platform: gpio
pin: GPIO17
id: led_green
This ESPHome configuration sets up two monochromatic light entities for the red and green LEDs on GPIO16 and GPIO17. They can be controlled separately in Home Assistant to create different lighting effects.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
PlatformIO Example Code
#include <Arduino.h>
#define LED_RED_PIN 16
#define LED_GREEN_PIN 17
void setup() {
pinMode(LED_RED_PIN, OUTPUT);
pinMode(LED_GREEN_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("KY-029 Dual Color LED Module Test");
}
void loop() {
digitalWrite(LED_RED_PIN, HIGH);
digitalWrite(LED_GREEN_PIN, LOW);
Serial.println("Red LED ON");
delay(3000);
digitalWrite(LED_RED_PIN, LOW);
digitalWrite(LED_GREEN_PIN, HIGH);
Serial.println("Green LED ON");
delay(3000);
}
This PlatformIO code alternates between turning on the red and green LEDs every 3 seconds, with messages printed to the serial monitor.
MicroPython Example
import machine
import time
LED_RED_PIN = machine.Pin(16, machine.Pin.OUT)
LED_GREEN_PIN = machine.Pin(17, machine.Pin.OUT)
while True:
LED_RED_PIN.on()
LED_GREEN_PIN.off()
print("Red LED ON")
time.sleep(3)
LED_RED_PIN.off()
LED_GREEN_PIN.on()
print("Green LED ON")
time.sleep(3)
This MicroPython script toggles the KY-029 red and green LEDs every 3 seconds using GPIO16 and GPIO17.
Conclusion
The ESP32 KY-029 Dual 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.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.