0% found this document useful (0 votes)
30 views4 pages

Gas Sensor

This document describes interfacing an MQ-2 gas sensor with a NodeMCU to detect flammable gases. The MQ-2 gas sensor detects gases like LPG, CH4, CO, and alcohol. It has a fast response time and adjustable sensitivity. The sensor is enclosed in stainless steel mesh for explosion protection and filtering of particles. The NodeMCU is connected to the MQ-2 and a buzzer. When gas levels exceed a threshold, the buzzer sounds.

Uploaded by

sri kanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Gas Sensor

This document describes interfacing an MQ-2 gas sensor with a NodeMCU to detect flammable gases. The MQ-2 gas sensor detects gases like LPG, CH4, CO, and alcohol. It has a fast response time and adjustable sensitivity. The sensor is enclosed in stainless steel mesh for explosion protection and filtering of particles. The NodeMCU is connected to the MQ-2 and a buzzer. When gas levels exceed a threshold, the buzzer sounds.

Uploaded by

sri kanth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Nodemcu ESP8266 – Lab 10 MQ-2 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:

int buzzer = D2;


int smokeA0 = A0;

// Your threshold value. You might need to change it.


int sensorThres = 600;

void setup() {
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}

void loop() {
int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");


Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
tone(buzzer, 1000, 200);
}
else
{
noTone(buzzer);
}
delay(100);
}
Humidity and Temperature Measurement using Arduino

#include<dht.h> // Including library for dht

#include<LiquidCrystal.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

#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);
}

You might also like