กลับไปหน้ารวมไฟล์
mq-2-flammable-gas-sensor-with-arduino-sheekar-banerjee-6472e6-en.md

CircuitPlanning:

Arduino UNO R3 --> MQ2 Sensor

Pins--> Vin-->Vcc

Pins--> GND --> GND

Pins--> A0 --> A0

Code:

//Coded and tested by :
// Sheekar Banejee, AI-ML-IOT Solution Engineer and Researcher
int smokeA0 = A0;
// Your threshold value
int sensorThres = 700;
void setup() {
pinMode(smokeA0, INPUT);
Serial.begin(9600); //Streaming 9600 bits of Sensor Data per Second
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.println("Sensor Value: ");
Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
Serial.println("Alert! Smoke Detected!");
}
else
{
Serial.println("Normal...");
}
delay(3000);
}

Results:

Serialmonitor:

EXPANDED TECHNICAL DETAILS

Electrochemical Gas Detection

The MQ-2 is a versatile sensor for detecting LPG, smoke, alcohol, propane, and hydrogen.

  • Heating Element Management: The sensor requires a "pre-heat" phase (typically 24 hours for first use, 60 seconds for daily use) to stabilize the internal heater before readings are accurate.
  • Sensitivity Calibration: Features an onboard potentiometer to adjust the baseline trigger level. The Arduino reads the analog output voltage; higher concentrations of gas result in lower resistance and higher output voltage.

Safety Alert Logic

  • Visual & Audible Warnings: When the gas concentration exceeds a safe limit, the Arduino triggers a Piezo Buzzer and a high-intensity blinking LED.
  • Emergency Action: This setup is often expanded with a relay to automatically shut off gas valves or activate emergency ventilation.

ข้อมูล Frontmatter ดั้งเดิม

title: "MQ-2 Flammable Gas Sensor with Arduino | Sheekar Banerjee"
description: "The MQ-2 Flammable Gas and Smoke Sensor is usually used to detect the presence of flammable or smoke element in the air."
author: "sheekar"
category: ""
tags:
  - "environmental sensing"
  - "embedded"
  - "home automation"
  - "smart appliances"
  - "human welfare"
  - "health"
  - "internet of things"
  - "monitoring"
views: 1873
likes: 2
price: 870
difficulty: "Intermediate"
components:
  - "1x Arduino UNO"
  - "1x Gravity: Analog Gas Sensor (MQ2) For Arduino"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "f077a69268391b03f84ba0c7e93d3333629eb460ef21115ecfe64870bce60827"
encryptedPayload: "U2FsdGVkX1/2mc8iHnqO2sCU9rNnsklON3FXORm+ACwuU0wTEwOHP1k4HEEiLVTQizldUNrcox5zvBoLE2IlWgy8K1LaQS2lta1mqd3o66c="
seoDescription: "Learn to use MQ-2 Flammable Gas Sensor with Arduino to detect Flammable and Smoke elements in the air."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/mq-2-flammable-gas-sensor-with-arduino-sheekar-banerjee-6472e6_cover.jpg"
lang: "en"