Tim's blah blah blah

Measuring CO2 using MH-Z19B and D1 mini pro

(Updated: )

In this article I describe how to measure CO2 levels using an MH-Z19B CO2 sensor (winsen-sensor.com) connected to D1 mini pro (wemos.cc) and push these somewhere over wifi.

CO2 sensor

There are numerous CO2 sensors available, a non-exhaustive follows here:

  1. MH-Z19 (winsen-sensor.com), sometimes also denoted as MH-Z19A: original version, with a less optimal auto-calibration function
  2. MH-Z19B (winsen-sensor.com): improved version which you want

Connecting MH-Z19B

The MH-Z19B requires 5V to operate. I’ve connected the sensor as follows (based on this article (esp8266-server.de) and this pinout (escapequotes.net)):

Reading data

I used the “MH-Z CO2 Sensors” library by Tobias Schürg (github.com) to read out the sensor. You can install this in the Arduino IDE via the library manager.

In the example program, I updated the pins using the above connection:

// pin for uart reading
#define CO2_IN D0

// pin for pwm reading
#define MH_Z19_RX D2
#define MH_Z19_TX D1

Once updated, compile and upload the program to the D1 mini and open the serial monitor (at the right baud rate) to read the CO2 values. Once everything is correct, you should see something like (in this case with debugging turned on):

-- read CO2 uart ---
  >> Sending CO2 request.
  << FF  86  9  B9  3D  0  7C  0  FF  
  getCheckSum()
 # PPM UART: 2489
 # Temperature? 17
 Status  OK: 0
PPMuart: 2489, Temperature: 17

One issue I have is that the sensor reports values that are way too high indoors (2500 to 5000 ppm) , which might be because of ABC not working, or the sensor being broken (or maybe I’m not as alive as I feel ;\)).

Sources

#ESP8266 #Smarthome