ESP32 KY-026 Flame Sensor Module
Overview
The KY-026 is a flame sensor module capable of detecting light in the 760 nm to 1100 nm wavelength range. It offers both analog and digital outputs, with adjustable sensitivity via an onboard potentiometer, making it suitable for various flame detection applications.
About KY-026 Flame Sensor Module
The KY-026 Flame Sensor Module is designed to detect open flames and other light sources emitting wavelengths between 760 nm and 1100 nm. It features both analog and digital outputs: the analog output provides a voltage proportional to the detected flame intensity, while the digital output activates when the flame intensity exceeds a user-defined threshold, adjustable via an onboard potentiometer. This module is ideal for fire detection systems, flame alarms, and firefighting robots.
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.
GND:
Connects to ground.+V:
Connects to 3.3V or 5V power supply.D0:
Digital output; goes high when the detected flame intensity exceeds the set threshold.A0:
Analog output; provides a voltage proportional to the detected flame intensity.
Troubleshooting Guide
Common Issues
❌ No Response from Sensor
Issue: The sensor does not provide any output when exposed to a flame.
Solutions:
- Verify all connections are secure and correctly placed.
- Ensure the module is receiving the appropriate voltage (3.3V or 5V).
- Adjust the potentiometer to set the correct sensitivity threshold.
- Test the sensor with a known flame source to confirm functionality.
⚠️ False Positives
Issue: The sensor triggers without the presence of a flame.
Solutions:
- Reduce the sensitivity by adjusting the potentiometer.
- Avoid exposing the sensor to direct sunlight or other strong light sources.
- Ensure there are no reflective surfaces causing stray light to reach the sensor.
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
// Declaration and initialization of the input pins
int analog_input = A0; // Analog output of the sensor
int digital_input = 3; // Digital output of the sensor
void setup() {
pinMode(analog_input, INPUT);
pinMode(digital_input, INPUT);
Serial.begin(9600); // Serial output with 9600 bps
Serial.println("KY-026 Flame detection");
}
void loop() {
float analog_value;
int digital_value;
// Current values are read out, converted to the voltage value...
analog_value = analogRead(analog_input) * (5.0 / 1023.0);
digital_value = digitalRead(digital_input);
//... and printed at this point
Serial.print("Analog voltage value: ");
Serial.print(analog_value, 4);
Serial.print(" V, Threshold value: ");
if (digital_value == 1) {
Serial.println("reached");
} else {
Serial.println("not yet reached");
}
Serial.println("----------------------------------------------------------------");
delay(1000);
}
This Arduino code reads the analog voltage from the KY-026 sensor's analog output and checks the digital output to determine if the flame intensity has surpassed the set threshold. The results are printed to the serial monitor every second.
ESP-IDF Example
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/adc.h"
#include "driver/gpio.h"
#define FLAME_SENSOR_ANALOG_PIN ADC1_CHANNEL_0 // GPIO36
#define FLAME_SENSOR_DIGITAL_PIN GPIO_NUM_17
void app_main(void) {
adc1_config_width(ADC_WIDTH_BIT_12);
adc1_config_channel_atten(FLAME_SENSOR_ANALOG_PIN, ADC_ATTEN_DB_11);
gpio_set_direction(FLAME_SENSOR_DIGITAL_PIN, GPIO_MODE_INPUT);
printf("KY-026 Flame Detection\n");
while (1) {
int analog_value = adc1_get_raw(FLAME_SENSOR_ANALOG_PIN);
int digital_value = gpio_get_level(FLAME_SENSOR_DIGITAL_PIN);
printf("Analog Value: %d, Digital Threshold: %s\n", analog_value, digital_value ? "Flame Detected" : "No Flame");
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
This ESP-IDF code reads the analog value from the KY-026 sensor using ADC on GPIO36 and monitors the digital output on GPIO17 to determine if the flame intensity threshold is exceeded. The results are printed every second.
ESPHome Example
sensor:
- platform: adc
pin: GPIO36
name: "KY-026 Flame Intensity"
update_interval: 1s
binary_sensor:
- platform: gpio
pin:
number: GPIO17
mode: INPUT_PULLUP
name: "KY-026 Flame Detection"
This ESPHome configuration reads the KY-026 sensor's analog output on GPIO36 and detects the flame threshold trigger using GPIO17 as a binary sensor. Updates are logged every second.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
PlatformIO Example Code
#include <Arduino.h>
#define FLAME_SENSOR_ANALOG_PIN A0
#define FLAME_SENSOR_DIGITAL_PIN 17
void setup() {
pinMode(FLAME_SENSOR_DIGITAL_PIN, INPUT);
Serial.begin(115200);
Serial.println("KY-026 Flame Sensor Test");
}
void loop() {
int analog_value = analogRead(FLAME_SENSOR_ANALOG_PIN);
int digital_value = digitalRead(FLAME_SENSOR_DIGITAL_PIN);
Serial.printf("Analog: %d, Digital: %s\n", analog_value, digital_value ? "Flame Detected" : "No Flame");
delay(1000);
}
This PlatformIO code reads the KY-026 sensor's analog output and monitors the digital flame detection trigger. The values are printed every second.
MicroPython Example
import machine
import time
FLAME_SENSOR_ANALOG_PIN = machine.ADC(machine.Pin(36))
FLAME_SENSOR_ANALOG_PIN.atten(machine.ADC.ATTN_11DB)
FLAME_SENSOR_DIGITAL_PIN = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_UP)
while True:
analog_value = FLAME_SENSOR_ANALOG_PIN.read()
digital_value = FLAME_SENSOR_DIGITAL_PIN.value()
print("Analog:", analog_value, "Digital:", "Flame Detected" if digital_value else "No Flame")
time.sleep(1)
This MicroPython script reads the KY-026 sensor's analog signal using ADC on GPIO36 and monitors the digital output on GPIO17. The readings are printed every second.
Conclusion
The ESP32 KY-026 Flame Sensor 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.