MQ2 Sensor w/AirQuality Sketch
-
I'm using similar sensors, this test sketch works fine for me, but I'm using raw readings from this sensors.
8 sensors connected to A0-A7 pins on arduino nano directly to analog output pin on each sensor board.#include <SPI.h> #include <MySensor.h> unsigned long SLEEP_TIME = 10000; // Sleep time between reports (in milliseconds) #define NODE_ID 4 MySensor gw; MyMessage msg(0, V_VAR1); int lastLightLevel[8] = {0}; unsigned long lastRefreshTime = 0; void setup() { pinMode(13, OUTPUT); // warm up sensors (3 minutes) for (int i = 0; i < 180; i++) { digitalWrite(13, HIGH); delay(250); digitalWrite(13, LOW); delay(250); digitalWrite(13, HIGH); delay(250); digitalWrite(13, LOW); delay(250); } gw.begin(NULL, NODE_ID); gw.sendSketchInfo("GasSensors", "1.5"); gw.present(1, S_AIR_QUALITY, false, "MQ-2"); gw.present(2, S_AIR_QUALITY, false, "MQ-3"); gw.present(3, S_AIR_QUALITY, false, "MQ-4"); gw.present(4, S_AIR_QUALITY, false, "MQ-6"); gw.present(5, S_AIR_QUALITY, false, "MQ-7"); gw.present(6, S_AIR_QUALITY, false, "MQ-8"); gw.present(7, S_AIR_QUALITY, false, "MQ-9"); gw.present(8, S_AIR_QUALITY, false, "MQ-135"); } void loop() { gw.wait(100); boolean bNeedRefresh = (millis() - lastRefreshTime) > SLEEP_TIME; if (bNeedRefresh) { lastRefreshTime = millis(); } for (int i = 0; i < 8; i++) { int lightLevel = 0; for (int j = 0; j < 32; j++) lightLevel += analogRead(i); lightLevel = (lightLevel / 32); int nDifference = lastLightLevel[i] - lightLevel; if ((abs(nDifference) > 5) || bNeedRefresh) { gw.send(msg.setSensor(i + 1).set(lightLevel)); lastLightLevel[i] = lightLevel; } } }Raw ADC readings are 20-80 (differs from sensor to sensor) for fresh outdoor air.
@robosensor What is on pin 13? In the Setup() warmup part?
btw, I am getting a value of 1 or 2, after warmup. -
@robosensor What is on pin 13? In the Setup() warmup part?
btw, I am getting a value of 1 or 2, after warmup.@gigaguy pin 13 connected to board's led :)
Warm up is just 3-minute pause (with led blinking) between power up and start of main loop measurements transmission. Cold sensors shows very big measurements, so I heating them up for 3 minutes. -
@robosensor What is on pin 13? In the Setup() warmup part?
btw, I am getting a value of 1 or 2, after warmup.@gigaguy
example response of sensors for natural gas (left) and alcohol (right):
-
@robosensor this graph shows well the limit ofg the MQ gas sensors, they somehow all react to the same gases, and thus are not one gas specific.
-
@robosensor this graph shows well the limit ofg the MQ gas sensors, they somehow all react to the same gases, and thus are not one gas specific.
@epierre in general, you are right, but there are exceptions.
This measurements, but one sensor per graph:








And 6-day graph of all sensors:

-
@robosensor sure, but people need to know not to rely for their life on these classes of sensors.
-
is it normal that the reads of my MQ-2 sensor are 0ppm in fresh air?
If I use a lighter to throw some gas, the reads skyrocket and then without gas they go back to zero.
Should I adjust the sensitivity? -
@Viper_Scull If you follow my method, it considers clean air has no toxic gas so it should be 0.
If you are able to do a calibration, you could change that, but I would recommend to keep the straight lean air way if you cannot do that.
-
@Viper_Scull If you follow my method, it considers clean air has no toxic gas so it should be 0.
If you are able to do a calibration, you could change that, but I would recommend to keep the straight lean air way if you cannot do that.
@epierre said:
@Viper_Scull If you follow my method, it considers clean air has no toxic gas so it should be 0.
If you are able to do a calibration, you could change that, but I would recommend to keep the straight lean air way if you cannot do that.
@epierre I use the AirQualitySensor example in the MySensors library that I believe is your work indeed. Happy now to know that it's ok 0ppm for clean air.
One thing I noticed on the sketch is that last_mq inital value is 0. If we are in clean air, no value is send to the gateway when connected because val_mq = last_mq, so the controller would have no data to display unless it sets it to zero by default or gas is present.
By the way, I can't get domoticz to recognize this sensor. It receives the name of the sketch and the version, but although I can see that the sensor sends the value, there's no sign of it in the log of domotic and no device is recognized.
-
@Viper_Scull I have someone else reporting this, you should ask @GizMoCuz for him to support it
-
@epierre, already asked. Turns out, domoticz doesn't support V_VARs. Changing V_VAR1 in the sketch for V_DUST_LEVEL works.
-
@epierre, already asked. Turns out, domoticz doesn't support V_VARs. Changing V_VAR1 in the sketch for V_DUST_LEVEL works.
@Viper_Scull Domoticz supports V_VARs, just not as a viewable or modifiable value on the controller. It will store and return the V_VARs values for the sketch, nothing more.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login