Overview
Learn how to use the KY-026 flame sensor with an ESP32 to detect flame or strong infrared light. This project is useful for fire alarms, safety monitoring, and simple warning systems.
Instructions
Step by step
1. Connect the KY-026 VCC pin to 3.3V.
2. Connect the KY-026 GND pin to GND.
3. Connect the KY-026 DO pin to D15.
4. Connect the KY-026 AO pin to D34 if you want to read flame intensity.
5. Run the code and open the Serial Monitor.
6. Click or adjust the flame sensor in the simulator.
7. When flame is detected, the output should print "Flame detected!".
8. When no flame is detected, the output should print "No flame".
Code
Source code
const int flameDigitalPin = 15;
const int flameAnalogPin = 34;
void setup() {
Serial.begin(115200);
pinMode(flameDigitalPin, INPUT);
Serial.println("KY-026 Flame Sensor Test");
}
void loop() {
int digitalValue = digitalRead(flameDigitalPin);
int analogValue = analogRead(flameAnalogPin);
if (digitalValue == LOW) {
Serial.print("Flame detected! Level: ");
Serial.println(analogValue);
} else {
Serial.print("No flame. Level: ");
Serial.println(analogValue);
}
delay(500);
}
Related