Parts list
| Part | Qty | Approx. | Buy |
|---|---|---|---|
| Arduino Uno R3 (CH340 clone) | 1 | ₹450 | Buy Arduino Uno R3 (CH340 clone) |
| MQ-2 smoke/gas sensor module | 1 | ₹140 | Buy MQ-2 smoke/gas sensor module |
| DS18B20 temperature sensor (TO-92 or waterproof probe) | 1 | ₹90 | Buy DS18B20 temperature sensor (TO-92 or waterproof probe) |
| 4.7 kΩ resistor | 1 | ₹2 | Buy 4.7 kΩ resistor |
| Active buzzer module (or a 12 V hooter via a relay) | 1 | ₹25 | Buy Active buzzer module (or a 12 V hooter via a relay) |
| 9 V 1 A adapter | 1 | ₹150 | Buy 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 R3 | Part · pin | Wire | Notes |
|---|---|---|---|
| A0 | MQ-2 gas sensor module · AO | green | |
| 5V | MQ-2 gas sensor module · VCC | red | Heater draws about 150 mA |
| GND | MQ-2 gas sensor module · GND | black | |
| D4 | DS18B20 (1-Wire) · DQ | yellow | |
| 5V | DS18B20 (1-Wire) · DQ | red | Via 4.7 kΩ — Pull-up from DQ to 5 V |
| 5V | DS18B20 (1-Wire) · VDD | red | |
| GND | DS18B20 (1-Wire) · GND | black | |
| D8 | Active buzzer module (high-level trigger) · I/O | orange | |
| 5V | Active buzzer module (high-level trigger) · VCC | red | |
| GND | Active buzzer module (high-level trigger) · GND | black |
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 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);
}// 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.



