ESP8266 - Flame Sensor

The flame sensor is a nifty device that picks up and gauges the infrared emissions from flames, making it a handy tool for fire detection. You might also hear it referred to as an infrared flame sensor or a fire sensor. This sensor offers two types of outputs: a digital one (LOW/HIGH) and an analog one.

In this guide, we'll walk through using an ESP8266 along with a flame sensor to identify and measure flames and fires. Specifically, we'll go over the following steps:

esp8266 flame sensor

Afterward, you can modify the code to activate a warning horn (via a relay) when it detects fire.

Hardware Preparation

1×ESP8266 NodeMCU
1×Micro USB Cable
1×Flame Sensor
1×Jumper Wires
1×(Optional) ESP8266 Screw Terminal Adapter

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of Flame Sensor

The infrared flame sensor serves the purpose of identifying the existence of a flame or gauging the level of infrared emissions produced by the flame. This makes it a valuable tool for fire detection. The sensor offers two choices through a digital output pin and an analog output pin.

These infrared flame sensors are meticulously crafted to be discerning in the wavelengths of infrared radiation they pick up, concentrating on the specific wavelengths associated with flames. Their design aims to reduce the chances of false alarms triggered by other sources of infrared radiation, like human body heat or artificial lighting. Despite their precision, it's important to note that, like any sensor, they do have limitations. Under specific conditions, they may exhibit false positives or false negatives.

Pinout

The flame sensor includes four pins:

  • VCC pin: It needs to be connected to VCC (3.3V to 5V).
  • GND pin: It needs to be connected to GND (0V).
  • DO pin: It is a digital output pin. It is HIGH if the flame is not detected and LOW if detected. The threshold value for flame detection can be adjusted using a built-in potentiometer.
  • AO pin: It is an analog output pin. The output value decreases as the infraed level is decreased, and it increases as infraed level is increased.
Flame Sensor Pinout
image source: diyables.io

Furthermore, it has two LED indicators:

  • One PWR-LED indicator for power.
  • One DO-LED indicator for the flame state on the DO pin: it is on when flame is present.

How It Works

For the Digital Output (DO) Pin:

  • The module comes with a built-in dial that lets you adjust how sensitive it is to infrared light.
  • If the infrared light is strong enough (passes the set sensitivity), it means the sensor has detected a flame. The output pin goes "LOW," and the DO-LED lights up.
  • If the infrared light is not strong enough (below the set sensitivity), it means no flame is detected. The output pin goes "HIGH," and the DO-LED turns off.

For the Analog Output (AO) Pin:

  • The AO pin gives you a number that represents how much infrared light is around.
  • More surrounding infrared light gives you a higher number from the AO pin.
  • Less surrounding infrared light gives you a lower number from the AO pin.

Keep in mind that adjusting the sensitivity with the dial doesn't change the value you get from the AO pin.

Wiring Diagram

Since the flame sensor module has two outputs, you can choose to use one or both of them, depending on what you need.

  • The wiring diagram between ESP8266 and the flame sensor when using DO only.
The wiring diagram between ESP8266 NodeMCU and Flame Sensor

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

  • The wiring diagram between ESP8266 and the flame sensor when using AO only.
The wiring diagram between ESP8266 NodeMCU and fire sensor

This image is created using Fritzing. Click to enlarge image

  • The wiring diagram between ESP8266 and the flame sensor when using both AO an DO.
The wiring diagram between ESP8266 NodeMCU and infrared flame sensor

This image is created using Fritzing. Click to enlarge image

ESP8266 Code - Read value from DO pin

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-flame-sensor */ #define DO_PIN D7 // The ESP8266 pin connected to DO pin of the flame sensor void setup() { // Initialize the Serial to communicate with the Serial Monitor. Serial.begin(9600); // initialize the ESP8266's pin as an input pinMode(DO_PIN, INPUT); } void loop() { int flame_state = digitalRead(DO_PIN); if (flame_state == HIGH) Serial.println("No flame => No fire detected"); else Serial.println("Flame present => Fire detected"); }

Detailed Instructions

To get started with ESP8266 on Arduino IDE, follow these steps:

  • Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP8266
  • Direct the flame sensor to a flame.
  • Check out the result on the Serial Monitor.
COM6
Send
Flame present => Fire detected Flame present => Fire detected No flame => No fire detected No flame => No fire detected No flame => No fire detected Flame present => Fire detected Flame present => Fire detected Flame present => Fire detected
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Please keep in mind that if you notice the LED status remaining on constantly or off even when the sensor faces to a flame, you can adjust the potentiometer to fine-tune the sensitivity of the sensor.

ESP8266 Code - Read value from AO pin

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-flame-sensor */ #define AO_PIN A0 // The ESP8266 pin connected to AO pin of the flame sensor void setup() { // Initialize the Serial to communicate with the Serial Monitor. Serial.begin(9600); } void loop() { int flameValue = analogRead(AO_PIN); Serial.println(flameValue); }

Detailed Instructions

  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to ESP8266
  • Direct the flame sensor to a flame.
  • Check out the result on the Serial Monitor.
COM6
Send
245 246 246 573 677 949 955 1004 1007 1013 1018 641 543 340 179
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

Learn More