I have connected up one of the MH-Z19C co2 sensors to an esp8266 nodemcu and I am getting bad data from the co2 sensor. 5000ppm which is the max value it can read. The temp value of the sensor is correct however:
Can anyone who might have hooked one of these up assist me in setting it up correctly?
The red led light on the sensor itself is flashing on and off (not sure what this means?).
Also, the little white fabric over that light, does it need to be removed? It came with 0 instructions.
I have one of MH-Z19C. You should NOT Remote the white filter.
I checken my logs
I get:
[21:05:33][D][mhz19:046]: MHZ19 Received CO₂=468ppm Temperature=20°C Status=0x40
I see that i get status 0x40 and you get 0x0.
So maybe something is wrong. Maybe you could try to disconnect or cross them tx or rx cable and see if the status change.
When I connect it to my esp I did the classic mistake to connect the pin defined rx to rx on the mh-z19 and tx to tx. When they should be crossed rx to tx .
Mine doesn’t have a led so I cannot help there.
I t have automatic calibration. So if you leave it on for a time maybe it will fix it self.
Sorry that I don’t have so much solution to offer. But I hope you figure it out.
So I have the same version as the guy in this video, the one with 7 cables https://www.youtube.com/watch?v=Gp-5t1zlnuw
Which is where I got my pin layout from (for some reason I could not find anything on the 19C version without the pins)
Connected it like so:
Red -> 3.3v
Black -> GND
Blue -> TX
Green -> RX
He has blue/green cables swapped in his video but that just gives me an error which goes away if I swap them around (this could be what you mentioned above rx to tx, tx to rx)
Could be it just takes time but seems like maybe my cabling is not correct or maybe my yaml.
Can you please post your yaml config for this sensor so that I can compare?
Thanks
I see that you are using the pins marked with tx and rx. I know that they maybe used by the esp itself. I suggest to try to use the pin GPIO 4 and GPIO5 instead (Usually d1 and d2). The esphome will use the softserial instead. Read that the esp8266 always uses soft serial. More reason to use more safe pins like the gpio4 and gpio5.
That the only thing that I could come up with.
/Mattias
My config below.
Note that it really old I have not updated mine to the latest version. It keeps going.
Thanks and yes I have tried those pins also but I am using rx/tx just fine with an SGP30 and it works fine as long as I change the logger to UART1 otherwise it uses UART0 by default which creates a conflict.
Will try this again today just in case
The value is always stuck at 5000 ppm
Once I do I start to see it, around 500 ish which is better but according to the documentation https://esphome.io/components/sensor/mhz19.html it says to leave it in a stable env for around 20 mins but still not sure on the setup of automatic_baseline_calibration should it be true or false?
How exactly is the calibration working?
The calibration uses the fact that the carbon dioxide content in the air is around 400 ppm. So when it measures during the calibration on. It looks for the lowest point of the measurement and sets it to 400.
So the big question is should you go on automatic baseline calibration or not. If you do that it will recalibrate it self every 24 hours I think. That means that sometimes it get a lowest point that is not 400. Which affect the values for upcoming time until the next calibration.
So there is no straight answer. If you have a can of calibration gas. You could calibrate it with that and it will not need calibration for a long time. But If you dont have that. I guess that you have to try some and see if you get something that seems reasonable.
Looks like this does not suffer from drift after time (like the SGP30 sensor) so if I can calibrate it once correctly, will it keep the correct value indefinitely, will it reset on restart/power off?
Also, when I call the mhz19_calibrate_zero service, does it just set the current value as the zero value? Or does it read it for some time then picks one automatically?
I dont know about the restart/reboot. It should be pretty long term stable what I have understand.
I dont know in such detail about how the calibration works if it a one short low point or if it starts and pick the lowest part during a certain timeperiod.
This is the library that esphome uses.
There are some links to there to some pdf. But It not clear in detail how it works.
have you figured out how to solve this issue?
I have exactly the same problem. Temperature is ok, but CO2 level is at 5000 ppm without change.
Changed pins, did some calibrations (I don’t know if the sensor really made a calibration) but no relsult.
I just want to meantion that you can manually calibrate the MH-Z19 sensor by connecting GND pin and HD pin for a minimun of 7 seconds in fresh air (outside). This will set the sensor to 400ppm but you must be in an enviroment were the air is around 400ppm (outside depending on were you live).