Arduino IDE library for operating the MH-Z19 CO2 sensor in ESP-WROOM-02/32(ESP8266/ESP32) or Arduino
version 0.31
License MIT
Include this library to your Arduino IDE.
Wiring MH-Z19 sensor to your Arduino or ESP-WROOM-02/32(ESP8266/ESP32).
MH-Z19 Vout to Arduino Vout(5V)
MH-Z19 GND to Arduino GND
MH-Z19 Tx to Arduino Digital Pin (Serial Rx pin)
MH-Z19 Rx to Arduino Digital Pin (Serial Tx pin)
other MH-Z19 pins are not used.
Read sample source code. It's very simple !
MHZ19_uart
normal constractor. if you use this constractor, you must execute begin() function after this constractor execute.
MHZ19_uart(int rx, int tx)
setting rx and tx pin, and initialize Serial.
void begin(int rx, int tx)
setting rx and tx pin, and initialize Serial.
void setHardwareSerialNo(int serialNo)
setting hardware serial no. # You can use this function only ESP32.
void setAutoCalibration(bool autocalib)
MH-Z19 has automatic calibration procedure. the MH-Z19 executing automatic calibration, its do zero point(stable gas environment (400ppm)) judgement.
The automatic calibration cycle is every 24 hours after powered on.
If you use this sensor in door, you execute setAutoCalibration(false)
.
void calibrateZero()
execute zero point calibration.
if you want to execute zero point calibration, the MH-Z19 sensor must work in stable gas environment (400ppm) for over 20 minutes and you execute this function.
void calibrateSpan(int ppm)
execute span point calibration.
if you want to execute span point calibration, the MH-Z19 sensor must work in between 1000 to 2000ppm level co2 for over 20 minutes and you execute this function.
int getCO2PPM()
get co2 ppm.
int getTemperature()
get temperature (MH-Z19 hidden function? this function is not support.)
MH-Z19 Data sheet
http://www.winsen-sensor.com/d/files/PDF/Infrared%20Gas%20Sensor/NDIR%20CO2%20SENSOR/MH-Z19%20CO2%20Ver1.0.pdf
MH-Z19B Data sheet
http://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z19b-co2-ver1_0.pdf
MH-Z19C Data sheet
https://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z19c-pins-type-co2-manual-ver1_0.pdf