Go Down

Topic: MQ2 Gas Sensor (Read 10980 times) previous topic - next topic

Marciokoko

Jan 01, 2016, 06:28 pm Last Edit: Jan 04, 2016, 10:39 pm by Marciokoko
Hi,

Im using the mq2 sensor (http://www.seeedstudio.com/wiki/Grove_-_Gas_Sensor(MQ2)) and I am trying to understand how the measurements should be interpreted.

I ran the baseline code and got my R0 value and plugged it into the sample code according to these sketches provided by the manufacurer:

Code: [Select]
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  float sensor_volt;
  float RS_air; //  Get the value of RS via in a clear air
  float R0;  // Get the value of R0 via in H2
  float sensorValue;
 
/*--- Get a average data by testing 100 times ---*/   
    for(int x = 0 ; x < 100 ; x++)
  {
    sensorValue = sensorValue + analogRead(A0);
  }
  sensorValue = sensorValue/100.0;
/*-----------------------------------------------*/
 
  sensor_volt = sensorValue/1024*5.0;
  RS_air = (5.0-sensor_volt)/sensor_volt; // omit *RL
  R0 = RS_air/9.8; // The ratio of RS/R0 is 9.8 in a clear air from Graph (Found using WebPlotDigitizer)
 
  Serial.print("sensor_volt = ");
  Serial.print(sensor_volt);
  Serial.println("V");
 
  Serial.print("R0 = ");
  Serial.println(R0);
  delay(1000);
 
}


and

Code: [Select]
void setup() {
  Serial.begin(9600);
}
 
void loop() {
 
  float sensor_volt;
  float RS_gas; // Get value of RS in a GAS
  float ratio; // Get ratio RS_GAS/RS_air
  int sensorValue = analogRead(A0);
  sensor_volt=(float)sensorValue/1024*5.0;
  RS_gas = (5.0-sensor_volt)/sensor_volt; // omit *RL
 
  /*-Replace the name "R0" with the value of R0 in the demo of First Test -*/
  ratio = RS_gas/R0;  // ratio = RS/R0
  /*-----------------------------------------------------------------------*/
 
  Serial.print("sensor_volt = ");
  Serial.println(sensor_volt);
  Serial.print("RS_ratio = ");
  Serial.println(RS_gas);
  Serial.print("Rs/R0 = ");
  Serial.println(ratio);
 
  Serial.print("\n\n");
 
  delay(1000);
 
}


From what I understand, the sensor detects varying concentrations of:

H2
LPG
CH4
CO
Alcohol
Smoke
Propane

So from the image below, and according to the Rs/R0 obtained from the sensor I get values ranging from 100-700.  According to the literature I should be getting a ratio value between 0.1-10.


WeemanCrew

OK, so what is it you are trying to understand? Where to go from there?
Yes, these sensors will detect various gases at a particular concentration range, in parts per million.

That in itself isn't particularly useful without first ensuring a few conditions are met:
That the sensor has had a suitable break in period;
That the sensor upon any use has been warmed to operating temperature;
That the sensor is properly calibrated for a set concentration of a set target gas, with an appropriate load resistor in place to adjust for the sensitivity. The datasheet states 5 kilohm in their example.

These sensors are blind and stupid, you see. They will detect any gas across they encounter, including a strong wind or you blowing into it. But that is meaningless until you calibrate it with the gas you are trying to monitor for. It can't do all the gases, you pick one and calibrate it to that and afterward you may apply correction factors for various other gases.

For example, suppose you calibrated the sensor to methane. You could then apply a correction factor to measure propane, butane, pentane, etc.

It is very important to note here, however, that these sensors are at best going to give you a rough approximation of the amount of target gas only. Since gases such as methane are explosive, they should not be relied upon by hobbyists for life safety purposes. There is much more to air monitoring than simply plugging in a sensor to an Arduino and applying a couple lines of calculation. Cross-sensitivities, sensor failure, false positive readings, false negative readings, sensor over range conditions (where sensor is in a higher concentration atmosphere than the sensor is capable of reading, such as, from the datasheet: "detecting concentration scope 5000-20000 ppm methane". What this means is that, the sensor will no longer sense methane above 20000ppm. 20000ppm equates to 2% room air by volume, BUT METHANE ISN'T EXPLOSIVE AT THAT CONCENTRATION, ITS FLAMMABLE RANGE IS 5-15% ROOM AIR BY VOLUME.

Take home message: since that is the case, at best, this sensor can alert you to the presence of a gas such as methane, but you won't know when that gas has gone from merely present, to an immediate life and property hazard.

Not sure if all this answered what you are trying to figure out, just food for thought.

And last point of this post, I guess: that sensor for is useless for measuring any gas in any concentration, until you have calibrated it with a lab-grade quantity of a known calibration gas. That is the piece missing from your formula.

You can crudely, as in for demonstration purposes of such, calibrate one of these against a known, reliable standard, ie: measuring say, natural gas on the surface of a barbecue (don't light it :)
next to a commercially made monitor, by placing them side by side and mapping your result to the Arduino analogRead.

Good luck!


Marciokoko

OK, I understand about the baseline for a gas.  What I'm not clear about is that, for example, I set the baseline in my room.  The room presumably wouldn't have much H2, CH, Smoke, Propane or CO.

So I followed the instructions for jotting down the value and using it in my next sketch.  Now I'm trying to relate it to the chart.  It states the chart goes from 100ppm to 10,000ppm.  I get 248.


Marciokoko

My code is:

Code: [Select]

void SampleMQ2Alarm() {
  Serial.println("Sampling MQ2");
  float sensor_volt;
  float RS_gas; // Get value of RS in a GAS
  float ratio; // Get ratio RS_GAS/RS_air
  int sensorValue = analogRead(A1);
  sensor_volt=(float)sensorValue/1024*5.0;
  RS_gas = (5.0-sensor_volt)/sensor_volt; // omit *RL
 //R0 stabilized at 0.08 in secret room
  /*-Replace the name "R0" with the value of R0 in the demo of First Test -*/
  ratio = RS_gas/0.08;  // ratio = RS/R0
  /*-----------------------------------------------------------------------*/
 
  Serial.print("MQ2 Sensor_volt = ");
  Serial.println(sensor_volt);
  Serial.print("RS_ratio = ");
  Serial.println(RS_gas);
  Serial.print("Rs/R0 = ");
  Serial.println(ratio);
  mq2ratio = ratio;
  Serial.print("\n\n");
  delay(1000);
}

Freddy23

Hi, I know this is an old topic. But I found a very good write-up on setting up the MQ2 gas sensor here:
https://www.bootcamplab.com/working-with-mq2-gas-sensor/    I have not tried the set up yet, but it looks pretty thorough in the explanation and math. (using arduino)

Go Up