Short answer: an Arduino UNO, MQ-2 sensor, optional infrared flame sensor, buzzer and LEDs can make a useful low-voltage hazard-warning prototype. It can report relative responses associated with smoke and combustible vapors and warn when a flame sensor responds. It is not a certified smoke alarm, carbon-monoxide alarm, gas detector or fire-alarm system.
Safety first: install and maintain listed smoke, carbon-monoxide and combustible-gas alarms where appropriate. Do not use this Arduino project as the only protection for a home, workplace, rental property or vehicle.
As an Amazon Associate I earn from qualifying purchases.
What this project detects
“Fire and smoke (gas)” describes several different hazards that should not be treated as one measurement:
- Smoke: airborne particles. An MQ-2 may respond to smoke, but it is not the same technology as a listed photoelectric or ionization smoke alarm.
- Combustible gas and vapour: the MQ-2 has a broad response that can include LPG, propane, methane, hydrogen, alcohol vapour and smoke. It does not identify which gas caused the reading or automatically measure concentration in ppm. See the MQ-2 technical overview.
- Flame: an infrared flame module can respond to a visible flame within its field of view, but it may miss shielded, distant or smouldering fires and can react to other infrared sources.
- Heat: an added temperature sensor can provide useful corroboration, but temperature alone is usually too slow or location-dependent to be the sole fire indicator.
- Carbon monoxide: do not treat an MQ-2 as a dependable CO alarm.
The honest description is: this circuit detects sensor responses associated with smoke, combustible gases and visible flame. It does not identify every fire, measure every gas or guarantee an alarm.
#1 Best Overall
- TURN CODE INTO REAL-WORLD RESULTS — Follow 22+ guided lessons to make LEDs blink, read temperature and distance, move servo and stepper motors, control an LCD and respond to joystick or IR input; ideal for a family weekend build, homeschool unit, coding club or STEM classroom
- MORE PROJECT VARIETY IN ONE ORGANIZED KIT — Includes the UNO R3 controller, LCD1602 with pre-soldered header, breadboard power module, ultrasonic and DHT11 sensors, joystick, IR receiver and remote, SG90 servo, stepper motor, relay, DC motor, fan blade, displays, LEDs, buttons, resistors and jumper wires
- START WITHOUT SOLDERING — Plug-in modules, a solderless breadboard and the pre-soldered LCD help beginners focus on wiring, code and testing; the illustrated component list makes it easier to find each part and move from one lesson to the next
- LEARN THE LOGIC, THEN CREATE YOUR OWN — Use Arduino IDE and the included example code to understand digital input and output, analog sensing, timing, motor control and display functions, then change thresholds, speeds and sequences for alarms, environmental monitors, reaction games and motion projects
- CLEAR SETUP SUPPORT FOR FIRST-TIME BUILDERS — Download the latest tutorial and code, select the UNO board and correct computer port, check component polarity and breadboard rows, and keep power-module input at 9V or below; younger learners should work with an experienced adult
How the system works
The UNO reads the MQ-2’s analogue output, optionally reads a flame module, filters the readings and compares them with thresholds established for the particular sensor and environment. When a condition persists—or when the flame input responds—it activates a buzzer and warning LED.
The official UNO R3 uses an ATmega328P, with six analogue inputs, 14 digital I/O pins and a 16 MHz clock—enough for this educational circuit. See Arduino’s UNO overview and the UNO Rev3 specifications.
MQ-2 analogue output -> A0
Flame sensor output -> D2
Buzzer -> D8
Red LED -> D9 through resistor
Green LED -> D10 through resistor
Optional I2C display -> A4/A5
A robust prototype should use a warm-up period, averaging or median filtering, a threshold above the clean-air baseline, hysteresis, several consecutive high readings and a latched alarm that requires a deliberate reset.
Parts list
- Arduino UNO R3 or compatible UNO board
- MQ-2 smoke/flammable-gas sensor module
- Optional infrared flame sensor module
- Active buzzer or piezo buzzer
- Red and green LEDs
- 220–330 Ω resistors for the LEDs
- Breadboard and jumper wires
- USB cable or correctly regulated external supply
- Optional reset pushbutton, display and temperature sensor
Many MQ-2 modules are designed around a 5 V supply and include a heater that consumes substantially more power than a simple passive sensor. Check the exact module’s documentation. Never connect a bare sensor heater to an Arduino I/O pin.
Wiring
MQ-2 module
| MQ-2 pin | UNO connection |
|---|---|
| VCC | 5 V, if supported by the module |
| GND | GND |
| AO | A0 |
| DO | Optional digital input |
Use AO for this project because it provides a varying reading. DO is only the output of the module’s onboard comparator. Its potentiometer changes the comparator trip point; it does not calibrate the sensor in ppm. SunFounder’s MQ-2 UNO lesson also notes the need for sensor preheating.
Rank #2
- 30+ Guided Electronics Projects: Start with LEDs and build toward LCD1602 displays, RFID access, motion detection, distance sensing, motor control and environmental monitoring for STEM learning, coding clubs, classrooms and hobby projects
- 200+ Components Across 63 Types: Includes an ELEGOO UNO R3 controller, LCD1602, RC522 RFID, RTC, HC-SR501 PIR sensor, ultrasonic sensor, DHT11, GY-521, MAX7219, keypad, joystick, relay, SG90 servo, stepper motor, breadboard and more
- Begin Without Soldering: Pre-soldered modules, a solderless breadboard, organized storage case and small-parts box reduce setup time and help beginners move from lesson to lesson while keeping LEDs, ICs, wires and sensors easy to find
- Learn, Modify and Create: Program the ELEGOO UNO R3 board with Arduino IDE using the included PDF tutorial and example code, then adjust sensor thresholds, timing, display text and motor behavior to turn guided lessons into original projects
- Flexible Power and Project Setup: Includes a 9 V, 1 A power supply, breadboard power module, 9 V battery and USB cable to support controller, breadboard and module experiments without sourcing basic setup accessories separately
Flame module
| Flame pin | UNO connection |
|---|---|
| VCC | 5 V, according to the module specification |
| GND | GND |
| DO | D2 |
| AO | Optional A1 |
Flame modules do not all use the same logic polarity. Confirm whether the output is LOW or HIGH in the presence of a flame before changing the code.
Buzzer and LEDs
| Device | Connection |
|---|---|
| Buzzer signal | D8 |
| Red LED anode | D9 through a 220–330 Ω resistor |
| Green LED anode | D10 through a 220–330 Ω resistor |
| LED cathodes | GND |
For a larger siren, relay, motor or other high-current load, use a suitable transistor or MOSFET driver, a separate regulated supply and a flyback diode where appropriate. Never switch mains voltage on a breadboard. A relay controlling a gas valve or fuel appliance is a safety-critical installation, not a casual upgrade.
Recommended Free Tools
Arduino sketch
This sketch is an educational starting point. The threshold values are deliberately not presented as universal danger limits.
const byte MQ2_PIN = A0;
const byte FLAME_PIN = 2;
const byte BUZZER_PIN = 8;
const byte RED_LED_PIN = 9;
const byte GREEN_LED_PIN = 10;
const byte RESET_PIN = 7;
// Adjust after observing clean-air readings.
int gasAlarmThreshold = 650;
int gasClearThreshold = 600;
// Set true when the flame module reports LOW with flame present.
const bool flameActiveLow = true;
const unsigned long warmupTime = 60000UL;
const byte samplesPerReading = 10;
const byte requiredHighReads = 3;
bool alarmLatched = false;
byte highReadCount = 0;
int readGasAverage() {
long total = 0;
for (byte i = 0; i < samplesPerReading; i++) {
total += analogRead(MQ2_PIN);
delay(10);
}
return total / samplesPerReading;
}
bool flameDetected() {
int state = digitalRead(FLAME_PIN);
return flameActiveLow ? (state == LOW) : (state == HIGH);
}
void setAlarm(bool enabled) {
digitalWrite(RED_LED_PIN, enabled ? HIGH : LOW);
digitalWrite(GREEN_LED_PIN, enabled ? LOW : HIGH);
digitalWrite(BUZZER_PIN, enabled ? HIGH : LOW);
}
void setup() {
pinMode(FLAME_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(RED_LED_PIN, OUTPUT);
pinMode(GREEN_LED_PIN, OUTPUT);
pinMode(RESET_PIN, INPUT_PULLUP);
Serial.begin(9600);
setAlarm(false);
Serial.println(F("MQ-2 warning prototype"));
Serial.println(F("Allowing sensor warm-up..."));
unsigned long start = millis();
while (millis() - start < warmupTime) delay(100);
Serial.println(F("Monitoring started."));
}
void loop() {
int gasValue = readGasAverage();
bool flame = flameDetected();
Serial.print(F("Gas/smoke raw value: "));
Serial.print(gasValue);
Serial.print(F(" | Flame: "));
Serial.println(flame ? F("YES") : F("NO"));
bool gasHigh = gasValue >= gasAlarmThreshold;
if (gasHigh) {
if (highReadCount < requiredHighReads) highReadCount++;
} else if (gasValue <= gasClearThreshold) {
highReadCount = 0;
}
if (flame || highReadCount >= requiredHighReads) alarmLatched = true;
if (digitalRead(RESET_PIN) == LOW) {
alarmLatched = false;
highReadCount = 0;
delay(250);
}
setAlarm(alarmLatched);
delay(250);
}
Upload and observe readings
- Install the Arduino IDE.
- Connect the UNO by USB.
- Select the correct UNO board and serial port.
- Upload the sketch.
- Open Serial Monitor at 9600 baud.
- Watch the raw MQ-2 value and flame state during warm-up and normal operation.
UNO analogue readings are nominally represented from 0 to 1023 in the standard Arduino environment, but that number is an ADC reading—not a gas concentration. Sensor voltage, board reference, module design and environmental conditions all matter.
Calibrate the MQ-2 instead of copying a threshold
- Place the sensor in clean, normally ventilated air.
- Allow it to warm up and stabilise. The 60-second delay above is only a practical educational delay; some measurements require longer.
- Record readings for several minutes and note the average and normal variation.
- Set the alarm threshold above that baseline.
- Set the clear threshold lower than the alarm threshold to create hysteresis.
- Repeat the observation in the actual environment because kitchens, garages, workshops and bedrooms have different vapours and airflow.
For example, a baseline of 280–340, normal variation of about ±20, an initial alarm threshold of 450–500 and a clear threshold of 400–450 could be a starting experiment. These figures are illustrative only, not validated safety limits.
Rank #3
- The most economical kit comes with everything compatible with Arduino to starting programming for beginners .
- This is the upgraded starter kits come with a 9V 1A Power Adapter (At least $5.99 on amazon) to replace a 9V Battery , and the Lcd1602 module come with pin header(not need to be soldered by yourself).
- Include High Quality Base Board base on Arduino UNO R3 compatible with Arduino IED and Sensors, Servo, Motor, ULN2003 driver board, lcds, etc.
- Free PDF Tutorial and Datasheet are available to download from our official website or you can contact our customer service.
- All of the Components and Integrated Circuits are individually packaged and labeled, and packing in a plastic box which is bigger enough for you.
Do not convert a raw value such as 700 directly into “unsafe” or a ppm figure. Proper quantitative measurement requires a gas-specific calibration model, controlled concentrations and defined environmental conditions. The MQ-2 is cross-sensitive, drifts during warm-up, varies between modules and can be affected by humidity, temperature, contamination and age.
Test safely
Use low-risk demonstrations such as incense smoke at a safe distance, while keeping the sensor and electronics away from heat, flame, grease, water and strong drafts. Test the flame module only under controlled supervision and away from combustible materials.
Do not deliberately release LPG, methane, propane, hydrogen or other combustible gas indoors. Do not put the MQ-2 over an open cooking flame, and do not place a lighter or candle near a breadboard power supply as a casual demonstration.
A successful test means the circuit reports a changed reading, applies the intended persistence and hysteresis rules, activates the warning output and can be reset deliberately. It does not prove that the device will detect every real fire or gas release.
Important limitations and failure modes
- False alarms: cooking fumes, alcohol vapour, aerosols and cleaning chemicals may affect the MQ-2.
- Missed events: gas may not reach the sensor, or a concentration may remain below its response level.
- No gas identification: a high value does not reveal which substance caused it.
- Flame blind spots: infrared sensing needs a suitable line of sight and may be affected by sunlight, lamps and reflections. It will not reliably detect a smouldering fire without flame.
- Startup drift: the heated sensor needs stabilisation and may continue to drift.
- Power failure: a single failed 5 V supply can disable sensing and alarming at once.
- Software faults: an Arduino can reset, hang or be affected by electrical noise.
- Installation weakness: breadboards and jumper wires are not suitable for a permanent fire-protection installation.
- Human-factor weakness: a local buzzer is ineffective if nobody is present or it cannot be heard.
Troubleshooting
The alarm stays on
Check whether the sensor is still warming up, whether the threshold is above the clean-air baseline, and whether cooking vapour, alcohol, aerosol or cleaning products are present. Confirm that the flame logic is not inverted.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsRank #4
- LEARN ELECTRONICS AND CODING FROM SCRATCH: Start your maker journey or enhance classroom learning with the Arduino Starter Kit R4 – no prior experience required. Includes a printed project book and all components for 13 hands-on tutorials, as well as access to a growing repository of projects that will be added over time.
- POWERED BY THE ARDUINO UNO R4 WIFI BOARD: Discover modern connectivity and performance with the Arduino UNO R4 WiFi, featuring built-in Wi-Fi and Bluetooth and full compatibility with the Arduino ecosystem.
- CERTIFICATION VOUCHER INCLUDED: Once you’ve mastered sensors, motors, displays, and logic through the projects, take the official Arduino Fundamentals certification exam with the voucher that comes with your kit.
- BONUS DIGITAL RESOURCES: Register your kit online to unlock extra projects, multilingual lessons (Italian, German, French), and exclusive online content designed by the Arduino team.
- DESIGNED FOR LEARNING AND TEACHING: Ideal for classrooms, labs, or self-learners. Combine hands-on experiments with clear explanations and an AI coding assistant to support you as you grow.
Nothing triggers the alarm
Confirm common ground, the MQ-2 supply voltage, the AO-to-A0 connection, the selected serial port and the actual readings in Serial Monitor. Check that the threshold has not been copied from a different module.
The flame sensor behaves backwards
Print the digital state with and without a flame, then change flameActiveLow to match the module.
The buzzer is silent or the UNO resets
Check whether the buzzer is active-high or active-low and measure its current requirement. A larger buzzer or siren needs a transistor or MOSFET driver and a separate suitable supply. Keep noisy loads away from the sensor supply.
The alarm stops when USB is unplugged
The USB connection was supplying power. Use a correctly regulated external supply that meets the UNO and sensor requirements, and test the complete system—including startup and power loss—without a computer.
Free tools Windows power users keep installed
One-click scans. No signup required.
Ways to improve the prototype
- Add a manually accessible test and reset button.
- Use a loud external alarm through a properly rated driver.
- Add temperature or rate-of-rise sensing as corroboration.
- Implement sensor-disconnected and out-of-range diagnostics rather than treating every reading as normal.
- Add watchdog, brownout and power-failure handling.
- Use battery backup with low-battery monitoring.
- Store calibration data and event history in nonvolatile memory.
- Move from a breadboard to a soldered PCB and suitable ventilated enclosure.
- Retain a local alarm even if adding Wi-Fi, cellular or network notifications.
Any connection to mains wiring, fuel appliances, gas valves, suppression equipment or building alarm wiring should be engineered and inspected by a qualified professional.
Best Value
- All-in-One Starter Kit for Beginners: Part of the Powered by Arduino program, this kit includes an original Arduino UNO R4 WiFi, 300+ high-quality components, 50+ hands-on projects (30 basic, 13 fun, and 8 IoT), and 100+ free video lessons co-created with renowned educator Paul McWhorter. Designed for beginners ages 8+, it provides a complete, step-by-step path to learn Arduino, electronics, coding, and IoT. RoHS compliant for added safety and quality, it also makes a thoughtful gift for tech enthusiasts, students, and aspiring makers for birthdays, holidays, and special occasions
- Powerful Arduino Uno R4 WiFi Board: Upgraded from the Arduino Uno R3, the Arduino Uno R4 WiFi features a 32-bit processor, more memory, and built-in WiFi and Bluetooth, enabling connection to third-party apps for more interactive and practical projects.
- 300+ Components for Endless Possibilities: With 300+ components and sensors, this kit is perfect for portable projects. It features step-by-step tutorials, open-source code, and compatibility with other Arduino boards like Uno R3 and Nano, offering endless customization and learning opportunities.
- Engaging Projects for Every Skill Level: Featuring 50 projects (30 basic, 13 fun, 8 IoT) with IoT app integration like Arduino IoT Cloud , this kit supports Arduino C++ programming, making it perfect for students, teachers, and engineers to learn, code, and create at any skill level.
- Dedicated Support for Beginners: Alongside online resources and video tutorials, SunFounder provides technical support and troubleshooting forums to help beginners solve programming challenges with ease.
Is this safe to use as a real fire alarm?
No—not by itself. A classroom or workshop prototype lacks the product testing, supervised wiring, fault monitoring, backup-power behaviour, enclosure requirements, maintenance regime and regulatory evaluation of a listed alarm.
NFPA 72 materials refer to complete product standards including UL 217 for smoke alarms, UL 268 for smoke detectors, UL 1484 for residential gas detectors and UL 2034 for carbon-monoxide alarms. These standards apply to complete products and systems, not merely an UNO sketch and sensor module. See the NFPA 72 publication page and relevant NFPA materials.
The applicable NFPA edition and local requirements depend on the jurisdiction and authority having jurisdiction. Use manufacturer instructions and local rules when installing life-safety equipment.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Better choices for different goals
| Goal | Better choice |
|---|---|
| Protect a home from smoke | Listed residential smoke alarms, interconnected where appropriate |
| Detect carbon monoxide | Listed CO alarm |
| Detect a known combustible gas | Listed detector designed for that gas and installation environment |
| Learn analogue sensing | UNO plus MQ-2 as an educational prototype |
| Monitor a connected project | An Arduino-compatible connected board, alongside independent listed alarms |
| Protect an industrial or hazardous location | A certified commercial fire-and-gas system designed for that environment |
Photoelectric and ionization smoke technologies respond differently to smouldering and flaming fires; a listed alarm using appropriate tested technology is therefore a better protection choice than attempting to reproduce life-safety performance with a broad MQ sensor.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




