Loading...
Searching...
No Matches
MH-Z19 CO2 sensor

MH-Z19 CO2 sensor driver. More...

Detailed Description

MH-Z19 CO2 sensor driver.

Description

The MH-Z19 is a CO2 sensor. Measurements are provided in parts per million (ppm) over UART and PWM. The ppm value ranges from 0 (theoretically) to 2000 or 5000, depending on the sensor settings.

In UART mode, additional commands are available to configure the sensor.

Note that the sensor requires considerable time before accurate measurements are provided.

Files

file  mhz19.h
 Interface definition for the MH-Z19 CO2 sensor driver.
 
file  mhz19_internals.h
 Internal addresses, registers, constants for the MH-Z19 CO2 sensor.
 
file  mhz19_params.h
 Default configuration for MH-Z19.
 

Enumerations

enum  { MHZ19_OK = 0 , MHZ19_ERR_INIT = -1 , MHZ19_ERR_TIMEOUT = -2 , MHZ19_ERR_CHECKSUM = -3 }
 Status and error return codes. More...
 

Functions

int mhz19_init (mhz19_t *dev, const mhz19_params_t *params)
 Initialize a MH-Z19 device.
 
int mhz19_get_ppm (mhz19_t *dev, int16_t *ppm)
 Get measured CO2 ppm value.
 

Variables

const saul_driver_t mhz19_ppm_saul_driver
 Export SAUL endpoint.
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Status and error return codes.

Enumerator
MHZ19_OK 

everything was fine

MHZ19_ERR_INIT 

error initializing the device

MHZ19_ERR_TIMEOUT 

timeout on retrieving sensor data

MHZ19_ERR_CHECKSUM 

checksum failure on received data

Definition at line 62 of file mhz19.h.

Function Documentation

◆ mhz19_get_ppm()

int mhz19_get_ppm ( mhz19_t *  dev,
int16_t *  ppm 
)

Get measured CO2 ppm value.

Parameters
[in]devdevice descriptor
[out]ppmint16_t buffer where CO2 measurement will be written to, in ppm
Returns
MHZ19_OK
MHZ19_ERR_TIMEOUT
MHZ19_ERR_CHECKSUM

◆ mhz19_init()

int mhz19_init ( mhz19_t *  dev,
const mhz19_params_t *  params 
)

Initialize a MH-Z19 device.

Parameters
[out]devdevice descriptor
[in]paramsMH-Z19 initialization struct
Returns
MHZ19_OK
MHZ19_ERR_INIT