DEV Community

張旭豐
張旭豐

Posted on

5 MQ-2 Gas Sensor Projects That Keep You Safe

5 MQ-2 Gas Sensor Projects That Keep You Safe

Build safety monitoring systems: kitchen gas leak alarm, workshop smoke detector, RV air monitor, wine cellar controller, and 3D printer exhaust

Hero

Project 1: Kitchen Gas Leak Alarm

Goal: Alert with buzzer and SMS when gas leak detected

Kitchen Gas Leak Alarm

Hardware

MQ-2, Arduino Nano, Buzzer, GSM SIM800L, Relay

Code

#define GAS_PIN    A0
#define BUZZER_PIN 8
#define GSM_PIN    7
#define THRESHOLD  300

void setup() { pinMode(BUZZER_PIN, OUTPUT); }

void loop() {
  int gas = analogRead(GAS_PIN);
  if (gas > THRESHOLD) {
    tone(BUZZER_PIN, 1000);
    // Send SMS via GSM
    delay(5000);
    noTone(BUZZER_PIN);
  }
}
Enter fullscreen mode Exit fullscreen mode

Project 2: Workshop Smoke Detector

Goal: Alert when smoke or fumes exceed safe level

Workshop Smoke Detector

Hardware

MQ-2, Arduino Nano, Buzzer, Red LED, Exhaust fan relay

Code

void loop() {
  int smoke = analogRead(GAS_PIN);
  if (smoke > 250) {
    digitalWrite(RED_LED, HIGH);
    tone(BUZZER, 2000);
    digitalWrite(FAN_RELAY, HIGH);
  }
}
Enter fullscreen mode Exit fullscreen mode

Project 3: RV Air Quality Monitor

Goal: Monitor CO and smoke levels in recreational vehicle

RV Air Quality Monitor

Hardware

MQ-2, Arduino Nano, 16×2 LCD, Green/Yellow/Red LEDs

Code

void loop() {
  int level = analogRead(GAS_PIN);
  lcd.clear();
  lcd.print("Air: ");
  if (level < 200) { lcd.print("GOOD"); digitalWrite(GREEN, HIGH); }
  else if (level < 350) { lcd.print("WARN"); digitalWrite(YELLOW, HIGH); }
  else { lcd.print("DANGER"); digitalWrite(RED, HIGH); }
  delay(500);
}
Enter fullscreen mode Exit fullscreen mode

Project 4: Wine Cellar Controller

Goal: Monitor storage conditions to protect wine

Wine Cellar Controller

Hardware

MQ-2, Arduino Nano, LCD, Temperature sensor

Code

void loop() {
  int air = analogRead(GAS_PIN);
  float temp = dht.readTemperature();
  lcd.setCursor(0, 0); lcd.print("Air:"); lcd.print(air);
  lcd.setCursor(0, 1); lcd.print("Temp:"); lcd.print(temp, 1);
  if (air > 300) { tone(BUZZER, 880); }
}
Enter fullscreen mode Exit fullscreen mode

Project 5: 3D Printer Fume Exhaust

Goal: Automatically extract fumes when printing

3D Printer Fume Exhaust

Hardware

MQ-2, Arduino Nano, 5V relay, 12V fan

Code

void loop() {
  int fumes = analogRead(GAS_PIN);
  if (fumes > 200) {
    digitalWrite(FAN_RELAY, HIGH);
    lcd.setCursor(0, 0); lcd.print("Extracting...");
  } else {
    digitalWrite(FAN_RELAY, LOW);
    lcd.setCursor(0, 0); lcd.print("Air OK    ");
  }
}
Enter fullscreen mode Exit fullscreen mode

How It Works

// WF1 Run #045 - Basic Gas Detection
#define GAS_PIN  A0

void setup() {
  Serial.begin(115200);
  pinMode(GAS_PIN, INPUT);
}

void loop() {
  int gas = analogRead(GAS_PIN);
  Serial.print("Gas Level: ");
  Serial.println(gas);
  delay(500);
}
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

Problem Cause Fix
False alarms Sensor needs burn-in Run sensor 24 hours before calibrating
Readings drift Temperature/humidity affect accuracy Apply temperature compensation formula in code
Slow response Sensor warm-up needed Allow 5 minute warm-up before readings are valid

Start Here

Affiliate disclosure: As an Amazon Associate, I earn from qualifying purchases.

MQ-2 Gas Sensor
Arduino Nano
Buzzer Module
GSM SIM800L

Next Step: From Scene to Sensor, Without Writing Code

I offer a personalized interactive device design guide at Fiverr:

👉 https://www.fiverr.com/phd_hfchang/generate-an-arduino-interactive-prototypef

Tags: Arduino MQ2 Gas Smoke Detector Safety

Top comments (0)