Raspberry Pi Pico - Flame Sensor
This tutorial instructs you how to use a Raspberry Pi Pico and a flame sensor to detect and measure flames and fire. We will cover these topics:
- How to connect a flame sensor to a Raspberry Pi Pico.
- How to program the Raspberry Pi Pico to detect fire using the digital signal from the flame sensor.
- How to program the Raspberry Pi Pico to measure flame intensity with the analog signal from the flame sensor.
Then, you can adjust the code to activate a warning horn (using a relay) when it detects fire.
Hardware Preparation
1 | × | Raspberry Pi Pico W | |
1 | × | Raspberry Pi Pico (Alternatively) | |
1 | × | Micro USB Cable | |
1 | × | Flame Sensor | |
1 | × | Jumper Wires | |
1 | × | Breadboard | |
1 | × | (Optional) Screw Terminal Expansion Board for Raspberry Pi Pico |
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 flame sensor can sense and measure infrared light from a flame, useful for fire detection. It is also called an infrared flame 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 infrared radiation wavelengths emitted by flames. They aim to minimize false alarms from other infrared sources such as human body heat or lights. Yet, these sensors can sometimes make errors, either by signaling an alarm for something that isn't there or failing to detect actual flames.
Pinout
The flame sensor has four metal parts called pins.
- VCC pin: Connect this to VCC (3.3V to 5V).
- GND pin: Connect this to GND (0V).
- DO pin: This pin gives a digital output. It is HIGH when there is no flame and LOW when there is a flame. You can adjust the sensitivity to flames using a potentiometer on the board.
- AO Garage Pin: This pin sends out an analog signal. The signal value decreases as the infrared level drops and increases as the infrared level rises.
It also includes two LED lights.
- One PWR-LED light indicates when the power is on.
- One DO-LED light indicates when a flame is detected.
How It Works
Regarding the DO pin:
- The module has a potentiometer to set the infrared threshold (sensitivity).
- When the infrared level is above the threshold, it detects a flame, the sensor’s output pin becomes LOW, and the DO-LED turns on.
- When the infrared level is below the threshold, no flame is detected, the sensor’s output pin is HIGH, and the DO-LED remains off.
For the AO pin:
- If there is a lot of infrared light, the AO pin reading will be high.
- If there is a little infrared light, the AO pin reading will be low.
The potentiometer does not alter the value at the AO pin.
Wiring Diagram
The flame sensor module provides two output options. You can use one or both based on what you need.
This image is created using Fritzing. Click to enlarge image
Raspberry Pi Pico Code - Read value from DO pin
Detailed Instructions
Please follow these instructions step by step:
- Ensure that Thonny IDE is installed on your computer.
- Ensure that MicroPython firmware is installed on your Raspberry Pi Pico.
- If this is your first time using a Raspberry Pico, refer to the Raspberry Pi Pico - Getting Started tutorial for detailed instructions.
- Connect the Raspberry Pi Pico to the flame sensor according to the provided diagram.
- Connect the Raspberry Pi Pico to your computer using a USB cable.
- Launch the Thonny IDE on your computer.
- On Thonny IDE, select MicroPython (Raspberry Pi Pico) Interpreter by navigating to Tools Options.
- In the Interpreter tab, select MicroPython (Raspberry Pi Pico) from the drop-down menu.
- Ensure the correct port is selected. Thonny IDE should automatically detect the port, but you may need to select it manually (e.g., COM3 on Windows or /dev/ttyACM0 on Linux).
- Copy the above code and paste it to the Thonny IDE's editor.
- Save the script to your Raspberry Pi Pico by:
- Click the Save button, or use Ctrl+S keys.
- In the save dialog, you will see two sections: This computer and Raspberry Pi Pico. Select Raspberry Pi Pico
- Save the file as main.py
- Click the green Run button (or press F5) to run the script. The script will execute.
- Aim the flame sensor at a flame.
- Check out the message in the Shell at the bottom of Thonny.
If the LED light is always on or off, even when the sensor is facing a flame, you can turn the potentiometer to change the sensor's sensitivity.
Raspberry Pi Pico Code - Read value from AO pin
Detailed Instructions
- Copy the provided MicroPython code and paste it into Thonny's editor.
- Save the code to your Raspberry Pi Pico.
- Click the green Run button (or press F5) to execute the script.
- Aim the flame sensor at a flame.
- Check out the message in the Shell at the bottom of Thonny.