Free Nationwide Doorstep Delivery on orders over ₹499
← All 10 Projects•Advanced•60 mins

Gas Leakage & Air Quality Prototype Alert System

Implement an environmental safety detector using an MQ gas sensor prototype module with audible buzzer alarm and visual warning alert.

Real-World Engineering Application

Domestic LPG kitchen safety detectors, industrial gas storage monitoring, and mine air quality sentinels.

Physics & Working Principle

The MQ sensor uses a Tin Dioxide (SnO2) sensitive layer heated by an internal element. When combustible gases pass over the heated surface, oxygen adsorption decreases and electrical resistance drops, yielding a proportional analog voltage.

Key Learning Outcome:Understand chemical gas sensors, preheating cycles, ADC calibration, and emergency threshold fail-safes.

Pin Connection & Wiring Table

Component Pin / TerminalMicrocontroller Pin (ESP32 / Arduino)Wiring Note
MQ-2 VCCVIN / 5VHeater requires 5V supply
MQ-2 GNDGNDCommon ground
MQ-2 AOUTGPIO 35 / A0Analog sensor voltage
Buzzer (+)GPIO 19Audio alarm
LED Anode via 220ΩGPIO 4Visual alarm

Step-by-Step Plug & Play Assembly

1

Connect MQ-2 VCC to 5V and GND to GND.

2

Connect MQ-2 analog output (AOUT) to GPIO 35.

3

Allow the sensor to pre-heat for 2-3 minutes until readings stabilize.

4

Wire the buzzer to GPIO 19 and warning LED to GPIO 4.

Complete Tested Source Code

// NovaCircuit Project 10: Gas Leakage Safety Alert
const int SENSOR_PIN = 35;
const int BUZZER_PIN = 19;
const int LED_PIN = 4;

const int GAS_ALARM_THRESHOLD = 1800; // Calibrate during pre-heating

void setup() {
  Serial.begin(115200);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.println("Gas Leakage Alert System Active (Pre-heating...)");
}

void loop() {
  int sensorValue = analogRead(SENSOR_PIN);
  Serial.print("Air Quality Gas ADC: ");
  Serial.println(sensorValue);

  if (sensorValue > GAS_ALARM_THRESHOLD) {
    // Dangerous gas concentration detected
    Serial.println("EMERGENCY ALERT: High Gas / Smoke Concentration Detected!");
    digitalWrite(LED_PIN, HIGH);
    digitalWrite(BUZZER_PIN, HIGH);
    delay(150);
    digitalWrite(BUZZER_PIN, LOW);
    delay(100);
  } else {
    // Normal ambient conditions
    digitalWrite(LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
  }

  delay(400);
}
Code Logic Breakdown:

Continuous polling of GPIO 35 measures gas concentration. If the ADC reading exceeds GAS_ALARM_THRESHOLD, an emergency pulsing buzzer alarm and blinking warning LED are engaged immediately.

Expected Physical Output

Serial monitor logs air quality levels. When exposed to a safe test gas source (like a trace of isopropyl alcohol vapors), the alarm triggers.
Troubleshooting Tips
  • •High readings initially: MQ sensors run hot by design and require 2-5 minutes of initial warm-up to burn off protective coatings.
  • •Sensor body warm to touch: Normal operation; the internal heater coil maintains ~200°C for catalytic sensing.
Electrical Safety Directives
  • •Do NOT test with open gas cylinders or flammable flames. Use a safe swab with rubbing alcohol vapors to test response.
Companion Resources

Related Book Chapter & Hardware Kit

Covered in depth within Chapter 11: Hands-on Electronics Projects. Build this easily with the IoT Innovator Kit.