Arduino Project

Flame Monitor 1.0

Course Introduction

In this lesson, you’ll learn how to use a Flame Sensor and an OLED Display with the Arduino UNO R4. The OLED shows the flame intensity in real time and alerts with “FIRE!” when a flame is detected.

Note

If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.

1.1 Install Arduino IDE(Important)
1.2 Introduction of Arduino IDE

Required Components

In this project, we need the following components:

SN

COMPONENT INTRODUCTION

QUANTITY

PURCHASE LINK

1

Arduino UNO R4 Minima

1

2

USB Type-C cable

1

×

3

Breadboard

1

BUY

4

Wires

Several

5

Flame Sensor Module

1

6

OLED Display Module

1

Wiring

5.png__PID:7823423b-e098-49ea-9f40-7407d4a9e8ac

Common Connections:

Flame Sensor Module
A0:
Connect to A0 on the Arduino.
GND: Connect to breadboard’s negative power bus.
VCC: Connect to breadboard’s red power bus.

OLED Display Module
SDA:
Connect to A4 on the Arduino.
SCK: Connect to A5 on the Arduino.
GND: Connect to breadboard’s negative power bus.
VCC: Connect to breadboard’s red power bus.

Writing the Code

Note
You can copy this code into Arduino IDE.
To install the library, use the Arduino Library Manager and search for Adafruit SSD1306 and Adafruit GFX and install it.
Don’t forget to select the board(Arduino UNO R4 Minima/WIFI) and the correct port before clicking the Upload button.


#include 
#include 
#include 
#include 

#define SCREEN_WIDTH 128   // OLED display width in pixels
#define SCREEN_HEIGHT 64   // OLED display height in pixels

#define OLED_RESET -1      // Reset pin (not used here)
#define SCREEN_ADDRESS 0x3C // I2C address of the OLED display
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

#define FLAME_PIN A0       // Analog pin connected to the flame sensor

void setup() {
  Serial.begin(9600);                         // Start serial communication
  Serial.println(F("Flame Sensor with OLED test!"));

  // Initialize the OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Stop if OLED initialization fails
  }

  display.clearDisplay();                     // Clear the display buffer
  display.setTextColor(WHITE);                // Set text color to white
}

void loop() {
  // Read the analog value from the flame sensor (0–1023)
  int rawValue = analogRead(FLAME_PIN);

  // Invert the value: lower = no fire, higher = fire detected
  int flameValue = 1023 - rawValue;

  // Detect fire if the value is higher than 300 (adjust as needed)
  bool fireDetected = (flameValue > 300);

  // Print sensor data to the Serial Monitor
  Serial.print("Flame Sensor Value: ");
  Serial.println(flameValue);
  if (fireDetected) {
    Serial.println("** Fire detected!!! **");
  } else {
    Serial.println("No Fire detected");
  }

  // Clear previous display content
  display.clearDisplay();

  // Display the flame intensity value
  display.setTextSize(1);              // Small text for label
  display.setCursor(0, 0);             // Set cursor at the top-left
  display.println("Flame Intensity:");

  display.setTextSize(2);              // Larger text for the value
  display.setCursor(0, 10);            // Move slightly down
  display.print(flameValue);

  // Display flame status message
  display.setTextSize(1);              // Small text for label
  display.setCursor(0, 40);            // Lower part of the screen
  display.println("Status:");

  display.setTextSize(2);              // Larger text for status message
  display.setCursor(0, 50);            // Bottom area for output
  if (fireDetected) {
    display.print("FIRE!");
  } else {
    display.print("SAFE");
  }

  // Update the OLED with new content
  display.display();

  // Short delay before next reading
  delay(500);
}