MyRoboPathOpen Robotics Lab
Arduino Uno #20 of 35
Est. 0.75 Hours
Budget: $3 - $6
Beginner

MQ-2 Combustible Gas & Smoke Safety Detector

Monitor LPG, methane, propane, and smoke concentration using a heated SnO2 semiconductor gas sensor and safety alarm.

Build an environmental gas and smoke alarm monitor with the MQ-2 metal-oxide sensor module. Understand internal heater preheat stabilization, capture clean-air baseline ADC values, and trigger staged Warning/Danger LED and piezo alerts when combustible vapors rise.

Arduino Uno R3MQ-2 Gas SensorSnO2 Heater CoilSafety Alarm LogicAnalog PPM Trend
MQ-2 Combustible Gas & Smoke Safety Detector Blueprint
MQ-2 Combustible Gas & Smoke Safety DetectorCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Understand SnO2 chemiresistive gas sensing and why the internal 5V heater needs a warm-up period.
2Capture a dynamic clean-air baseline at startup so room humidity shifts do not cause false alarms.
3Implement multi-tier safety alerts (Safe → Elevated → Danger Siren) using analog delta thresholds.
4Follow lab safety practices when testing gas sensors (use rubbing alcohol vapor, never open flames!).

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

The MQ-2 contains a 5V Nichrome heating coil drawing ~150mA continuously to activate its tin-dioxide (SnO2) sensing layer. Ensure a solid USB port capable of 500mA when running alongside LEDs and a buzzer. SAFETY: Internal heater warms the metal mesh noticeably—do not touch while powered. Educational prototype only; never replace certified UL/EN home smoke alarms!

MQ-2 Combustible Gas & Smoke Safety Detector Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for MQ-2 Combustible Gas & Smoke Safety Detector
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P @ 16MHz1$8.00
MQ-2 Gas & Smoke Sensor ModuleDetects LPG, propane, methane, H2, smoke (300–10000ppm)1$2.50
Green & Red LEDs + 220Ω ResistorsSafe vs Hazard status indicators2$0.30
5V Piezo BuzzerAudible warning alarm on D81$0.80

Electrical & System Architecture

Connect MQ-2 VCC to 5V, GND to GND, AO to A0, and DO to D2. Wire a Red Hazard LED (+220Ω) to D7, Green Safe LED (+220Ω) to D6, and Piezo Buzzer to D8.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for MQ-2 Combustible Gas & Smoke Safety Detector.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for MQ-2 Combustible Gas & Smoke Safety Detector.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling MQ-2 Combustible Gas & Smoke Module acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for MQ-2 Combustible Gas & Smoke Safety Detector.
Figure: Firmware execution flow and state transitions for MQ-2 Combustible Gas & Smoke Safety Detector.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Review Gas Sensor Thermal & Testing Safety

Duration: 5 Mins

Place the MQ-2 in a well-ventilated area where the warm stainless-steel mesh cannot touch plastic or skin.

MQ-2 Combustible Gas & Smoke Safety Detector hardware layout diagram
Stage 1: MQ-2 Combustible Gas & Smoke Module hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • Inspect the 4 pins on the MQ-2 module: VCC, GND, DO, AO.
  • Position the sensor upright on the breadboard with clear airflow.
  • For safe testing, use a cotton swab dipped in rubbing alcohol (isopropyl vapor)—never use open flame!
Engineering & Tuning Tip: Brand-new MQ-2 sensors settle best after running continuously for 10–20 minutes on first use.
2

Wire MQ-2, Status LEDs & Piezo Buzzer

Duration: 10 Mins

Connect the sensor to A0/D2, Green LED to D6, Red LED to D7, and Buzzer to D8.

MQ-2 Combustible Gas & Smoke Safety Detector breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • Wire MQ-2 VCC → 5V, GND → GND, AO → A0, DO → D2.
  • Wire Green LED (+220Ω) to D6 and Red LED (+220Ω) to D7.
  • Wire Piezo Buzzer (+) to D8 and (-) to GND.
Engineering & Tuning Tip: Notice the MQ-2 draws ~150mA—make sure your breadboard power jumpers sit tightly.
3

Verify Heater Warm-Up & Baseline Reading

Duration: 5 Mins

Power up and observe raw AO drop gradually as the heater reaches operating temperature.

MQ-2 Combustible Gas & Smoke Safety Detector power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (≈150–160mA heater)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • Upload the diagnostic snippet and open Serial Monitor.
  • Watch raw A0 start high (~400–600) and settle steadily toward a clean-air baseline (~100–250).
  • Confirm the sensor housing becomes gently warm to the touch nearby.
Engineering & Tuning Tip: Never calibrate during the first 10 seconds—always let the SnO2 heater stabilize first.
4

Upload Dual-Stage Safety Monitor Firmware

Duration: 10 Mins

Flash the auto-calibrating gas detector with 20-second warm-up and buzzer siren.

MQ-2 Combustible Gas & Smoke Safety Detector serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • Upload the production sketch below.
  • Wait 20 seconds for the Serial warm-up countdown to complete and lock clean-air baseline.
  • Verify Green LED (D6) illuminates steadily once monitoring begins.
Engineering & Tuning Tip: Using a relative delta (current - baseline) makes your detector resilient across different rooms and sensors.
5

