Arduino Mega - Flame Sensor

This guide shows you how to use an Arduino Mega and a flame sensor to detect and measure flames and fire. We will cover these topics:

Arduino Mega flame sensor

Next, change the code so a warning horn turns on when it detects fire (using a relay).

Hardware Preparation

1×Arduino Mega
1×USB 2.0 cable type A/B (for USB-A PC)
1×USB 2.0 cable type C/B (for USB-C PC)
1×Flame Sensor
1×5-in-1 5-way Flame Sensor
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
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.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Flame Sensor

infrared flame fire-sensor module

The flame sensor can detect and measure the infrared light from a flame, which helps with fire detection. It is also called an infrared flame sensor or fire sensor. This sensor provides two kinds of signals: a digital output (LOW or HIGH) and an analog output.

Infrared flame sensors are designed to detect certain kinds of infrared light that comes from flames. They are built to reduce false alarms caused by other infrared sources like body heat or lights. However, these sensors are not perfect and sometimes they may give wrong alerts—either by picking up something that isn’t there or by missing something that is there.

Pinout

There are two kinds of flame sensor modules available:

This flame sensor has four pins:

  • VCC pin: Connect to VCC (3.3V to 5V).
  • GND pin: Connect to ground (0V).
  • DO pin: This is a digital output. It shows HIGH when no flame is detected and LOW when a flame is detected. You can adjust how sensitive the flame detector is with a small knob on the board.
  • AO pin: This is an analog output. The output value falls when the infrared level decreases and rises when the infrared level increases.
Flame Sensor Pinout
image source: diyables.io

It also has two LED lights.

  • One Power LED lights up when power is on.
  • One Flame LED lights up when a flame is detected.

5-in-1 flame sensor brings together five flame sensors on one circuit board. All sensors share one adjustable resistor (potentiometer), plus VCC and GND power lines, making power setup easier. But each sensor has its own Digital Output (DO) and Analog Input (AI) pins, so they can detect flames at the same time and independently. Also, each sensor points in a different direction, which greatly increases the overall detection range.

How It Works

About the DO pin:

  • The module has a small knob (potentiometer) to adjust how sensitive it is to infrared light.
  • If the infrared light is stronger than the limit, the flame is detected, the sensor output pin goes LOW, and the DO-LED lights up.
  • If the infrared light is weaker than the limit, no flame is detected, the sensor output pin goes HIGH, and the DO-LED is off.

About the analog output pin:

  • If there is more infrared light nearby, the AO pin reading is higher.
  • If there is less infrared light nearby, the AO pin reading is lower.

The pot does not change the voltage on the AO pin.

Wiring Diagram

The flame sensor module has two output wires, so you can use one or both, depending on what you need.

The wiring diagram between Arduino Mega Flame Sensor

This image is created using Fritzing. Click to enlarge image

Arduino Mega Code - Read value from DO pin

/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-flame-sensor */ #define DO_PIN 2 // The Arduino UNO R4 pin connected to DO pin of the flame sensor void setup() { // initialize serial communication Serial.begin(9600); // initialize the Arduino's pin as an input pinMode(DO_PIN, INPUT); } void loop() { int flame_state = digitalRead(DO_PIN); if (flame_state == HIGH) Serial.println("The flame is NOT present => The fire is NOT detected"); else Serial.println("The flame is present => The fire is detected"); }

Detailed Instructions

Do these steps one by one.

  • Connect the flame sensor to the Arduino Mega following the diagram.
  • Connect the Arduino Mega to your computer with a USB cable.
  • Open the Arduino IDE on your computer.
  • Choose the right board: Arduino Mega, and select the COM port.
  • Copy the code above and open it in the Arduino IDE.
  • Click the Upload button in the Arduino IDE to upload the code to the Arduino Mega.
  • Point the flame sensor toward a flame.
  • Check the results in the Serial Monitor.
COM6
Send
The flame is present => The fire is detected The flame is present => The fire is detected The flame is NOT present => The fire is NOT detected The flame is NOT present => The fire is NOT detected The flame is NOT present => The fire is NOT detected The flame is present => The fire is detected The flame is present => The fire is detected The flame is present => The fire is detected
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

If the LED stays on all the time or stays off even when the sensor is aimed at a flame, turn the small knob to adjust how sensitive the sensor is.

Arduino Mega Code - Read value from AO pin

/* * This Arduino Mega code was developed by newbiely.com * * This Arduino Mega code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mega/arduino-mega-flame-sensor */ #define AO_PIN A0 // The Arduino UNO R4 pin connected to AO pin of the flame sensor void setup() { // initialize serial communication Serial.begin(9600); } void loop() { int flame_value = analogRead(AO_PIN); Serial.println(flame_value); }

Detailed Instructions

  • Copy the code and open it in the Arduino IDE.
  • Click the Upload button in the Arduino IDE to upload the code to the Arduino Mega.
  • Point the flame sensor at a flame.
  • See the result in the Serial Monitor.
COM6
Send
145 206 226 513 697 959 965 1005 1006 1016 1019 661 545 341 172
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

Video Tutorial

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!