ESP32 KY-034 Automatic Flashing Color LED Module
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.
🔗 Quick Links
🛒 KY-034 Price
ℹ️ 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.⚙️ KY-034 Sensor Technical Specifications
Below you can see the KY-034 Automatic Flashing Color LED 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: Digital
- Operating Voltage: 3.3V to 5V
- LED Type: 5mm round head
- Color Cycle: Automatic sequence of 7 colors
- Dimensions: 16.5mm x 18.5mm
🔌 KY-034 Sensor Pinout
Below you can see the pinout for the KY-034 Automatic Flashing Color LED 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!
S (Signal):
Connects to a digital output pin on the microcontroller.Middle Pin:
Not connected.G (Ground):
Connects to the ground of the circuit.
🧵 KY-034 Wiring with ESP32
Below you can see the wiring for the KY-034 Automatic Flashing Color LED 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.
S (Signal):
Connect to ESP32GPIO13
.G (Ground):
Connect to ESP32GND
.
🛠️ KY-034 Automatic Flashing Color LED 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 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.
💻 Code Examples
Below you can find code examples of KY-034 Automatic Flashing Color LED Module with ESP32 in several frameworks:
If you encounter issues while using the KY-034 Automatic Flashing Color LED Module, check the Common Issues Troubleshooting Guide.

ESP32 KY-034 Arduino IDE Code Example
Fill in your main
Arduino IDE sketch file with the following code to use the KY-034 Automatic Flashing Color LED Module:
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.
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-034 ESP-IDF Code ExampleExample in Espressif IoT Framework (ESP-IDF)
If you're using ESP-IDF to work with the KY-034 Automatic Flashing Color LED 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/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.
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-034 ESPHome Code Example
Fill in this configuration in your ESPHome YAML configuration file (example.yml
) to integrate the KY-034 Automatic Flashing Color LED Module
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.
Upload this code to your ESP32 using the ESPHome dashboard or the esphome run
command.

ESP32 KY-034 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-034 PlatformIO Example Code
Write this code in your PlatformIO project under the src/main.cpp
file to use the KY-034 Automatic Flashing Color LED Module:
#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.
Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload
command.

ESP32 KY-034 MicroPython Code Example
Fill in this script in your MicroPython main.py file (main.py
) to integrate the KY-034 Automatic Flashing Color LED Module with your ESP32.
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.
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-034 Automatic Flashing Color LED Module, its pinout, connection with ESP32 and KY-034 Automatic Flashing Color LED Module code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.