The Winsen MH-Z19 carbon dioxide sensor can be purchased for around $20 USD.
Usage[edit | edit source]
These CO2 modules cost about $17 USD. They come in 3 models: 0-2000PPM, 0-5000PPM, and 0-10000PPM (though not according to the datasheet?). These modules can be sensed with either the PWM output or via serial/UART.
The modules automatically measure the CO2 levels every 5 seconds which can be seen by the slight orange glow that's emitted from inside the module. It measures CO2 levels regardless of whether any requests are made via UART, which makes sense since it needs up to date data for the PWM output to be accurate.
Wiring[edit | edit source]
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[edit | edit source]
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[edit | edit source]
- Datasheet: https://www.winsen-sensor.com/d/files/PDF/Infrared%20Gas%20Sensor/NDIR%20CO2%20SENSOR/MH-Z19%20CO2%20Ver1.0.pdf