nara256 / mhz19_uart

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MHZ19_uart

Arduino IDE library for operating the MH-Z19 CO2 sensor in ESP-WROOM-02/32(ESP8266/ESP32) or Arduino
version 0.31

Credits and license

License MIT

How to use

  • 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 !

caution

  • MH-Z19 is supporting PWM , but this library is supporting only serial connection.
  • this library is testing only ESP-WROOM-02/32(ESP8266/ESP32) boards. if you can't execute this library on your arduino (or clone) boards, please contact me.

MHZ19_uart library function

Constractor

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

public function

  • 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.)

link

history

  • ver. 0.1: closed version.
  • ver. 0.2: first release version.
  • ver. 0.3: support ESP-WROOM-32(ESP32), Change library name. (MHZ19_Serial -> MHZ19_uart)
  • ver. 0.31: Operation check on MH-Z19C, Delete functions getStatus() and isWarming(), And refactor details.

About

License:Other


Languages

Language:C++ 100.0%