Air Quality Sensor
-
Hi All. Very interesting stuff, thanks all for sharing! I'm attempting to integrate an MQ-2, MQ-6 and MQ-135 (sensors only, no boards) using parts of epierre's sketch but I'm confused on a few things on how to set it up properly:
- What resistor(s) should go between A0 and ground? Keep in mind I'm not using a sensor board with built in protection resistor. Should there be a protection resistor then an adjustable pot for calibration?
- define RL_VALUE (5)
-- does this refer to the size of the protection resistor between A0 and ground? - define RO_CLEAN_AIR_FACTOR (9.83)
-- does this value need to change at all? - float Ro4 = 2.511;
-- when you say this needs to be tuned to 10k, does that mean put a pot between A0 and ground and adjust until the calibration R0 is 10k?
Sorry for all the questions, I appreciate any input! Thanks!
-
Hi All. Very interesting stuff, thanks all for sharing! I'm attempting to integrate an MQ-2, MQ-6 and MQ-135 (sensors only, no boards) using parts of epierre's sketch but I'm confused on a few things on how to set it up properly:
- What resistor(s) should go between A0 and ground? Keep in mind I'm not using a sensor board with built in protection resistor. Should there be a protection resistor then an adjustable pot for calibration?
- define RL_VALUE (5)
-- does this refer to the size of the protection resistor between A0 and ground? - define RO_CLEAN_AIR_FACTOR (9.83)
-- does this value need to change at all? - float Ro4 = 2.511;
-- when you say this needs to be tuned to 10k, does that mean put a pot between A0 and ground and adjust until the calibration R0 is 10k?
Sorry for all the questions, I appreciate any input! Thanks!
1- see http://www.electronicaestudio.com/docs/SHT-114.pdf Fig 2 for wiring, the adjustable resistance is with ground and the sensor.
2- yes
3- Ro is calculated on first launch expecting you do this outside.
Ro = MQCalibration(MQ_SENSOR_ANALOG_PIN);4- this is a default value I observed here. again the datasheet recommands for MQ135 20K to be in range with their values:
we recommend that you calibrate the detector for 100ppm NH3 or 50ppm Alcohol concentration in air and use value of Load resistance that( RL) about 20 KΩ -
1- see http://www.electronicaestudio.com/docs/SHT-114.pdf Fig 2 for wiring, the adjustable resistance is with ground and the sensor.
2- yes
3- Ro is calculated on first launch expecting you do this outside.
Ro = MQCalibration(MQ_SENSOR_ANALOG_PIN);4- this is a default value I observed here. again the datasheet recommands for MQ135 20K to be in range with their values:
we recommend that you calibrate the detector for 100ppm NH3 or 50ppm Alcohol concentration in air and use value of Load resistance that( RL) about 20 KΩThanks for fast reply! I think i understand all but point #4... What do you mean by the Ro needs to be tuned to 10k? Using the adjustable resistor? Does that mean that the calibration number in fresh air at startup should ideally reach a set number, 10k?
Since I don't have access to properly calibrate the sensor against a know quantity of gas, I thought the rough calibration would occur in clean air at start up, is that correct?
Sorry for all the questions, it's a bit complicated. Thanks again!
-
Thanks for fast reply! I think i understand all but point #4... What do you mean by the Ro needs to be tuned to 10k? Using the adjustable resistor? Does that mean that the calibration number in fresh air at startup should ideally reach a set number, 10k?
Since I don't have access to properly calibrate the sensor against a know quantity of gas, I thought the rough calibration would occur in clean air at start up, is that correct?
Sorry for all the questions, it's a bit complicated. Thanks again!
@pbo as stated above, the sensors evolve in their life... let's say that the value recommended by the datasheet is the best if you can.
clean air calibration means that you should have a 0 value in clean air. Let's say that for CO2 the actual value is 399... so it should not be 0, but the clean air calibration is "assumed" quite good for LPG, SO2, NOx... that should be present in very little quantity, and again this is when the value increases a lot that it gets dangerous... there are some discussion on this above.
-
I tried to analyze what is on the small ciscuitboar for my MQ-2 sensor an here is what I think it contains:
So adding the 10K between AOUT and GND is pointless. So what now? Can I use it as is and just use the 1K value for RL in the sketch or is it recommended to change the 1K to something else (10K)??
-
@epierre Couldn't find it either, sorry...
I wouldn't buy a $52,- component without a datasheet, if I were you...@Yveaux right, I opened a dispute with the seller, since I observed also no/nearly no answer to match burning with the sensor, he didn't even answer thus closing the dispute in my favor... that will be a good warning to me about those undocumented sensors comming from only one supplier without datasheet... there are other around, I shall avoid them..
-
I tried to analyze what is on the small ciscuitboar for my MQ-2 sensor an here is what I think it contains:
So adding the 10K between AOUT and GND is pointless. So what now? Can I use it as is and just use the 1K value for RL in the sketch or is it recommended to change the 1K to something else (10K)??
@korttoma You've been lucky finding such a schema, but it is strange there is a resistance on the other side of the sensor, and the variable one is not where expected... maybe the 1K is wrong on the schema, can you mesure it on the board?
5.1 Ohm is low...
The RL here is for the voltage comparator that gives the digital output with led.
MQ-2 datasheet asks for Rs in 3KΩ-30KΩ
If this is right, then the value that the autocalibration "in clean air" should give you something around 1K.The MQ-9 datasheet is a bit more versatile:
Power of Sensitivity body(Ps): Ps=Vc^2×Rs/(Rs+RL)^2
Resistance of sensor(Rs): Rs=(Vc/VRL-1)×RLMQ-9: Rs(in air)/Rs(100ppm CO)≥5
I fear they are using a standard board for all sensors and that the resistance value may be wrong from this, just because they want to deliver a digital signal...
-
@korttoma You've been lucky finding such a schema, but it is strange there is a resistance on the other side of the sensor, and the variable one is not where expected... maybe the 1K is wrong on the schema, can you mesure it on the board?
5.1 Ohm is low...
The RL here is for the voltage comparator that gives the digital output with led.
MQ-2 datasheet asks for Rs in 3KΩ-30KΩ
If this is right, then the value that the autocalibration "in clean air" should give you something around 1K.The MQ-9 datasheet is a bit more versatile:
Power of Sensitivity body(Ps): Ps=Vc^2×Rs/(Rs+RL)^2
Resistance of sensor(Rs): Rs=(Vc/VRL-1)×RLMQ-9: Rs(in air)/Rs(100ppm CO)≥5
I fear they are using a standard board for all sensors and that the resistance value may be wrong from this, just because they want to deliver a digital signal...
I did not find the schema, I measured the board and figured it out myself so it might be wrong.
Could you draw a schema that would show me exactly how it would preferably look so I can change it? Because I'm clearly not smart enough to understand it from your descriptions. Please explain it to me like I was 4 years old ;)
-
Now changed my sensor according to this (disconnected the OP related to DOUT) :
Please confirm that this is how it is preferred to be connected.
-
Now changed my sensor according to this (disconnected the OP related to DOUT) :
Please confirm that this is how it is preferred to be connected.
Hello,
I guess here you have the same that the datasheet, so I assume it is ok ;-)
I've been working to port sketches to a Spark Core with good results, the 12 bits ADC gives more precise values, at least the MQ135 is now very sensitive.
I am also correcting errors in the sketches I have produced.
-
Hello,
A good article on the comparison of 3 same MQ-7 sensors
A lot of good questions, not easy to answer! It is good you tryed it with three sensors instead of just one, and you can see there is a lot of variation from one sensor to the next of the same batch. [...] As to the value of Ro, that is the million dollar question. You have to have a known calibration source of CO in order to determine that! Each MQ-7 sensor will be different. The normal levels in a lab or home will be (should be!) well below the level that this sensor can detect and discriminate. It's lower limit implied in the data sheet is around 50ppm, which is where it begins to be dangerous for continuous exposure. Do read wiki and other sources about carbon monoxide and levels that can occur under different conditions. -
During the weekend I did the hardware changes and tried my MQ-2 sensor again and now if I hit it with smoke (I have smoke on a can) I do get values in Vera under the Variable1 property. No values on the dashboard device itself. I guess some changes are needed for the device file to display the V_VAR1 or we should use something else than V_VAR1.
If you have already updated the sketch for the MQ-2 please let me know where I can get the latest version so I can try it out.
btw, is the MQ-2 supposed to give the value 0 after it is calibrated in clean air? My sensor sends the value 0 all the time unless I hit it with my smoke can.
-
@korttoma said:
If you have already updated the sketch for the MQ-2 please let me know where I can get the latest version so I can try it out.
btw, is the MQ-2 supposed to give the value 0 after it is calibrated in clean air? My sensor sends the value 0 all the time unless I hit it with my smoke can.
Yes I am deeply modifying it, and will have a question for @hek : to have something consistant in time, it owuld be better to have the initial calibration stored, either in EEPROM or as a VAR on the server. Could it be possible that I introduce a loop that wait till the var is answered and if not go into calibration ?
@korttoma the best sketch so far is the following, to be scaled down to one sensor, remove specific Mega initialization. I will make a simpler one based on this soon, as I have already done it for the Spark core.
https://github.com/empierre/arduino/blob/master/MQv01dgi_1_4.ino -
@korttoma said:
If you have already updated the sketch for the MQ-2 please let me know where I can get the latest version so I can try it out.
btw, is the MQ-2 supposed to give the value 0 after it is calibrated in clean air? My sensor sends the value 0 all the time unless I hit it with my smoke can.
Yes I am deeply modifying it, and will have a question for @hek : to have something consistant in time, it owuld be better to have the initial calibration stored, either in EEPROM or as a VAR on the server. Could it be possible that I introduce a loop that wait till the var is answered and if not go into calibration ?
@korttoma the best sketch so far is the following, to be scaled down to one sensor, remove specific Mega initialization. I will make a simpler one based on this soon, as I have already done it for the Spark core.
https://github.com/empierre/arduino/blob/master/MQv01dgi_1_4.ino -
Now some questions I have currently:
I've used your clean air calibration in open air given values of air concentration where appropriate. Around sept 20th I applied this method t omy sketches and I have since sensors that are very much more reactive ! Only 2SH12 has no curve, it is voltage for this (damn) sensor doesn't have a datasheet...
I don't know if this was this predictible...
They are all placed inside a room that I sometime open to clean air. Also there are restarts that calculates again those values where you see it drop maybe, but anyway it will still go to the previous values.
MQ135 in CO2:

