MH-Z16 UART communication library for ESP32
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Add .gitignore for C++ Apr 13, 2018
LICENSE
MHZ16_uart.cpp Initial commit Apr 13, 2018
MHZ16_uart.h Initial commit Apr 13, 2018
README.md Fix line ends in pinout list Dec 20, 2018

README.md

MHZ16_uart

Arduino IDE library for the MH-Z16 CO₂ sensor. Tested with ESP32 but might just work for Arduino too.

Version 0.1

Credits and License

By: Intar BV

Based on: https://github.com/nara256/mhz19_uart

License: MIT

Usage

  1. Add this library to your Arduino IDE's libraries folder.

  2. Include the library in your program

  3. 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

  4. Upload your program to the ESP32

Warnings

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.

Reference

MHZ16_uart()

Default constructor. You must call begin(int rx, int tx) before you can use the MH-Z16

MHZ16_uart(int rx, int tx)

Constructor that sets Rx and Tx pin, and initialises the serial interface.

void begin(int rx, int tx)

Set the Rx and Tx pin, and initialise the serial interface.

void calibrateZero()

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.

void calibrateSpan(int ppm)

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.

int getPPM()

Read the CO₂ concentration in PPM from the sensor. On a read error the return value is -1.

bool isWarming()

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

MH-Z16 Datasheet

http://www.winsen-sensor.com/d/files/PDF/Infrared%20Gas%20Sensor/NDIR%20CO2%20SENSOR/MH-Z16%20CO2%20V2.1.pdf

Change log

Version 0.1

First release