INTRODUCTION
The MQ-2 Gas sensor can detect or measure gasses like LPG, Alcohol, Propane, Hydrogen, CO, and even methane. With this sensor, we can build a gas leak detector to check if there is a gas leak and send a notification to our mobile phone. Watch this video to know how to make a gas detector using Maker NANO.
HARDWARE PREPARATION
This tutorial use :
Sample Code
This is the sample code used for this tutorial. Try it!
#define MQ2 A0 | |
#define GREEN_LED 4 | |
#define YELLOW_LED 5 | |
#define RED_LED 6 | |
#define PIEZO 8 | |
int sensorValue = 0; | |
void setup() | |
{ | |
Serial.begin(9600); // Initialize serial communications with the PC | |
pinMode(RED_LED, OUTPUT); | |
pinMode(GREEN_LED, OUTPUT); | |
pinMode(YELLOW_LED, OUTPUT); | |
pinMode(PIEZO, OUTPUT); | |
pinMode(MQ2, INPUT); | |
digitalWrite(GREEN_LED, HIGH); | |
} | |
void loop() | |
{ | |
sensorValue = analogRead(MQ2); | |
Serial.println(sensorValue); | |
if (sensorValue > 300) | |
{ | |
digitalWrite(GREEN_LED, LOW); | |
digitalWrite(RED_LED, HIGH); | |
tone(PIEZO, 1000, 300); | |
delay(700); | |
} | |
else | |
{ | |
noTone; | |
digitalWrite(GREEN_LED, HIGH); | |
digitalWrite(RED_LED, LOW); | |
} | |
} |
Thank you
Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiries, please post at Cytron Technical Forum.
3 thoughts on “Gas Detector Using The MQ2 Sensor on Maker NANO”
Hiya, is it possible to combine this build up with esp32 built up by spliting the cable connecting the MQ2 sensor?
Hi Muhammad Fitri, you may refer to this tutorial to get the notification sent to the mobile phone: https://tutorial.cytron.io/2020/05/08/gas-detector-using-mq2-on-esp32-and-blynk-app/ Hope this will help you.
hye. i just want o know…how to make it the project can send a notification to our mobile phone? how about the coding ?