How to Detect Fire with a Flame Sensor – KY-026

In this tutorial, you will learn how to detect fire with a flame sensor (KY-026) and an ESP32.

Parts Required

Circuit

Code

// lowest and highest sensor readings:
const int sensorMin = 0;     // sensor minimum
const int sensorMax = 1024;  // sensor maximum

void setup() {
  Serial.begin(9600);  
}

void loop() {
  // read the sensor on analog A0:
	int sensorReading = analogRead(A0);
  // map the sensor range (four options):
  // ex: 'long int map(long int, long int, long int, long int, long int)'
	int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
  
  // range value:
  switch (range) {
  case 0:    // A fire closer than 1.5 feet away.
    Serial.println("** Fogo Perto **");
    break;
  case 1:    // A fire between 1-3 feet away.
    Serial.println("** Fogo Longe **");
    break;
  case 2:    // No fire detected.
    Serial.println("Fogo Nao Detetado");
    break;
  }
  delay(1);  // delay between reads
}

References

[1] https://www.electronicshub.org/arduino-flame-sensor-interface/

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!

Hello! We have noticed you are using an ad blocker. Our website is funded by advertising which allows you to access all our content for free. By disabling your ad blocker, you are contributing to the sustainability of our project and ensuring we continue to provide high-quality, useful tutorials. We appreciate your support!