Back to Tutorials
Arduino

Fire Detection & Alarm System

Build a fire alarm that detects flame using a flame sensor and immediately triggers a buzzer and red LED alert - a real safety project!

~25 mins Beginner Arduino UNO
Skills & Concepts You'll Gain
Tech Used: Arduino UNO, Flame Sensor Module, Active Buzzer, Red LED, Arduino IDE
Components Needed
  • Arduino UNO
  • 1x Flame Sensor Module
  • 1x Active Buzzer
  • 1x Red LED + 220Ω Resistor
  • Breadboard
  • Jumper Wires
  • USB Cable
Software Required
  • Arduino IDE
Step 1

Understand the Flame Sensor

The flame sensor detects infrared (IR) light that fire produces. It has a small IR receiver that is sensitive to the wavelength of fire light.

The module has 3 pins:

  1. VCC → 5V on Arduino
  2. GND → GND on Arduino
  3. DO (Digital Output) → Pin 7 on Arduino - gives LOW when fire is detected, HIGH when no fire
The flame sensor output is inverted - it gives LOW (0) when fire IS detected and HIGH (1) when there is NO fire. Keep this in mind when writing the code!
Step 2

Wire the Circuit

  1. Flame Sensor: VCC → 5V, GND → GND, DO → Pin 7
  2. Red LED: Positive leg → Pin 6 (via 220Ω resistor), Negative leg → GND
  3. Buzzer: Positive (+) → Pin 8, Negative (-) → GND
Wiring Diagram
Fire Detection Alarm Wiring Diagram
Keep the flame sensor away from direct sunlight and strong light sources, as they can cause false fire detection due to infrared interference.
Step 3

Write the Code by opening Arduino UNO

fire_detection.ino
// Fire Detection & Alarm - NKDevSpace Tutorial

const int flameSensor = 7;
const int redLED      = 6;
const int buzzerPin   = 8;

void setup() {
  pinMode(flameSensor, INPUT);
  pinMode(redLED, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("Fire Detection System Ready!");
}

void loop() {
  int flameStatus = digitalRead(flameSensor);

  // Flame sensor gives LOW when fire is detected
  if (flameStatus == LOW) {
    Serial.println("🔥 FIRE DETECTED! ALARM ON!");
    digitalWrite(redLED, HIGH);   // Red LED ON
    tone(buzzerPin, 2000);        // Buzzer alarm at 2000 Hz
  } else {
    Serial.println("✅ No fire. All safe.");
    digitalWrite(redLED, LOW);    // Red LED OFF
    noTone(buzzerPin);            // Buzzer OFF
  }

  delay(500);  // Check every 0.5 seconds
}
Step 4

Code Explanation

digitalRead(flameSensor)
Reads the flame sensor pin. It returns either 0 (LOW) or 1 (HIGH). Since the sensor is inverted, LOW means fire detected.
if (flameStatus == LOW)
This checks if fire is detected. Remember - the sensor gives LOW when it sees fire. So we check for LOW, not HIGH. This is the inverted logic of the sensor.
tone(buzzerPin, 2000)
Activates the buzzer at 2000 Hz - a high-pitched alarm sound. You can change the frequency to make it sound different. noTone() silences it.
delay(500)
The system checks for fire every 500 milliseconds (0.5 seconds). This is fast enough to detect fire quickly without overloading the Arduino.
Step 5

Test the Project

  1. Make sure your Arduino Uno is connected to your laptop using a USB cable
  2. If not already selected, choose the correct settings:
    • Go to Tools → Board → Arduino AVR Boards → Arduino Uno
    • Go to Tools → Port → COM X(COM 3, COM4, ...) (Arduino Uno)
  3. Open Tools → Serial Monitor
  4. Set the baud rate to 9600
  5. You should see the message "No fire. All safe." repeating every 0.5 seconds
  6. Check that the LED is OFF and the buzzer is silent in normal condition
  7. Now carefully bring a lit candle or lighter near the flame sensor (keep safe distance)
  8. When fire is detected:
    • Red LED turns ON
    • Buzzer starts making sound
    • Serial Monitor shows Fire detected
  9. Move the flame away from the sensor
  10. The system should return to normal:
    • LED turns OFF
    • Buzzer stops
    • Message changes back to "No fire. All safe."
Safety first! Keep the flame at least 10-15 cm away and never leave it unattended.
Step 6

Try It Yourself - Challenges

Previous Tutorial Next Tutorial