Arduino UNO R4 - Flame Sensor

This tutorial instructs you how to use an Arduino UNO R4 and a flame sensor to detect and measure flames and fire. We will focus on the following topics:

Arduino UNO R4 flame sensor

Then, you can change the code to turn on a warning horn (using a relay) when it senses fire.

Hardware Preparation

1×Arduino UNO R4 WiFi
1×Arduino UNO R4 Minima (Alternatively)
1×USB Cable Type-C
1×Flame Sensor
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino UNO R4
1×(Recommended) Screw Terminal Block Shield for Arduino Uno
1×(Optional) Transparent Acrylic Enclosure For Arduino Uno

Or you can buy the following sensor 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. We appreciate your support.

Overview of Flame Sensor

The flame sensor can detect and measure the infrared light from a flame, which can be used for fire detection. It is also known as an infrared flame sensor or fire sensor. This sensor offers two types of signals: a digital output (LOW or HIGH) and an analog output.

Infrared flame sensors are made to detect specific types of infrared radiation wavelengths that come from flames. They are built to reduce false alarms caused by other infrared sources like human body heat or lights. However, these sensors are not perfect and sometimes might give incorrect alerts either by detecting something that isn't there or missing what is there.

Pinout

The flame sensor has four pins:

  • VCC pin: Connect this to VCC (3.3V to 5V).
  • GND pin: Connect this to GND (0V).
  • DO pin: This is a digital output pin. It shows HIGH when no flame is detected and LOW when a flame is detected. You can change the flame detection sensitivity with a potentiometer included on the board.
  • AO pin: This is an analog output pin. The output value goes down when the infrared level decreases and goes up when the infrared level increases.
Flame Sensor Pinout
image source: diyables.io

It also has two LED lights:

  • One PWR-LED indicator shows if power is on.
  • One DO-LED indicator shows if there is a flame dectected.

How It Works

For the DO pin:

  • The module includes a potentiometer to adjust the infrared threshold (sensitivity).
  • If the infrared intensity exceeds the threshold, the flame is detected, the sensor’s output pin is LOW, and the DO-LED lights up.
  • If the infrared intensity is under the threshold, the flame is not detected, the sensor’s output pin is HIGH, and the DO-LED is off.

For the AO pin:

  • When there is more infrared light around, the reading from the AO pin will be higher.
  • When there is less infrared light around, the reading from the AO pin will be lower.

The potentiometer does not change the value on the AO pin.

Wiring Diagram

The flame sensor module has two outputs, so you can use either one or both, depending on your needs.

The wiring diagram between Arduino UNO R4 Flame Sensor

This image is created using Fritzing. Click to enlarge image

Arduino UNO R4 Code - Read value from DO pin

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-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

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Connect the flame sensor to the Arduino Uno R4 according to the provided diagram.
  • Connect the Arduino Uno R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
  • Copy the code above and open it in Arduino IDE.
  • Click the Upload button in Arduino IDE to transfer the code to Arduino UNO R4.
  • Point the flame sensor towards a flame.
  • Check the results on 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 you see that the LED light stays on all the time or is off even when the sensor is pointing at a flame, you can turn the potentiometer to adjust how sensitive the sensor is.

Arduino UNO R4 Code - Read value from AO pin

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-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 UNO R4.
  • Point the flame sensor at a flame.
  • Check the result on 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!