leonlucc / WZ

Arduino library for Dart WZ-S, Prosense WZ-H3 and Winsen ZE08-CH2O formaldehyde (HCHO) sensors. 达特WZ-S、普晟WZ-H3、炜盛ZE08-CH2O系列甲醛传感器的Arduino开发库

Home Page:https://reference.arduino.cc/reference/en/libraries/wz-library/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WZ Library

Arduino library for Dart WZ-S, Prosense WZ-H3 and Winsen ZE08-CH2O formaldehyde (HCHO) sensors, using methods same with the PMS Library.

中文介绍

Applicable Sensors

brand model product documents
DART WZ-S, WZ-S-K WZ-S module product detail
WZ-S module manual
Prosense WS-H3, WS-H3-N WZ-H3 module product detail
WZ-H3 module manual
Winsen ZE08-CH2O, ZE08K-CH2O, ZE08B-CH2O ZE08-CH2O module product detail
ZE08-CH2O module manual

Installation

Just use Arduino Library Manager and search "WZ Library" in Sensors category.

Basic Usage

Read in active mode using ESP32-S board

#include "WZ.h"

/////////////////////////// ESP32-S NodeMCU Board
/*
 * There are three serial ports on the ESP32 known as UART0, UART1 and UART2.
 *
 * UART0 (GPIO1 - TX0, GPIO3 - RX0) is used to communicate with the ESP32 for programming and during reset/boot.
 * UART1 (GPIO10 - TX1, GPIO9 - RX1) is unused and can be used for your projects. Some boards use this port for SPI Flash access though
 * UART2 (GPIO17 - TX2, GPIO16 - RX2) is unused and can be used for your projects.
 *
 */

WZ wz(Serial2); // UART2
WZ::DATA hcho_data;

void setup()
{
    Serial.begin(115200);
    Serial2.begin(9600);
    // wz.activeMode();
}

void loop()
{
    if (wz.read(hcho_data))
    {
        Serial.print("HCHO (ppd): ");
        Serial.println(hcho_data.HCHO_PPB);
        Serial.print("HCHO (ug/m3): ");
        Serial.println(hcho_data.HCHO_UGM3); // no data here, 0 returned
        Serial.println();
    }
    // Do other stuff...
}

Read in passive mode using Arduino Nano board

#include "WZ.h"
#include <SoftwareSerial.h>

/////////////////////////// Arduino Nano Board
/*
 * There is only one serial port on the Arduino Nano, so software serial is needed to connect to the sensor. 
 */
const byte PIN_RX = 8; // define software serial RX pin
const byte PIN_TX = 9; // define software serial TX pin
SoftwareSerial WzSoftSerial(PIN_RX, PIN_TX);
WZ wz(WzSoftSerial);
WZ::DATA hcho_data;

void setup()
{
    Serial.begin(9600);
    WzSoftSerial.begin(9600);
    wz.passiveMode();
}

void loop()
{
    wz.requestRead();
    if (wz.readUntil(hcho_data))
    {
        Serial.print("HCHO (ppd): ");
        Serial.println(hcho_data.HCHO_PPB);
        Serial.print("HCHO (ug/m3): ");
        Serial.println(hcho_data.HCHO_UGM3); 
        Serial.println();
    }
    delay(1000);
    // Do other stuff...
}

more examples here

Acknowledgements

  • this project is based on PMZ
  • this project is inspired by WZ-S

License

  • MIT

About

Arduino library for Dart WZ-S, Prosense WZ-H3 and Winsen ZE08-CH2O formaldehyde (HCHO) sensors. 达特WZ-S、普晟WZ-H3、炜盛ZE08-CH2O系列甲醛传感器的Arduino开发库

https://reference.arduino.cc/reference/en/libraries/wz-library/

License:MIT License


Languages

Language:C++ 100.0%