UedaTakeyuki / mh-z19

Read CO2 concentration from mh-z19 sensor on the Raspberry Pi & handle it. Detect Raspberry Pi model automatically and read the value from an appropriate serial device.
MIT License
182 stars 37 forks source link

Add option to read temperature #5

Closed rzarajczyk closed 5 years ago

rzarajczyk commented 5 years ago

According to this webpage https://revspace.nl/MHZ19 it should be possible (although not documented in official datasheet) to read the temperature along with CO2 level. Would it be possible to include this information in the result?

UedaTakeyuki commented 5 years ago

Hi Rafał,

Thank you for your good request. It sound to be nice idea! I'll try to add it soon.

UedaTakeyuki commented 5 years ago

Hi Rafał,

I've updated mh_z19.py to return all of command 0x86 feedback as follows:

sudo python3 mh_z19.py --all
{"UhUl": 10523, "temperature": 17, "TT": 57, "co2": 539, "SS": 232}

sudo python -m mh_z19 --all
{"SS": 232, "UhUl": 10523, "TT": 57, "co2": 551, "temperature": 17}

How do you feel about it? Thank you for your feedback!

rzarajczyk commented 5 years ago

I'm really impressed with the implementation time! The implementation itself seems to be correct - it does provide results according to the spec.

However I'm disappointed with the accuracy of MH-Z19 thermometer - in my setup (RPI 1B + MH-Z19 [TBH I don't know which version]) it shows 29-30 °C in the room where actual temperature is 22 °C. So either the the thermometer is inaccurate, or the revspace article was wrong.

Anyway thank you for immediate response! I really appreciate your code!

UedaTakeyuki commented 5 years ago

Hi Rafał,

IMHO, the TT value might be related temperature, but this may NOT be a ambient temperature, but also heated temperature for measuring CO2.

The principle of CO2 concentration detection is called NDIR(Nondispersive Infrared ). As a rule of thum, this calibrate the temperature near the thermal infrared heater which is falling due to absorption by CO2. Detail explanation of NDIR is available here. Figure 1. of the document might be informative to get intuitive understanding.

I think TT value must be related the NIDR calibration value which is heated a bit.

For calibrate room temperature, I think DHT22 might be one of the good sensor module with good accurate and inexpensiveness.

By the way, please feel free to ask me anything. I also really appreciate if I can help you!