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:
- Connecting the flame sensor to an Raspberry Pi.
- Programming the Raspberry Pi to identify flames and fires by interpreting the digital signal from the flame sensor.
Afterward, you can modify the code to activate a warning horn (via a relay) when it detects fire.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
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
There are two types of flame sensor modules available:
A single 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.
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.
The 5-in-1 flame sensor combines 5 individual flame sensors on a single PCB. These sensors share a common potentiometer, VCC, and GND, while each sensor's DO (Digital Output) and AI (Analog Input) pins remain independent.
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.
This image is created using Fritzing. Click to enlarge image
To simplify and organize your wiring setup, we recommend using a Screw Terminal Block Shield for Raspberry Pi. This shield ensures more secure and manageable connections, as shown below:
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:
- Create a Python script file flame_sensor.py and add the following code:
- Save the file and run the Python script by executing the following command in the terminal:
- Direct the flame sensor to a flame.
- Check out the result on the Serial Monitor.
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.