m
Line 22: Line 22:
 
*Datasheet: https://www.winsen-sensor.com/d/files/PDF/Infrared%20Gas%20Sensor/NDIR%20CO2%20SENSOR/MH-Z19%20CO2%20Ver1.0.pdf
 
*Datasheet: https://www.winsen-sensor.com/d/files/PDF/Infrared%20Gas%20Sensor/NDIR%20CO2%20SENSOR/MH-Z19%20CO2%20Ver1.0.pdf
  
 
+
{{Navbox Tinkering}}
 
+
[[Category:Tinkering]]
<br />
 

Revision as of 16:46, 26 July 2020

The Winsen MH-Z19 carbon dioxide sensor can be purchased for around $20 USD.

Usage

Wiring

Provide the module with 5V power. With the default wire connector, the green wire is TX and blue is RX. Connect TX to RX and vice versa when using the MH-Z library.

Measurement

MH-Z19 PWM
MH-Z19 PWM

The PWM output has a period of 1004ms. The amount of time that the signal is high corresponds linearly with the sensor's maximum ppm.

Since timing the PWM output takes 1 second per reading, it may be desirable to just use the UART interface to poll the sensor.

For the ESP8266, you can use this project to interface with both the UART and the PWM output:

This project however hardcodes a preheating time interval of 3 minutes since the start (or reset) of the ESP. There is also a 'response time' interval of 2 minutes for the MH-Z19B which isn't specified anywhere in the datasheet and locks out the ability to do frequent polling for a CO2 measurement. This is mostly pointless since the PWM measurement is always constant, meaning the module measures the CO2 measurement constantly. Fix this by editing the MHZ.cpp file and set the preheating time to 0 and the response time to 1000ms.

See Also