In this illustration we will wire the GAS SENSOR MQ2 Module, these device is very useful for GAS leakage detection in home or industry it can detect H2, LPG, CH4, CO, Alcohol or Propane. This device is very sensitive and fast response time and measuring and also can be adjusted onboard by the trimmer potentiometer.
The GAS Sensor is using an Analog output, and should be connected to MCU Analog input. See the illustration below.
The signal output voltage from the GAS SENSOR will increase & decrease when the sensor detects concentration of GAS. Sensitivity can be adjusted by varying the trimmer onboard. The best detection time for the sensor is should be 24 hours. For detailed information for the MQ 2 Sensor, refer to the datasheet.
Required Components
- Arduino Board
- MQ-2 Sensor / H2, LPG, CH4, CO, Alcohol or Propane Sensor
- Jumper Wires / DuPont Wires
- Solder Less Bread Board
Wiring Diagram
Arduino Sketch
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 |
/* //******************************************** // 14CORE Sample Test code for threshold to detect any // increase/decrease in gas concentration. // INDUSTRIAL GAS CONCENTRATION SENSOR // Analog Sense for MQ02 - MQ012 //******************************************** */ float voltage_Sense; //Float var voltage_sense float sensor_value; //Float var sensor value void setup() { Serial.begin(9600); //Start Serial Communication Baud rate 9600 } void loop() { sensor_value = analogRead(A0); //Read value from analog A0 voltage_Sense = sensor_value/1024*5.0; // Voltage / 1024 * 5.0 Serial.print("voltage_Sense = "); Serial.print(voltage_Sense); Serial.println("Voltage"); delay(1000); // Delay at 1 second } |
The code below are tested for standard environment. It may vary based on the temperature and humidity. Make it sure that you have a clean air environment then upload the Arduino sketch.
“Sensing the Clean Air”
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 40 41 |
/* //******************************************** // 14CORE Sample Test code for approximate the GAS // concentration as per the datasheet of MQ-X sensors // INDUSTRIAL GAS CONCENTRATION SENSOR // Analog Sense for MQ02 - MQ12 See the datasheet //******************************************** */ float sensor_voltage; // Define as voltage float Clear_Air; // Sensing resistance Get the value from the clear air float Convertion_Out; // Resistance = 0 Get the value of clean Air via H2 Hydrogen float sensorValue; // Getting sensor value void setup() { Serial.begin(9600); //Start Serial Communication at baud rate 9600 } void loop() { // Getting the average data by test to 100 times for(int x = 0 ; x < 100 ; x++) // x is equall to 0 if less than 100 increment by 1 { sensorValue = sensorValue + analogRead(A0); } sensorValue = sensorValue/100.0; /*-----------------------------------------------*/ sensor_voltage = sensorValue/1024*5.0; Clear_Air = (5.0-sensor_voltage)/sensor_voltage; // omit *RL Convertion_Out = Clear_Air/10.0; // The ratio of Clean Air / Convertion_Out is 10 in a clean air Serial.print("Voltage = "); // Voltage Out Serial.print(sensor_voltage); Serial.println("V"); Serial.print(" = "); Serial.println(Convertion_Out); delay(1000); // Delay to 1 sencond } |
“Sensing the GAS”
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 |
/* //******************************************** // 14CORE Sample Test code for approximate the GAS // concentration as per the datasheet of MQ-X sensors // INDUSTRIAL GAS CONCENTRATION SENSOR // Analog Sense for MQ02 - MQ12 See the datasheet //******************************************** */ float voltage_sensor; float Convertion_RS_Gas; // Get value of Resistance in a GAS float Clean_Air_Ratio; // Get the gas ratio devide by / clean air int sensorValue = analogRead(A0); void setup() { Serial.begin(9600); //Start Serial Communication at baud rate 9600 } void loop() { voltage_sensor=(float)sensorValue/1024*5.0; Convertion_RS_Gas = (5.0-voltage_sensor)/voltage_sensor; // omit *RL Clean_Air_Ratio = Convertion_RS_Gas/Clean_Air_Ratio; Serial.print("Voltage Sensor = "); Serial.println(voltage_sensor); Serial.print("RS_Clean_Air_Ratio = "); Serial.println(Convertion_RS_Gas); Serial.print("Gas / Clean Air = "); Serial.println(Clean_Air_Ratio); Serial.print("\n\n"); delay(1000); } |
Gas Concentration Graph
Download MQ-2 Data Schematics here | Pdf
Download MQ2 Circuit Diagram | Pdf