MQ-2 Sensor Arduino Tutorial
Overview
In This Tutorial, I will show how you interface the MQ-2 Sensor With Arduino Nano Microcontroller And How You Write the Code.
you just created soo many projects using the MQ-2 Sensor Like an Indoor Air Quality Monitoring stem, Breath Checker or Early Fire Detection System.
MQ-2 Sensor is measuring Gasses Like LPG, Smoke, Alcohol, Propane, Hydrogen, Carbon Monoxide(CO) And Methane Concentrations Anywhere From 200 To 10000ppm.
MQ Meaning
Metal Oxide Semiconductor (MOS) type Gas Sensor Also Know As Chemiresistor The Detection is based upon a change in the resistance of the sensing materials when gas comes in contact with the materials.
is used simple voltage divider when resistance will change the voltage will also change and is converted in ppm Unit.
MQ-2 Sensor Pinout
Writing Diagram MQ-2 With Arduino
Testing Of MQ-2 Sensor
The MQ-2 Sensor is connected to the A0 PIN Number.
And The Lcd Will be connected to PIN number 12,11,10,9,8,7
Display MQ-2 Reading In Serial Monitor
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#define MQ2pin 0 float sensorValue; void setup() { Serial.begin(9600); Serial.println("MQ2 Sensor!"); delay(20000); } void loop() { sensorValue = analogRead(MQ2pin); Serial.print("Sensor Value: "); Serial.println(sensorValue); delay(2000); } |
Display Mq-2 Reading In LCD Display
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include <Wire.h> #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 10, 9, 8, 7); #define MQ2pin (0) int buzzer = 4; int sensorValue; void setup() { pinMode(buzzer, OUTPUT); lcd.begin(16,2); lcd.setCursor(0,0); lcd.print(" GAS SENSOR "); delay(1000); lcd.setCursor(0,1); lcd.print(" WARMING UP ! "); delay(20000); } void loop() { lcd.clear(); sensorValue = analogRead(MQ2pin); lcd.setCursor(0,0); lcd.print("VALUE: "); lcd.print(sensorValue); lcd.print("ppm"); if(sensorValue > 400) { lcd.setCursor(0,1); lcd.print("SMOKE DETECTED"); tone(buzzer, 500, 2000); } else { lcd.setCursor(0,1); lcd.print(" NO SMOKE"); noTone(buzzer); } delay(2000); } |
If You are Interested In More Projects Then Plz Check Out
- Vehicle Accident Alert System
- DIY Ventilator Using Arduino
- Arduino Based Blind Stick With GPS And GSM
- Dam Monitoring System Using Arduino