Gas Alert System Using Arduino UNO – Step by Step Tutorial (MQ-2 Gas Sensor)

Gas Alert System Using Arduino | MakeMindz
Intermediate Project

Gas Alert System
Using Arduino

Detect LPG, methane & smoke with an MQ-2 sensor. Triggers buzzer + LED on gas leak. Includes circuit diagram, code, and Tinkercad simulation.

⏱ 30 min build 🔌 Arduino UNO 💡 MQ-2 Sensor 🧪 Tinkercad Sim
🔥 Why this project? Gas leaks from LPG cylinders cause thousands of home fires every year. This simple Arduino circuit gives you an instant audible + visual alarm — easy to build, cheap, and potentially life-saving.
  • Detect harmful gases — LPG, methane, and smoke
  • Trigger dual alert: buzzer (audible) + LED (visual)
  • Build a low-cost, real-world safety system
  • Learn MQ-2 sensor interfacing with Arduino
🔵
Arduino UNO
🟡
MQ-2 Gas Sensor
🔴
Red LED
Buzzer
🟢
220Ω Resistor
🟣
Breadboard
🟠
Jumper Wires
gas_alert_circuit.json
Gas Alert System — Circuit Diagram ARDUINO UNO 5V GND GND A0 A1 D7 D8 ATmega328P 16 MHz USB PWR MQ-2 SENSOR VCC GND A0 LED + 220Ω BUZZER + 5V A0 D7 D8 GND BUS
5V Power GND Analog A0 Digital D7 (LED) Digital D8 (Buzzer)
STEP 1

Connect MQ-2 Gas Sensor

VCC → 5V (Arduino) GND → GND (Arduino) A0 → Analog Pin A0
STEP 2

Connect Red LED

Long leg (+) → D7 via 220Ω resistor Short leg (−) → GND
STEP 3

Connect Buzzer

Positive (+) → Digital Pin D8 Negative (−) → GND
💡 Pro Tip Always connect the 220Ω resistor in series with the LED to prevent burning it out. Without the resistor, excess current will destroy the LED.
Power ON MQ-2 reads gas level Gas > Threshold (300) YES LED ON Buzzer ON NO LED OFF Buzzer OFF Wait 500ms → Loop
gas_alert.ino
// ── Gas Alert System | MakeMindz.com ──────────────
// Detects LPG, methane, smoke via MQ-2 sensor
// Triggers buzzer + LED when gas exceeds threshold

// ── Pin Definitions ──────────────────────────────
int gasSensor = A0;   // MQ-2 analog output → A0
int led       = 7;    // Red LED → Digital Pin 7
int buzzer    = 8;    // Buzzer  → Digital Pin 8
int threshold = 300;  // Adjust based on sensor sensitivity

// ── Setup ────────────────────────────────────────
void setup() {
  pinMode(led, OUTPUT);
  pinMode(buzzer, OUTPUT);
  Serial.begin(9600);  // Open Serial Monitor for live readings
  Serial.println("Gas Alert System Ready!");
}

// ── Main Loop ────────────────────────────────────
void loop() {
  int gasValue = analogRead(gasSensor);  // 0–1023
  Serial.print("Gas Level: ");
  Serial.println(gasValue);

  if (gasValue > threshold) {
    // ⚠ Gas detected — activate alerts
    digitalWrite(led, HIGH);
    digitalWrite(buzzer, HIGH);
    Serial.println("⚠ WARNING: Gas Detected!");
  } else {
    // ✓ Air is clean — keep quiet
    digitalWrite(led, LOW);
    digitalWrite(buzzer, LOW);
  }

  delay(500);  // Check every 500 milliseconds
}
⚙️ Calibration Tip The default threshold is 300. Open the Serial Monitor (9600 baud) and check the readings in clean air vs. near a gas source. Set your threshold 20–30% above the clean-air reading for reliable detection.

🧪 Try it in Tinkercad

No hardware? Run the complete circuit simulation online — drag the MQ-2 sensor slider to trigger the alert.

Open Simulation

How to run the simulation:

1

Open Tinkercad

Click the simulation button above to open the pre-built circuit

2

Click "Start Simulation"

The green Start button at the top right of the Tinkercad editor

3

Open Serial Monitor

Click "Serial Monitor" (bottom panel) to see live gas readings

4

Adjust Sensor Slider

Click on the MQ-2 sensor and drag the gas concentration slider above 300 — the LED lights up and buzzer activates

5

Test & Modify

Change the threshold value in the code and re-simulate to see the difference

🍳
Home Kitchen Monitoring
🏭
Industrial Safety
🧪
Laboratory Safety
🏠
Smart Home Systems
📡
IoT Gas Monitoring
🚗
Parking Garages
🚀 Level Up This Project Add a GSM module (SIM800L) to send SMS alerts when gas is detected. Connect an LCD display to show real-time gas readings. Or integrate with a relay to automatically cut off gas supply.

BEGINNER

INTERMEDIATE

ADVANCED

MakeMindz.com — Learn. Build. Innovate.

Arduino • IoT • Robotics • Electronics Tutorials

← Back to all projects

Comments

try for free