Safe Vapor Response Test

Duration: 5 Mins

Hold an alcohol-dampened cotton swab 2cm from the mesh (no contact) and verify rapid alarm trigger.

MQ-2 Combustible Gas & Smoke Safety Detector live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • Hold isopropyl swab near the mesh and watch ADC climb by 150–400 counts.
  • Confirm Red LED (D7) illuminates and the piezo buzzer sounds its warning pulse.
  • Remove the swab and watch readings recover cleanly back to Green SAFE state.
Engineering & Tuning Tip: This project is for educational prototyping—always rely on certified smoke/CO detectors for life safety.

Subsystem Benchtop Verification Scripts

Test each hardware subsystem independently before deploying the full autonomous firmware.

1Bench Diagnostic: MQ-2 Combustible Gas & Smoke Module Hardware Check

Subsystem Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for MQ-2 Combustible Gas & Smoke Module before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// Diagnostic: Raw MQ-2 Analog Trend Monitor
void setup() { Serial.begin(115200); }
void loop() { Serial.print("MQ2 AO: "); Serial.println(analogRead(A0)); delay(500); }
Expected Output: Settles to steady clean-air baseline (~120–240) and spikes >350 near alcohol vapor.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_mq2_gas_smoke_sensor.ino
arduino_uno_mq2_gas_smoke_sensor.inoArduino C++
/**
 * Project 20: MQ-2 Combustible Gas & Smoke Safety Monitor
 * Board: Arduino Uno R3 | Pins: A0 (MQ2 AO), D6 (Green), D7 (Red), D8 (Buzzer)
 */
const uint8_t MQ2_AO = A0;
const uint8_t LED_SAFE = 6;
const uint8_t LED_ALERT = 7;
const uint8_t BUZZER_PIN = 8;

const int ALERT_DELTA = 120; // Trigger alarm when ADC rises +120 above baseline
int cleanBaseline = 200;

int readAvg() {
  long sum = 0;
  for (uint8_t i = 0; i < 10; i++) { sum += analogRead(MQ2_AO); delay(10); }
  return sum / 10;
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_SAFE, OUTPUT);
  pinMode(LED_ALERT, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  Serial.println(F("MQ-2 Heating up (20s)... Keep in clean air."));
  for (int s = 20; s > 0; s--) {
    digitalWrite(LED_SAFE, s % 2);
    Serial.print(F("Warmup: ")); Serial.print(s); Serial.println(F("s"));
    delay(1000);
  }
  cleanBaseline = readAvg();
  Serial.print(F("Baseline Locked: ")); Serial.println(cleanBaseline);
}

void loop() {
  int val = readAvg();
  int delta = val - cleanBaseline;
  bool danger = (delta >= ALERT_DELTA);

  digitalWrite(LED_SAFE, !danger);
  digitalWrite(LED_ALERT, danger);

  if (danger) {
    tone(BUZZER_PIN, 2100, 180);
    Serial.print(F("[ALARM] Gas/Smoke Elevated! AO="));
  } else {
    noTone(BUZZER_PIN);
    Serial.print(F("[SAFE] Air Normal | AO="));
  }
  Serial.print(val); Serial.print(F(" (Delta: ")); Serial.print(delta); Serial.println(F(")"));
  delay(350);
}

Firmware Architecture Explanation:

  • Executes a 20-second preheat warm-up countdown before locking cleanBaseline in fresh air.
  • Uses relative delta above clean air so room humidity or sensor aging does not cause nuisance trips.
  • Activates both visual (Red LED) and audible (2.1kHz piezo pulse) warnings during gas spikes.

Operational Verification & Pin State Matrix

1Double-check all 5 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Settles to steady clean-air baseline (~120–240) and spikes >350 near alcohol vapor.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for MQ-2 Combustible Gas & Smoke Safety Detector
Input / StatePin / SignalDetected ConditionExpected Output
Delta < +120A0 Clean AirNormal EnvironmentGreen LED ON, Buzzer OFF
Delta ≥ +120A0 Gas SpikeVapor / Smoke DetectedRed LED ON + 2.1kHz Alarm

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for MQ-2 Combustible Gas & Smoke Safety Detector
ProblemLikely CauseDiagnostic CheckEngineering Solution
Alarm triggers immediately after power-onSensor still cold during initial burn-inWatch AO values drop over 60 secondsLet sensor warm up fully in clean air, then press Arduino Reset.
MQ-2 mesh stays cold and AO reads 05V supply wire loose or unpluggedMeasure 5.0V across module VCC and GNDRe-seat power jumpers tightly.
Slow recovery after vapor testNormal SnO2 desorption timeWait 30–60s in fresh airProvide gentle airflow; readings naturally settle back to baseline.

Engineering Challenges & Upgrades

Take your build to the next level with these progressive engineering upgrades:

Level 13-Tier Air Quality Bar

Add a Yellow Caution LED for Delta +60..+119 before triggering the Red siren at +120.

Level 2OLED Gas Level Gauge

Display live baseline, delta bar graph, and SAFE/ALERT status on Project 4 OLED.

Level 3Exhaust Fan Relay Trigger

Drive a 5V DC fan motor (Project 29) automatically whenever smoke is detected.