Preview build — page text is a draft awaiting human review. Code badges come from real compiles. The flasher is real but not yet hardware-tested; the Playground is still a preview.
Fire & Smoke Alarm: the finished build
UnoIndia utility

Fire and smoke alarm with heat-rise detection (Arduino Uno + MQ-2 + DS18B20)

Smoke, high heat or a fast temperature rise — any one sets off the alarm.

Difficulty
Medium
Build time
1.5 h
Parts cost
₹857 · $10
Verified — core avr 1.8.8, OneWire 2.3.8, 3 Nov 2026Compile-only

Community draft — report a mistake

Parts list

PartQtyApprox.Buy
Arduino Uno R3 (CH340 clone)1₹450Buy Arduino Uno R3 (CH340 clone)
MQ-2 smoke/gas sensor module1₹140Buy MQ-2 smoke/gas sensor module
DS18B20 temperature sensor (TO-92 or waterproof probe)1₹90Buy DS18B20 temperature sensor (TO-92 or waterproof probe)
4.7 kΩ resistor1₹2Buy 4.7 kΩ resistor
Active buzzer module (or a 12 V hooter via a relay)1₹25Buy Active buzzer module (or a 12 V hooter via a relay)
9 V 1 A adapter1₹150Buy 9 V 1 A adapter
Total₹857

Affiliate disclosure: “Buy” links may earn FlashReady a small commission at no extra cost to you. Prices are indicative.

Wiring

Arduino Uno R3Only the pins used are shown · 5 V logicMQ-2 gas sensor moduleDS18B20 (1-Wire)Active buzzer module (high-level trigger)4.7k → 5V5VGNDA0D4D8VCCGNDDO (not connected)AOGNDDQVDDI/OVCCGND
Every connection
Arduino Uno R3Part · pinWireNotes
A0MQ-2 gas sensor module · AOgreen
5VMQ-2 gas sensor module · VCCredHeater draws about 150 mA
GNDMQ-2 gas sensor module · GNDblack
D4DS18B20 (1-Wire) · DQyellow
5VDS18B20 (1-Wire) · DQredVia 4.7 kΩ — Pull-up from DQ to 5 V
5VDS18B20 (1-Wire) · VDDred
GNDDS18B20 (1-Wire) · GNDblack
D8Active buzzer module (high-level trigger) · I/Oorange
5VActive buzzer module (high-level trigger) · VCCred
GNDActive buzzer module (high-level trigger) · GNDblack

Board quirks: Smoke rises: mount the MQ-2 and DS18B20 on the ceiling or high on the wall, away from fans and the cooking area. The MQ-2 also reacts to LPG, alcohol and cooking fumes. The heat checks don’t, which is why the alarm uses both. Set SMOKE_LEVEL from the clean-air reading after the 3-minute warm-up (the Serial Monitor prints it every second), with a good margin above it. This is a hobby alarm, not a certified fire detection system. Shops and godowns still need proper smoke detectors and extinguishers.

Code

fire-smoke-alarm.inoArduino C++Open in PlaygroundOpen in PlaygroundFlash
// Fire and smoke alarm — Arduino Uno R3 + MQ-2 + DS18B20 + buzzer module
// MQ-2 AO on A0, DS18B20 data on D4 (4.7 kΩ pull-up to 5V), buzzer module on D8.
// Alarms on smoke OR heat OR a fast temperature rise. A hobby alarm — not a certified
// smoke detector; keep your certified one.
#include <OneWire.h>
#include <DallasTemperature.h>

constexpr uint8_t SMOKE_PIN = A0;
constexpr uint8_t TEMP_PIN = 4;
constexpr uint8_t BUZZER_PIN = 8;
constexpr int SMOKE_LEVEL = 350;     // raw ADC; set after warm-up in clean air
constexpr float HOT_C = 57.0;        // fixed-heat alarm
constexpr float RISE_C_PER_MIN = 8.0;
constexpr unsigned long WARM_UP_MS = 3UL * 60UL * 1000UL;

OneWire bus(TEMP_PIN);
DallasTemperature temp(&bus);
float lastC = NAN;
unsigned long lastTempMs = 0;
float risePerMin = 0;

int readSmoke() {
  long s = 0;
  for (int i = 0; i < 16; i++) s += analogRead(SMOKE_PIN);
  return s / 16;
}

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
  Serial.begin(9600);
  temp.begin();
}

void loop() {
  temp.requestTemperatures();
  float c = temp.getTempCByIndex(0);   // -127 means "no sensor"
  unsigned long now = millis();
  if (c > -100 && !isnan(lastC) && now > lastTempMs) risePerMin = (c - lastC) * 60000.0 / (now - lastTempMs);
  if (c > -100) {
    lastC = c;
    lastTempMs = now;
  }

  int smoke = readSmoke();
  bool warm = now > WARM_UP_MS;
  bool alarm = (warm && smoke > SMOKE_LEVEL) || c > HOT_C || risePerMin > RISE_C_PER_MIN;

  Serial.print(F("smoke="));
  Serial.print(smoke);
  Serial.print(F(" tempC="));
  Serial.print(c, 1);
  Serial.print(F(" rise/min="));
  Serial.print(risePerMin, 1);
  Serial.println(alarm ? F(" ALARM") : F(""));

  digitalWrite(BUZZER_PIN, alarm ? HIGH : LOW);
  delay(1000);
}

Compiled for uno on avr 1.8.8 with OneWire 2.3.8 · 3 Nov 2026

How it works

A small shop or godown full of cardboard needs warning as early as possible. A smoke sensor alone gives false alarms from cooking and incense; a heat sensor alone reacts late. This alarm uses both.

The MQ-2 detects smoke and combustible gases; its analog output on A0 rises as the air gets dirtier. Like all MQ sensors it needs a warm-up, so smoke is ignored for the first 3 minutes after power-on.

The DS18B20 on D4 gives two heat checks. A fixed limit of 57 °C catches a slow fire near the sensor. The rate of rise — more than 8 °C per minute — catches a fast fire before the room gets that hot. These are the same two methods commercial heat detectors use.

Any one of the three conditions turns on the buzzer on D8, and it stays on until all three clear. The Serial Monitor prints the smoke level, temperature and rise rate every second, which you need for setting the thresholds.

Troubleshooting

Temperature shows −127

The DS18B20 isn’t answering. Check the 4.7 kΩ pull-up from DQ to 5 V and that VDD and GND aren’t swapped — a reversed DS18B20 gets very hot.

It alarms in the kitchen when cooking

Move the MQ-2 away from the stove, or raise SMOKE_LEVEL. The heat-rise checks will still catch a real fire.

Rate-of-rise triggers on a sunny afternoon

Sunlight on the sensor can raise it quickly. Shade the DS18B20, or raise RISE_C_PER_MIN.

Upgrades

  • Add a SIM800L to send an SMS — see the gas leak alarm project for the wiring.
  • Use several DS18B20s on one wire to cover different racks in a godown.
  • Add a test button and a monthly self-test beep.

↑↓ to move · Enter to open