ESP32 KY-034 Automatic Flashing Color LED Module
Overview
The KY-034 is an automatic flashing color LED module that emits a sequence of seven colors when powered. It's suitable for decorative and visual display applications, providing dynamic lighting effects without the need for external control.
About KY-034 Automatic Flashing Color LED Module
The KY-034 Automatic Flashing Color LED Module features a 5mm LED that cycles through seven colors automatically when powered. This module is ideal for decorative lighting projects, visual displays, and effects where changing colors are desired. The automatic color sequence means no additional control is required, making it easy to integrate into various projects.
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.
S (Signal):
Connects to a digital output pin on the microcontroller.Middle Pin:
Not connected.G (Ground):
Connects to the ground of the circuit.
Troubleshooting Guide
Common Issues
❌ LED Not Lighting Up
Issue: The LED does not turn on when powered.
Solutions:
- Verify that the module is connected to the correct voltage (3.3V to 5V).
- Ensure proper wiring connections between the module and the microcontroller.
- Check for any damage to the LED or module components.
🎨 LED Not Changing Colors
Issue: The LED remains a single color and does not cycle through colors.
Solutions:
- Confirm that the module is receiving continuous power without interruptions.
- Ensure that the signal pin is set to HIGH to allow the LED to operate.
- Check for any firmware or code that might be interfering with the LED's operation.
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 = 13; // Declaration of the LED input pin
void setup() {
pinMode(led, OUTPUT); // Initialization output pin for the LED
}
void loop() {
digitalWrite(led, HIGH); // LED is switched on
delay(4000); // Wait for 4 seconds
digitalWrite(led, LOW); // LED is switched off
delay(2000); // Wait for another two seconds
}
This Arduino code initializes pin 13 as an output to control the KY-034 module. In the loop, it turns the LED on for 4 seconds and off for 2 seconds repeatedly, allowing the LED to cycle through its automatic color sequence during the on periods.
ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define LED_PIN GPIO_NUM_13
void app_main(void) {
gpio_config_t io_conf = {
.intr_type = GPIO_INTR_DISABLE,
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = (1ULL << LED_PIN),
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.pull_up_en = GPIO_PULLUP_DISABLE
};
gpio_config(&io_conf);
printf("KY-034 Automatic Flashing Color LED Test\n");
while (1) {
gpio_set_level(LED_PIN, 1); // LED on
vTaskDelay(pdMS_TO_TICKS(4000));
gpio_set_level(LED_PIN, 0); // LED off
vTaskDelay(pdMS_TO_TICKS(2000));
}
}
This ESP-IDF code configures GPIO13 as an output for the KY-034 module. It turns the LED on for 4 seconds and off for 2 seconds in a loop, allowing the LED to display its automatic color-changing sequence during the on periods.
ESPHome Example
light:
- platform: binary
name: "KY-034 Flashing Color LED"
output: ky034_output
output:
- platform: gpio
id: ky034_output
pin: GPIO13
This ESPHome configuration sets up the KY-034 module as a binary light component on GPIO13. The light can be controlled via Home Assistant or other ESPHome-compatible interfaces, turning the LED on to display its automatic color sequence and off as desired.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
PlatformIO Example Code
#include <Arduino.h>
#define LED_PIN 13
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("KY-034 Automatic Flashing Color LED Test");
}
void loop() {
digitalWrite(LED_PIN, HIGH);
Serial.println("LED ON");
delay(4000);
digitalWrite(LED_PIN, LOW);
Serial.println("LED OFF");
delay(2000);
}
This PlatformIO code initializes GPIO13 as an output for the KY-034 module. It turns the LED on for 4 seconds and off for 2 seconds in a loop while printing status messages to the serial monitor.
MicroPython Example
import machine
import time
LED_PIN = machine.Pin(13, machine.Pin.OUT)
while True:
LED_PIN.on()
print("LED ON")
time.sleep(4)
LED_PIN.off()
print("LED OFF")
time.sleep(2)
This MicroPython script configures GPIO13 as an output for the KY-034 module. It continuously cycles the LED on for 4 seconds and off for 2 seconds, printing status messages to the console.
Conclusion
The ESP32 KY-034 Automatic Flashing 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.