Arduino MicroPython Flame Sensor

This guide shows you how to use a flame sensor with an Arduino and MicroPython to detect and measure flames and fire. You will learn:

Arduino MicroPython flame sensor

Then, you can adjust the code to activate a warning horn (using a relay) when it detects fire.

Hardware Preparation

1×Arduino Giga R1 WiFi
1×USB Cable Type-C
1×Flame Sensor
1×5-in-1 5-way Flame Sensor
1×Jumper Wires
1×(Recommended) Screw Terminal Block Shield for Arduino Uno/Mega/Giga
1×(Recommended) Breadboard Shield For Arduino Mega/Giga
1×(Recommended) Enclosure For Arduino Giga
1×(Recommended) Power Splitter For Arduino Giga

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.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of Flame Sensor

infrared flame fire-sensor module

A flame sensor can detect and measure infrared light emitted by a flame, making it ideal for fire detection. Also known as an infrared flame or fire sensor, it provides two types of signals: a digital output (LOW or HIGH) and an analog output.

Infrared flame sensors are specifically designed to detect certain wavelengths of infrared radiation emitted by flames, minimizing false alarms from other infrared sources like human body heat or lights. However, they may still sometimes trigger false alarms or fail to detect actual flames.

Pinout

There are two types of flame sensor modules available:

The single flame sensor has four pins:

  • VCC pin: Connect to the power supply (3.3V to 5V).
  • GND pin: Connect to ground (0V).
  • DO pin: Provides a digital output, which is HIGH when no flame is detected and LOW when a flame is present. The sensitivity to flames can be adjusted using the potentiometer on the board.
  • AO pin: Outputs an analog signal, where the value decreases with lower infrared levels and increases with higher infrared levels.
Flame Sensor Pinout
image source: diyables.io

It also features two LED indicators:

  • The PWR-LED lights up when the sensor is powered on.
  • The DO-LED lights up when a flame is detected.

The 5-in-1 flame sensor integrates five individual flame sensors on a single PCB. These sensors share the same potentiometer, VCC, and GND connections; however, each sensor’s DO (Digital Output) and AI (Analog Input) pins remain independent. In addition, each sensor is oriented in a different direction, expanding the overall detection range.

How It Works

For the DO pin:

  • The module has a potentiometer to set the infrared sensitivity threshold.
  • When the infrared level goes above this threshold, indicating a flame, the sensor's output pin goes LOW, and the DO-LED lights up.
  • When the infrared level is below the threshold, indicating no flame, the sensor's output pin stays HIGH, and the DO-LED remains off.

For the AO pin:

  • A high level of infrared light produces a high reading at the AO pin.
  • A low level of infrared light produces a low reading at the AO pin.
  • The potentiometer does not affect the reading 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.

The wiring diagram between Arduino MicroPython Flame Sensor

This image is created using Fritzing. Click to enlarge image

Arduino MicroPython Code - Read value from DO pin

""" This Arduino MicroPython script was developed by newbiely.com This Arduino MicroPython script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-micropython/arduino-micropython-flame-sensor """ from machine import Pin import utime # For timing functions DO_PIN = Pin('D2', Pin.IN) # The Arduino Giga R1 WiFi pin connected to the DO pin of the flame sensor module while True: flame_state = DO_PIN.value() # Read the digital value from the pin if flame_state == 1: print("The flame is NOT present => The fire is NOT detected") else: print("The flame is present => The fire is detected") utime.sleep(1) # Add a small delay to avoid spamming the output

Detailed Instructions

Here’s instructions on how to run the above MicroPython code on Arduino with Thonny IDE:

  • Make sure Thonny IDE is installed on your computer.
  • Make sure MicroPython firmware is installed on your Arduino board.
  • If you are new to Arduino with MicroPython, see the Getting Started with Arduino and MicroPython.
  • Connect the Arduino board to the flame sensor according to the provided diagram.
  • Connect the Arduino board to your computer with a USB cable.
  • Open Thonny IDE and go to Tools Options.
  • Under the Interpreter tab, select MicroPython (generic) from the dropdown menu.
  • Select the COM port corresponding to your Arduino board (e.g., COM33 on Windows or /dev/ttyACM0 on Linux).
  • Copy the provided Arduino MicroPython code and paste it into Thonny's editor.
  • Save the MicroPython code to your Arduino by:
    • Clicking the Save button or pressing Ctrl+S.
    • In the save dialog, choose MicroPython device and name the file main.py.
  • Click the green Run button (or press F5) to execute the code.
  • Aim the flame sensor at a flame.
  • Check out the message in the Shell at the bottom of Thonny.
Shell x
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot 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
MicroPython (generic) • Giga Virtual Comm Port in FS Mode @ COM33 ≡

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.

Arduino MicroPython Code - Read value from AO pin

""" This Arduino MicroPython script was developed by newbiely.com This Arduino MicroPython script is made available for public use without any restriction For comprehensive instructions and wiring diagrams, please visit: https://newbiely.com/tutorials/arduino-micropython/arduino-micropython-flame-sensor """ from machine import ADC, Pin import utime # For timing functions AO_PIN = ADC(Pin('A0')) # The Arduino Giga WiFi pin connected to the AO pin of the flame sensor module while True: flame_value = AO_PIN.read() # Read the analog value (0-4095) print(flame_value) # Print the analog value utime.sleep(1) # Add a small delay to avoid spamming the output

Detailed Instructions

  • Copy the provided Arduino MicroPython code and paste it into Thonny's editor.
  • Save the code to your Arduino.
  • Click the green Run button (or press F5) to execute the code.
  • Aim the flame sensor at a flame.
  • Check out the message in the Shell at the bottom of Thonny.
Shell x
>>> %Run -c $EDITOR_CONTENT
MPY: soft reboot 195 296 336 563 647 969 975 1055 1106 1216 1319 662 546 344 179
MicroPython (generic) • Giga Virtual Comm Port in FS Mode @ COM33 ≡

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!