m
 
Line 2: Line 2:
  
 
==Usage==
 
==Usage==
These CO2 modules cost about $17 USD. They come in 3 models: 0-2000PPM, 0-5000PPM, and 0-10000PPM.
+
[[File:MH-Z19 CO2 Sensor.jpg|alt=MH-Z19 CO2 Sensor glowing every 5 seconds|thumb|MH-Z19 CO2 Sensor. It glows approximately every 5 seconds (pictured on left)]]
 +
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.
  
Interface: PWM or 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===
 
===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.
 
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.

Latest revision as of 12:20, 2 August 2020

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

Usage[edit | edit source]

MH-Z19 CO2 Sensor glowing every 5 seconds
MH-Z19 CO2 Sensor. It glows approximately every 5 seconds (pictured on left)

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]

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[edit | edit source]