Arduino IDE library for the MH-Z16 CO₂ sensor. Tested with ESP32 but might just work for Arduino too.
Version 0.1
By: Intar BV
Based on: https://github.com/nara256/mhz19_uart
License: MIT
-
Add this library to your Arduino IDE's libraries folder.
-
Include the library in your program
-
Connect your MH-Z16 sensor to your ESP32
MH-Z16 Vcc to 5V power supply
MH-Z16 GND to common GND
MH-Z16 Tx to ESP32 GPIO pin to use as Rx
MH-Z16 Rx to ESP32 GPIO pin to use as Tx
Other MH-Z16 pins are not supported -
Upload your program to the ESP32
This library only supports serial UART communication with the MH-Z16.
This library has only been tested on ESP32S.
The isWarming()
function does not indicate whether the MH-Z16 is warming up.
Default constructor. You must call begin(int rx, int tx) before you can use the MH-Z16
Constructor that sets Rx and Tx pin, and initialises the serial interface.
Set the Rx and Tx pin, and initialise the serial interface.
Calibrate the zero-point. According to the documentation the MH-Z16 sensor must have been working in a stable gas environment with a CO₂ concentration of 400ppm for 20 minutes before you call this function.
Calibrate the span point. According to the documentation the MH-Z16 sensor must have been working in a stable gas environment with a CO₂ concentration of ppm
for 20 minutes before you call this function.
Read the CO₂ concentration in PPM from the sensor. On a read error the return value is -1.
The return value indicates whether the documenation mandated 3 minutes of warm-up time have passed since the call to either MHZ16_uart(int rx, int tx)
or begin(int rx, int tx)
.
Caution: This is not a value read from the MH-Z16
First release