Arduino Flame Sensor Tutorial

 Fire is one of the biggest threats to life and property. Whether it's a house, a factory or a public place, fire safety is a primary concern for everyone. Flame sensor modules are used to detect fires, and they are widely used in a variety of applications. In this Arduino tutorial on sensors, we will discuss how to use a flame sensor module with an Arduino.

What is a Flame Sensor Module?

A flame sensor module is a device that is used to detect fires. It can detect different types of flames such as candle flames, lighter flames, and even sunlight. The module consists of an infrared sensor that is sensitive to the wavelength of the flame, a comparator circuit using LM393 op-amp, and a potentiometer that is used to adjust the sensitivity of the sensor. Actually it is easy to build sensor like this see the tutorial Light and Darkness sensor Circuit with LM393.

How does flame sensor work?

The flame sensor module works by detecting the infrared radiation emitted by the flame. When a flame is detected, the infrared radiation is absorbed by the sensor, and the output of the comparator circuit changes. The output of the comparator is connected to an LED, which indicates the presence of a flame.

Using a Flame Sensor Module with an Arduino

Using a flame sensor module with an Arduino is very easy. All you need is an Arduino board, a flame sensor module, an LED, and a few jumper wires. Here are the steps to follow:

Step 1: Connect the Flame Sensor Module to the Arduino

Connect the flame sensor module to the Arduino board as follows:

  • VCC to 5V
  • GND to GND
  • D0 to digital pin 2

Step 2: Connect the LED to the Arduino

Connect the LED to the Arduino board as follows:

  • Positive (long leg) to digital pin 12
  • Negative (short leg) to GND

The complete circuit diagram of interfacing flame sensor module with Arduino is shown below.

flame sensor with Arduino

Step 3: Upload the Code to the Arduino

Here is the code for the flame sensor module:

int ledPin = 12;
int flamePin = 2;
int val = 0;

void setup(){

void loop(){
    val = digitalRead(flamein);
    Serial.print("val : ");
    digitalWrite(ledPin, HIGH);

    if(val == HIGH){
        Serial.print("NO Fire detected");
        digitalRead(ledPin, LOW);  
        Serial.print("Fire DETECTED");
        digitalRead(ledPin, HIGH);

This code is for interfacing a KY-026 flame sensor with an Arduino. The code defines the pins for the LED and flame sensor, sets up the pins for input/output, and then continuously reads the flame sensor and turns the LED on or off depending on whether a flame is detected or not. Here is a line-by-line explanation of the code:

int ledPin = 11; This line defines the LED pin number and sets it to 11.

int flamePin = 2; This line defines the flame sensor pin number and sets it to 2.

int val = 0; This line initializes the variable "val" to 0.

void setup() { This line begins the setup function.

pinMode(ledPin, OUTPUT); This line sets the LED pin to output mode.

pinMode(flamePin, INPUT); This line sets the flame sensor pin to input mode.

Serial.begin(9600); This line starts the serial communication with a baud rate of 9600.

void loop() { This line begins the loop function.

val = digitalRead(flamePin); This line reads the value of the flame sensor and stores it in the variable "val".

Serial.print("val : "); This line prints the string "val : " to the serial monitor.

Serial.println(val); This line prints the value of "val" to the serial monitor.

digitalWrite(ledPin, HIGH); This line turns on the LED.

if(val == HIGH) {
    Serial.print("NO Fire detected");
    digitalWrite(ledPin, LOW);

 This block of code checks if the flame sensor has detected a flame. If it has not detected a flame, "NO Fire detected" is printed to the serial monitor, and the LED is turned off.

    Serial.print("Fire DETECTED");
    digitalWrite(ledPin, HIGH);

This block of code is executed if the flame sensor has detected a flame. "Fire DETECTED" is printed to the serial monitor, and the LED is turned on.

Copy and paste this code into the Arduino IDE and upload it to the Arduino board.

Step 4: Test the Flame Sensor Module

Now, light a match or lighter in front of the flame sensor module. The LED should turn on, and the serial monitor should display "Fire DETECTED". If you move the flame away from the sensor, the LED should turn off, and the serial monitor should display "NO Fire detected".


In conclusion, using a flame sensor module with an Arduino is a great way to detect fires and ensure fire safety. The module is easy to use and can be integrated into various applications. By using this module, we can take necessary precautions to prevent any fire incidents and save lives and property.


[1] Comparison between LM393 and LM311 comparators

[2] Light sensor using LDR and LM311


Post a Comment

Previous Post Next Post