Raspberry Pi - Flame Sensor

The flame sensor is a nifty device that can pick up and gauge the infrared emissions from a flame, making it handy for fire detection. Sometimes it's referred to as an infrared flame sensor or a fire sensor. This sensor offers two outputs: a digital one (LOW/HIGH) and an analog one.

In this guide, we'll walk through using an Raspberry Pi along with a flame sensor to spot and measure flames and fires. We'll cover the following:

arduino flame sensor

Afterward, you can modify the code to activate a warning horn (via a relay) when it detects fire.

Hardware Preparation

1×Raspberry Pi 4 Model B
1×Flame Sensor
1×Jumper Wires
1×(Optional) Screw Terminal Adapter for Raspberry Pi

Or you can buy the following sensor kit:

1×DIYables Sensor Kit 30 types, 69 units
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 infrared flame sensor serves a dual purpose: it can identify the presence of a flame and measure the emitted infrared levels from the flame. This versatility makes the flame sensor a valuable tool for fire detection. It offers two output options through a digital output pin and an analog output pin.

In the realm of infrared flame sensors, they're crafted with precision. These sensors are picky about the wavelengths of infrared radiation they pay attention to, zeroing in on those specifically linked to flames. Their design is intentional, aiming to minimize the chances of false alarms triggered by other sources of infrared radiation like human body heat or artificial lighting. Despite their thoughtful engineering, it's important to note that, like any sensor, they do have their limitations. Certain conditions might lead to false positives or false negatives.

Pinout

The flame sensor includes four pins:

  • VCC pin: It needs to be connected to VCC (3.3V to 5V).
  • GND pin: It needs to be connected to GND (0V).
  • DO pin: It is a digital output pin. It is HIGH if the flame is not detected and LOW if detected. The threshold value for flame detection can be adjusted using a built-in potentiometer.
  • AO pin: It is an analog output pin. The output value decreases as the infraed level is decreased, and it increases as infraed level is increased.
Flame Sensor Pinout
image source: diyables.io

Furthermore, it has two LED indicators:

  • One PWR-LED indicator for power.
  • One DO-LED indicator for the flame state on the DO pin: it is on when flame is present.

How It Works

For the DO pin:

  • The module has a built-in potentiometer for setting the infrared threshold (sensitivity).
  • When the infrared intensity is above the threshold value, the flame is detected, the output pin of the sensor is LOW, and the DO-LED is on.
  • When the infrared intensity is below the threshold value, the flame is NOT detected, the output pin of the sensor is HIGH, and the DO-LED is off.

For the AO pin:

  • The higher the infrared intensity in the surrounding environment, the higher the value read from the AO pin.
  • The lower the infrared intensity in the surrounding environment, the lower the value read from the AO pin.

Note that the potentiometer does not affect the value on the AO pin.

Wiring Diagram

Since the flame sensor module has two outputs, you can choose to use one or both of them, depending on what you need. However, Raspberry Pi does not have an analog input pin, so we can use DO pin.

The wiring diagram between Raspberry Pi and Flame Sensor

This image is created using Fritzing. Click to enlarge image

Raspberry Pi Code - Read value from DO pin

Detailed Instructions

  • Make sure you have Raspbian or any other Raspberry Pi compatible operating system installed on your Pi.
  • Make sure your Raspberry Pi is connected to the same local network as your PC.
  • Make sure your Raspberry Pi is connected to the internet if you need to install some libraries.
  • If this is the first time you use Raspberry Pi, See how to set up the Raspberry Pi
  • Connect your PC to the Raspberry Pi via SSH using the built-in SSH client on Linux and macOS or PuTTY on Windows. See to how connect your PC to Raspberry Pi via SSH.
  • Make sure you have the RPi.GPIO library installed. If not, install it using the following command:
sudo apt-get update sudo apt-get install python3-rpi.gpio
  • Create a Python script file flame_sensor.py and add the following code:
# This Raspberry Pi code was developed by newbiely.com # This Raspberry Pi code is made available for public use without any restriction # For comprehensive instructions and wiring diagrams, please visit: # https://newbiely.com/tutorials/raspberry-pi/raspberry-pi-flame-sensor import RPi.GPIO as GPIO import time DO_PIN = 7 # GPIO pin connected to DO pin of the flame sensor # Set up the GPIO mode GPIO.setmode(GPIO.BCM) # Initialize the GPIO pin as an input GPIO.setup(DO_PIN, GPIO.IN) try: while True: flame_state = GPIO.input(DO_PIN) if flame_state == GPIO.HIGH: print("No flame => No fire detected.") else: print("Flame present => Fire detected.") time.sleep(1) except KeyboardInterrupt: # Clean up GPIO on keyboard interrupt GPIO.cleanup()
  • Save the file and run the Python script by executing the following command in the terminal:
python3 flame_sensor.py
  • Direct the flame sensor to a flame.
  • Check out the result on the Serial Monitor.
PuTTY - Raspberry Pi
Flame present => Fire detected. Flame present => Fire detected. No flame => No fire detected. No flame => No fire detected. No flame => No fire detected. Flame present => Fire detected. Flame present => Fire detected. Flame present => Fire detected.

Please keep in mind that if you notice the LED status remaining on constantly or off even when the sensor faces to a flame, you can adjust the potentiometer to fine-tune the sensitivity of the sensor.

Video Tutorial

Learn More