DEV Community

Cover image for How to use Flame Sensor Module with Arduino
Akshay Jain
Akshay Jain

Posted on

How to use Flame Sensor Module with Arduino

In this tutorial, you’ll learn how to interface a flame sensor module with an Arduino to build a simple fire detection system. This system will monitor the presence of flames and trigger an alert using an alarm—ideal for DIY home safety or educational projects.

How Does a Flame Sensor Module Work?

The flame sensor module operates by detecting infrared (IR) light—a type of thermal radiation emitted by flames and hot objects. At its core is a photodiode, which is sensitive to IR wavelengths. When a flame is present, the photodiode picks up the IR radiation.

An onboard LM393 comparator IC processes this signal and compares it to a threshold value, which you can adjust using the module’s potentiometer. If the incoming IR signal exceeds the threshold, the digital output (DO) pin changes its state, indicating the presence of a flame.

You can also use the analog output (AO) pin to measure how intense the IR radiation is. An onboard Signal LED lights up to visually indicate flame detection, and you can fine-tune the sensor’s response using the adjustable potentiometer.

Flame Sensor Module Specifications

Here’s a quick look at the key specifications of the module:

Operating Voltage: 3.3V to 5V (compatible with Arduino and other MCUs)
Detection Angle: ~60°, suitable for focused flame detection
Detection Range: 1–2 meters depending on the flame size
Sensitivity: Adjustable via onboard potentiometer
Form Factor: Small and compact for easy integration

Hardware Overview of Flame Sensor Module

Here’s what makes up the module:

Image description
Photodiode: Detects infrared light from flames.
LM393 Comparator IC: Converts the IR signal to a digital output based on a threshold.
Potentiometer: Adjusts the sensor’s sensitivity to suit your environment.
Power LED: Lights up when the module is powered.
Signal LED: Indicates flame detection (typically turns off when a flame is detected).

Flame Sensor Module Pinout

Image description

VCC: Power supply input (3.3V to 5V)
GND: Ground connection
DO(Digital Output): Outputs HIGH or LOW based on flame presence
AO(Analog Output): Outputs analog signal proportional to IR intensity

Wiring diagram when using Analog Output pin of Flame Sensor

Image description

/* 
Interfacing Flame Sensor with Arduino UNO using Analog input pin of Arduino and displaying fire detected on I2C LCD.
code by www.playwithcircuit.com
*/
#include <LiquidCrystal_I2C.h>  // Library to Run I2C LCD
// Buzzer pin
#define BUZZER_PIN 11
// Maximum counts to detect the flame
#define FLAME_DETECT_COUNTS 300
// define the size of filter array
#define FILTER_SIZE 30
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define the analog input pin, for the flame sensor's analog output
const int FlameSensorAnalogPin = A0;
// Variable to store the Analog count from flame sensor
int FlameCounts;
// Variable to store the Filtered Analog count from flame sensor
int filteredFlameCounts;
// Analog value filter
int Filter(int sensorValue);
void setup() {
  // initialize the LCD
  lcd.init();
  // Turn ON the Backlight
  lcd.backlight();
  // Clear the display buffer
  lcd.clear();
  // Make buzzer pin as output
  pinMode(BUZZER_PIN, OUTPUT);
  // Turn OFF buzzer pin
  digitalWrite(BUZZER_PIN, LOW);
  // Print a message to the LCD
  lcd.setCursor(0, 0);
  lcd.print("Initializing");
  // Print a message to the LCD
  lcd.setCursor(0, 1);
  lcd.print("Please Wait...");
  // flush out the first 100 values AND give time to flame sensor counts to be stable
  for (int i = 0; i < 100; i++) {
    // Read the value from the flame sensor
    FlameCounts = analogRead(FlameSensorAnalogPin);
    // Filter the input counts
    filteredFlameCounts = Filter(FlameCounts);
    delay(10);
  }
  // Clear the display buffer
  lcd.clear();
  // Print a message to the LCD
  lcd.setCursor(0, 0);
  lcd.print("Fire Detected:  ");
  // Print a message to the LCD
  lcd.setCursor(0, 1);
  lcd.print("                ");
}
void loop() {
  // Read the value from the flame sensor
  FlameCounts = analogRead(FlameSensorAnalogPin);
  // Filter the input counts
  filteredFlameCounts = Filter(FlameCounts);
  // if the counts are less than flame_detect_counts, the buzzer is activated
  // for this sensor when the flame is detected, the Analog counts decreases
  if (filteredFlameCounts < FLAME_DETECT_COUNTS) {
    lcd.setCursor(0, 1);
    lcd.print("YES");
    digitalWrite(BUZZER_PIN, !digitalRead(BUZZER_PIN));
    delay(100);
  } else {
    lcd.setCursor(0, 1);
    lcd.print("NO ");
    // Turn OFF buzzer pin
    digitalWrite(BUZZER_PIN, LOW);
    // Wait for 10ms before the next loop
    delay(10);
  }
}
// Averaging filter to filter Analog values
int Filter(int sensorValue) {
  static int analogArray[FILTER_SIZE] = { 0 };
  unsigned long int filteredValue = 0;
  int i;
  // Shift the element removing the oldest value stored at index 0
  for (i = 0; i < (FILTER_SIZE - 1); i++) {
    analogArray[i] = analogArray[i + 1];
  }
  // Put the current value in the last element of Array i.e. at index FILTER_SIZE-1
  analogArray[FILTER_SIZE - 1] = sensorValue;
  for (i = 0; i < FILTER_SIZE; i++) {
    filteredValue += analogArray[i];
  }
  // Return Filtered Analog value
  return (filteredValue / FILTER_SIZE);
}
Enter fullscreen mode Exit fullscreen mode

To learn more checkout: Flame Sensor Module with Arduino

Output

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.