MQ2 in Smoke:

2SH12 in SO2 in voltage:

MQ6 in O3:

-
Now changed my sensor according to this (disconnected the OP related to DOUT) :
Please confirm that this is how it is preferred to be connected.
@korttoma I have found a sketch that may interrest you about the gas sensors boards:
http://www.parallax.com/sites/default/files/downloads/27983-Gas-Sensor-Board-A-Schematic.pdf
Their document speaks also about calibrating some gases:
http://www.parallax.com/sites/default/files/downloads/27983-Gas-Sensor-Board-Guide-v1.0.pdf -
@Yveaux you mean something like this ?
return ( (((float)RL_VALUE*(1023.0 - (float) raw_adc)) / (float) raw_adc));I somehow forked the discussion on arduino.cc and sent an email in parallel do Davide Gironi for I would like to understand his formula as opposed to the curve approach.
@Yveaux I have doubts about calculing the resistance, for it is depending on the steps, either 1024 or 4096, and/or the voltage either 5V or 3.3V.
I started with this formulae:
return ( ((float)RL_VALUE*(1023-raw_adc)/raw_adc));But saw Davide Gironi using this one:
return (long)((long)(1024*(long)RL_VALUE)/raw_adc-(long)RL_VALUE);RL_VALUE=22000
-
@Yveaux @korttoma
Bummer... this is the same formula when doing the reduction.... one is 1023 the other 1024 the only change.The RL_VALUE for Davide was 22k, when I mesure the resistance with Analog out with ground, I get 0,996 or 0,999 ohms depending on the sensor. I guess this is the RL_VALUE of the board which is way below the sensor maker recommendation (between 10K and 47K for a MQ135).
Also, I saw that the pot on the board does not change the analog to ground resistance, meaning it is used only for comparison of the digital output....
Am I correct in mesuring this ?
-
@Yveaux @korttoma
Bummer... this is the same formula when doing the reduction.... one is 1023 the other 1024 the only change.The RL_VALUE for Davide was 22k, when I mesure the resistance with Analog out with ground, I get 0,996 or 0,999 ohms depending on the sensor. I guess this is the RL_VALUE of the board which is way below the sensor maker recommendation (between 10K and 47K for a MQ135).
Also, I saw that the pot on the board does not change the analog to ground resistance, meaning it is used only for comparison of the digital output....
Am I correct in mesuring this ?
-
@Yveaux Doing so, I have used a RL_VALUE for each board I mesured, one went to 5MOhms...
MQ2:-8.85 MQ6:0.00 MQ131:0.00 TGS2600:0.00 MQ135:0.00 2SH12:-155004.00 TGZS2602:0.00Something to be noted: same boards have the same resistance, whatever the sensor maker recommendation, this is a pity...
The output I have:
MQ2 :LPG :7ppm CO :0ppm SMOKE :10ppm MQ6 :LPG :0ppm CH4 :0ppm MQ131 :CL2 :0ppm O3 :0ppm TGS2600:H2 :0ppm C2H5OH:0ppm C4H10 :0ppm MQ135 :CO2 :0ppm CO :0ppm CH3 :0ppm NH4 :0ppm 2SH12 :SO2 :-154588.20 raw TGS2602:C7H8 :0ppm Dust :raw : 0 Voltage: 0.00 - Dust Density: -0.10something to remember: MQ135 was calibrated for 1ppm of CO, not 399ppm of CO2, so the calculated value is very low, a per gas Ro must be calculated (clean air calibration) if several gas on one sensor is required to be displayed.