How to Use Flame Sensor Module With Arduino

by Rachana Jain in Circuits > Arduino

12 Views, 0 Favorites, 0 Comments

How to Use Flame Sensor Module With Arduino

Untitled design (7).jpg

Fire accidents can cause serious damage, making early detection extremely important. Traditional methods like smoke detection or sensing temperature changes are commonly used, but they have their limitations. Smoke detectors might not work well in fires that produce little or no smoke, and temperature-based systems often react only after the heat has risen significantly—by then, it may be too late to act quickly.

A more reliable solution is detecting thermal radiation, which flames naturally emit. One of the simplest and most cost-effective ways to do this is by using a flame sensor.

In this tutorial, we'll build a basic fire detection system that senses the presence of a flame and triggers an alarm to alert people nearby.

Supplies

Arduino UNO R3

Flame sensor

LCD 16x2

Jumper Wires

Breadboard

Buzzer

USB Cable Type A to B

12V Supply Adapter

Flame Sensor Module Overview

Slide1.PNG
  1. Operating Voltage: Works within 3.3V to 5V range, ensuring compatibility with most microcontrollers.
  2. Detection Angle: Offers a focused sensing field with an angle of approximately 60°.
  3. Detection Range: Capable of detecting flames from a distance of 1 to 2 meters.
  4. Adjustable Sensitivity: Includes a built-in potentiometer to easily adjust sensitivity levels.
  5. Compact Design: Small and lightweight, making it ideal for integration into various electronic projects.

Flame Sensor Module Pinout

The flame sensor module comes with 4 pins:

  1. VCC: Supplies power to the module.
  2. GND: Connects to the Arduino's ground.
  3. DO (Digital Output): Sends a HIGH or LOW signal based on flame detection.
  4. AO (Analog Output): Outputs an analog signal.


When Using Analog Output Pin of Flame Sensor

Slide4.PNG

Connect the VCC and GND pins of the flame sensor to the VCC and GND pins of the Arduino. Then, connect the analog output pin (AO) of the flame sensor to the Arduino's analog input pin A0. An I2C LCD is used to display the analog readings and the status of the flame sensor. Connect the VCC and GND pins of the I2C LCD to the Arduino's VCC and GND. The SCL (clock) and SDA (data) pins of the LCD are connected to the Arduino’s SCL and SDA lines, which are shared with analog pins A5 and A4 respectively. Additionally, a buzzer is included in the circuit for alerts; its red wire is connected to digital pin 11 on the Arduino, while the black wire goes to GND.

Code

Upload the following code:

/*
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);
}

When Using Digital Output of Flame Sensor

Slide5.PNG

The wiring remains the same as above, with one key difference: in this configuration, we are using the digital output pin of the flame sensor. Additionally, a buzzer has been added to the circuit. Its red wire is connected to pin 11 of the Arduino, and the black wire is connected to the GND pin.

Code

/*
Interfacing Flame Sensor with Arduino UNO using Digital input pin of Arduino and displaying fire detected on I2C LCD. A buzzer is used which turns ON and OFF when there is fire.
There is one averaging filter which checks for false alarm by averaging the input counts
Code by www.playwithcircuit.com
*/
#include <LiquidCrystal_I2C.h> // Library to Run I2C LCD
// Buzzer pin
#define BUZZER_PIN 11
// 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 digital input pin, for the flame sensor's digital output
const int FlameSensorDigitalPin = 10;
void setup() {
// initialize the LCD
lcd.init();
// Turn ON the Backlight
lcd.backlight();
// Clear the display buffer
lcd.clear();
// Make digital pin of sensor as input
pinMode(FlameSensorDigitalPin, INPUT);
// 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...");
// delay to make flame sensor stable
delay(1000);
// 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() {
// when the Digital pin turns HIGH, it means flame is present
if (checkFlameSensor() == HIGH) {
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);
}
}
// this function checks flame sensor two times to check if flame is really detected or not
bool checkFlameSensor() {
if (digitalRead(FlameSensorDigitalPin) == HIGH) {
// wait for 20ms to check for signal debouncing
delay(20);
if (digitalRead(FlameSensorDigitalPin) == HIGH) {
return HIGH;
} else {
return LOW;
}
} else {
return LOW;
}
}


To learn more checkout this article: Flame Sensor Module with Arduino