WifWaf / MH-Z19

For Arduino Boards (&ESP32). Additional Examples/Commands., Hardware/Software Serial
GNU Lesser General Public License v3.0
195 stars 39 forks source link

Readings way off #37

Closed marcelstoer closed 2 years ago

marcelstoer commented 3 years ago

This is likely related to #36 but I did not want to hijack that thread.

I have a recent MH-Z19C (plug version). The C02 readings have been ok-ish from the beginning. I compare them to the readings I get out of a Sensirion SCD41 that sits next to it. The temperature was off by roughly +10°C.

However, after a few weeks the CO2 readings started declining gradually until they ended up far below 400ppm (120-300). The reported temperature was constantly around +-32°C.

To see whether this library may be at fault I tried two others for this sensor and got similar results. I concluded my sensor must have failed the test of time. However, after I scanned #36 I'm not so sure anymore.

Tonight I ran the sensor outside for half an hour. Here's what it reports now (inside again).

Device info

21:57:22.753 -> Firmware Version: 05.12
21:57:22.753 -> Range: 2000
21:57:22.787 -> Background CO2: 500
21:57:22.787 -> Temperature Cal: 50
21:57:22.823 -> ABC Status: ON

Basic usage plus background CO2

22:18:26.583 -> CO2 (ppm): 493
22:18:26.583 -> background CO2: 493
22:18:26.654 -> Temperature (C): 33
22:18:28.653 -> CO2 (ppm): 497
22:18:28.653 -> background CO2: 497
22:18:28.725 -> Temperature (C): 33
22:18:30.716 -> CO2 (ppm): 469
22:18:30.716 -> background CO2: 469
22:18:30.782 -> Temperature (C): 33
22:18:32.815 -> CO2 (ppm): 465
22:18:32.815 -> background CO2: 465
22:18:32.850 -> Temperature (C): 33
22:18:34.858 -> CO2 (ppm): 465
22:18:34.858 -> background CO2: 465
22:18:34.895 -> Temperature (C): 33
22:18:36.939 -> CO2 (ppm): 468
22:18:36.939 -> background CO2: 468
22:18:36.976 -> Temperature (C): 33
22:18:38.985 -> CO2 (ppm): 466
22:18:38.985 -> background CO2: 466
22:18:39.056 -> Temperature (C): 33
22:18:41.054 -> CO2 (ppm): 491
22:18:41.054 -> background CO2: 491
22:18:41.126 -> Temperature (C): 33
22:18:43.143 -> CO2 (ppm): 492
22:18:43.143 -> background CO2: 492
22:18:43.181 -> Temperature (C): 33
22:18:45.198 -> CO2 (ppm): 485
22:18:45.198 -> background CO2: 485
22:18:45.232 -> Temperature (C): 33
22:18:47.263 -> CO2 (ppm): 436
22:18:47.263 -> background CO2: 436
22:18:47.299 -> Temperature (C): 33
22:18:49.342 -> CO2 (ppm): 440
22:18:49.342 -> background CO2: 440
22:18:49.380 -> Temperature (C): 33
22:18:51.414 -> CO2 (ppm): 494
22:18:51.414 -> background CO2: 494
22:18:51.450 -> Temperature (C): 33
22:18:53.455 -> CO2 (ppm): 506
22:18:53.455 -> background CO2: 506
22:18:53.529 -> Temperature (C): 33

-> CO2 and background always the same -> CO2 is off by ~500ppm compared to the SCD41 that I consider accurate -> CO2 readings are highly volatile, jumping 10% in just a couple of seconds -> appears to be caused by the sensor calibrating -> temperature is off by 10°C

WifWaf commented 3 years ago

Yes, it's likely the same issue.

The gradual decline in ppm would be due to the sensors autocalibration. Why it is going below 400ppm I'm not sure? While it could be correct (it does occur sometimes), I agree it's unlikely if your other sensor is reporting differently. If I was to guess, it could be a range issue, you could try setting the range to 2000 and see if it helps (changing span needs calibration equipment). If this fails, you could try zeroing the sensor manually and turning autocalibration off.

I hope to have some time to look at the new firmware changes next week (or the week after), I have the C version to test.

WifWaf commented 3 years ago

Just to add, the background CO2 value mirroring get CO2 is also due to the new firmware. It's not usually volatile however unless you are near to it (breathing etc) or have the black pcb version.

marcelstoer commented 3 years ago

I've been using a 2nd MH-Z19C for the past 10d (continuously). Today I grew suspicious if its readings; have them visualized on a screen on my desk. Sure enough, when compared to the Sensirion SCD41 it's again off by a few hundred ppms. That wasn't the case when I started using it.

Even though you provide great sketches incl. explanations I haven't tried fiddling with the settings of the sensor yet for a couple of reasons:

Is it justified I am worried I could irreversibly break something running your sketches? Given the described behavior what procedure would you recommend to either fix it or to provide maybe more data points?

WifWaf commented 3 years ago

I think your caution is warranted in all honesty.

The library/examples include undocumented (unofficial) commands, so newer versions (*of the sensor) hold no guarantees; the lack of documentation is probably the largest downside to the sensor.

I would personally try setting the range to 2000 (unless it's specified on the sensor otherwise), as this is the most accurate range and usually the default The range command is official, however, the auto-calibration will need time to adjust.

I would stay clear of the span function.... however, as a last resort, I've used an airtight bag with a working sensor alongside the one with issues. I tried to get the ppm around 2000 (the span/range value I'm using) by simply breathing into it, and then called the function. It worked relatively well, but it's not an exact science.. :)

marcelstoer commented 3 years ago

So, to confirm...you would use

myMHZ19.autoCalibration(false);   // make sure auto calibration is off for this example
Serial.print("ABC Status: "); myMHZ19.getABC() ? Serial.println("ON") :  Serial.println("OFF");  // now print it's status
myMHZ19.setRange(2000);

like in your CalibrationPlus.ino sketch even though the comments there warn

Changing this, usually requires changing Span which is not recommended.

Correct?

WifWaf commented 3 years ago

This looks correct - if you're using auto-calibration, you should be able to leave it on here as the calibration (zeroing) function isn't being called.

During calibration testing, I have had to reset the span a few times. It's not clear why or whether it was due to the sensor I was using (I corrupted the firmware), however, it 'shouldn't' be needed.

*As I'm unsure and struggle with time to repeat the testing, I err on the side of caution in regards to warnings. But to clarify, this would be the first step I would take if the sensor is still not reading correctly after either manual calibration or allowing the auto-calibration a few weeks to adjust.

WifWaf commented 2 years ago

Closing for now as no activity, feel free to comment again to open the issue.