Gas Sensor
Gas Sensor
Introduction:
In this tutorial we will learn that how a MQ-2 Gas Sensor can be interfaced with NodeMCU to detect flammable gasses in the atmosphere.
The Gas Sensor (MQ2) module is useful for gas leakage detection (home and industry). It is suitable for detecting H2, LPG, CH4, CO, Alcohol, Smoke or Propane.
Due to its high sensitivity and fast response time, measurement can be taken as soon as possible. The sensitivity of the sensor can be adjusted by potentiometer.
The sensor is actually enclosed in two layers of fine stainless steel mesh called Anti-explosion network. It ensures that heater element inside the sensor will not
cause an explosion, as we are sensing flammable gases.
It also provides protection for the sensor and filters out suspended particles so that only gaseous elements are able to pass inside the chamber. The mesh is
bound to rest of the body via a copper plated clamping ring.
Components Needed:
1x NodeMCU
1x MQ-2 Gas Sensor
1x Buzzer
Jumper Wires
Breadboard
Connections:
VCC pin of MQ-2 is connected to 3V pin of NodeMCU.
GND pin of MQ-2 is connected to GND pin of NodeMCU.
A0 pin of MQ-2 is connected to A0 pin of NodeMCU.
Positive (+) pin of Buzzer is connected to D2 pin of NodeMCU.
GND (-) pin of Buzzer is connected to GND pin of NodeMCU.
Arduino Code:
Upload the following code into the NodeMCU:
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
#include<LiquidCrystal.h>
#define dht_dpin 12
dht DHT;
byte degree[8] =
{
0b00011,
0b00011,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup()
{
lcd.begin(16, 2);
lcd.createChar(1, degree);
lcd.clear();
lcd.print(" Humidity ");
lcd.setCursor(0,1);
lcd.print(" Measurement ");
delay(2000);
lcd.clear();
lcd.print("Circuit Digest ");
delay(2000);
}
void loop()
{
DHT.read11(dht_dpin);
lcd.setCursor(0,0);
lcd.print("Humidity: ");
lcd.print(DHT.humidity); // printing Humidity on LCD
lcd.print(" %");
lcd.setCursor(0,1);
lcd.print("Temperature:");
lcd.print(DHT.temperature); // Printing temperature on LCD
lcd.write(1);
lcd.print("C");
delay(500);
}