Note

Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.

Why Join?

  • Expert Support: Solve post-sale issues and technical challenges with help from our community and team.

  • Learn & Share: Exchange tips and tutorials to enhance your skills.

  • Exclusive Previews: Get early access to new product announcements and sneak peeks.

  • Special Discounts: Enjoy exclusive discounts on our newest products.

  • Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.

👉 Ready to explore and create with us? Click [here] and join today!

Lesson 03: Flame Sensor Module

In this lesson, you will learn how to connect a flame sensor to an ESP32 Development Board for fire detection. We’ll examine the sensor’s response to fire and how it triggers a warning message. This project is ideal for beginners working with sensors and ESP32, providing hands-on experience in monitoring environmental factors using basic electronic components.

Required Components

In this project, we need the following components.

It’s definitely convenient to buy a whole kit, here’s the link:

Name

ITEMS IN THIS KIT

LINK

Universal Maker Sensor Kit

94

Universal Maker Sensor Kit

You can also buy them separately from the links below.

Component Introduction

Purchase Link

ESP32 & Development Board (ESP32 Board)

BUY

Flame Sensor Module

BUY

Breadboard

BUY

Wiring

../_images/Lesson_03_Flame_Sensor_Module_esp32_bb.png

Code

Code Analysis

  1. Defining the Sensor Pin:

    The pin to which the flame sensor is connected is defined as an integer constant.

    const int sensorPin = 25;
    
  2. Setup Function:

    This function runs once when the ESP32 starts. It initializes the sensor pin as an input and begins serial communication at 9600 baud rate for output.

    void setup() {
      pinMode(sensorPin, INPUT);
      Serial.begin(9600);
    }
    
  3. Loop Function:

    The core of the program, it continuously checks the state of the flame sensor. If the sensor detects a flame (returns 0), it prints a fire alert message. Otherwise, it indicates no fire is detected. The check happens every 100 milliseconds.

    void loop() {
      if (digitalRead(sensorPin) == 0) {
        Serial.println("** Fire detected!!! **");
      } else {
        Serial.println("No Fire detected");
      }
      delay(100);
    }