INTRODUCTION
In this tutorial, you are going to learn about Gas Sensors (MQ2) and the interface with Arduino UNO both in Analog and Digital mode.
THEORY
Mainly we can say it is a Metal Oxide Semiconductor(MOS) type Gas Sensor. It detects gas on change of resistance of the sensing material when it comes nearer to the sensor.
Its operating voltage is 5v. It can able to detect smoke, alcohol, LPG, hydrogen, propane, methane, carbon monoxide concentrations anywhere from 200ppm to 10000ppm.
(Configuration Of MQ2)
This sensor having 4 pins.
i)VCC
ii)GND
iii)AOUT(Analog pin)
iv)DOUT(Digital pin)
CHARACTER
i)Having high sensitivity LPG, Propane, Hydrogen.
ii)Having good sensitivity to combustible gases in a wide range.
iii)It has a simple drive circuit.
iv)Long life and low cost.
APPLICATION
i)can detect domestic gas leakage.
ii)In industry it works as the detector of combustible gases.
iii)In portable gas detector.
PARTS REQUIRED
Parts | Quantity |
---|---|
Arduino UNO | 1 |
A-B cable | 1 |
MQ2 Module | 1 |
Bread Board | 1 |
Connecting Wires | As per required |
CIRCUIT DIAGRAM
The connection of MQ2 and UNO is very simple
i)VCC to 5v of UNO
ii)GND to GND of UNO
iii)AOUT to one analog pin of UNO
iv)DOUT to one digital pin of UNO
NOTE: Can use either AOUT or DOUT. Can’t use it together.
PROGRAM
For programming this concept we need to understand some basic syntax of Arduino IDE. The first thing is we need to install Arduino. After that, we need to know about How to use Serial Monitor in Arduino IDE.
As we know all sensors are Input devices.
For control Gas Sensor we need to declare it as an input.
pinMode(PIN Number, Device TYPE);
PIN Number– The pin, to which we have connected the device. In this case, I have attached the sensor’s pin to 2 no pin of UNO.
Device Type– What is the device type. Like, For output devices we need to declare the type as OUTPUT and for input devices, we need to declare it as INPUT. In this case, we have connected MQ2.
pinMode(gas_sensor,INPUT);
After all declaration, we have to go for the digitalWrite() function.
digitalWrite(PIN Number, Status);
PIN Number– in which pin we have connected the device. In this case, I have attached to 2 no pin of Arduino UNO.
Status– status means we need to turn the led on/off. For turning led on we can write HIGH or 1 and for turning off led we can write LOW or 0.
Final Code
When we use DOUT,
/*
Tested by robogenesis. in
Data will show in your serial monitor.
*/
// Here I have initially declared gas sensor is connected to 2 no pin of UNO.
#define gas_sensor 2
void setup()
{
pinMode(gas_sensor,INPUT); // MQ2 as a input device
Serial.begin(9600); // Initilize serial monitor
Serial.println("gas detection");
}
void loop()
{
if(digitalRead(gas_sensor) == LOW) // If MQ2 is on
{
Serial.println("detected");
delay(1000);
}
else // If MQ2 is off
{
Serial.println("not detected");
delay(1000);
}
}
When there is AOUT,
/*
Tested by robogenesis. in
Data will show in your serial monitor.
*/
// Here I have initially declared gas sensor is connected to A0 no pin of UNO.
int sensorPin = A0;
int sensorValue = 0; // Initial value of sensor is 0
void setup()
{
Serial.begin(9600);
Serial.println("ANALOG SENSOR VALUE");
}
void loop()
{
sensorValue = analogRead(sensorPin);
Serial.println("sensorValue: ");
Serial.println(sensorValue);
if(sensorValue> 280)
{
Serial.println(" HIGH SMOKE ");
}
else
{
Serial.println("LOW SMOKE");
delay(1000);
}
}
Comments