mhz19b

package module
v0.0.0-...-078f290 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2025 License: GPL-3.0 Imports: 3 Imported by: 0

README

mhz19b

A Go package to allow you to communicate with MH-Z19B CO2 sensor.

MH-Z19B has UART and PWM output modes. This driver communicates in UART mode.

Sensor can be connected to a small single-board computers (like Orange Pi, Raspberry Pi and so on) or even to desktop PC. All that is needed are GPIO pins that support UART (and this should be supported by OS).

MH-Z19B documentation

mh-z19b-co2-ver1_0.pdf

Usage

package main

import (
	"fmt"
	"log"

	"github.com/avbasyrov/mhz19b"
)

func main() {
	sensor := mhz19b.New("/dev/ttyS5") // Choose correct serial device, on Windows systems it will look like "COM45"

	const set2kDetectionRange = true // Sets detection range 2000ppm
	const disableABC = true          // Disables Automatic Baseline Correction

	err := sensor.Connect(set2kDetectionRange, disableABC)
	if err != nil {
		log.Fatal(err)
	}

	co2level, err := sensor.ReadCO2()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("CO2 level: %d ppm\n", co2level)
}

Methods

Connect(set2kDetectionRange, disableABC bool) error
ReadCO2() (uint16, error)
Set2kDetectionRange() error
DisableABC() error

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Sensor

type Sensor struct {
	// contains filtered or unexported fields
}

func New

func New(device string) *Sensor

func (*Sensor) Connect

func (s *Sensor) Connect(set2kDetectionRange, disableABC bool) error

func (*Sensor) DisableABC

func (s *Sensor) DisableABC() error

DisableABC - disables Automatic Baseline Correction (ABC logic function) ABC logic function refers to that sensor itself do zero point judgment and automatic calibration procedure intelligently after a continuous operation period. The automatic calibration cycle is every 24 hours after powered on. The zero point of automatic calibration is 400ppm. From July 2015, the default setting is with built-in automatic calibration function if no special request. This function is usually suitable for indoor air quality monitor such as offices, schools and homes, not suitable for greenhouse, farm and refrigeratory where this function should be off. Please do zero calibration timely, such as manual or commend calibration.

func (*Sensor) ReadCO2

func (s *Sensor) ReadCO2() (uint16, error)

func (*Sensor) Set2kDetectionRange

func (s *Sensor) Set2kDetectionRange() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL