Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
/ CO2-Logger Public archive
forked from alpacagh/MHZ14-CO2-Logger

Monitor CO2 concentration using MH-Z19 (or the older Z14) sensor connected with UART.

License

Notifications You must be signed in to change notification settings

sammcj/CO2-Logger

 
 

Repository files navigation

MH-Z19 CO2 sensor reader, logger and visualiser

plot

  • Reads data from UART(serial)-connected MH-Z19 (or MH-Z14) sensor using python 3.
  • If you dare to install nodejs you can visualise the logged data (using html and plotly.js library).

Usage

Connection

Sensor can be queried using 3.3v UART at 9600 bps. Sensor main feed voltage is 5v.

Can be connected to computer using almost any USB-UART converter if voltage matches.

Requirements

  • Python3
  • pip3 install serial pyserial
  • A USB -> Serial UART connector (Could also be used with Raspberry Pi, ESP8266, Arduino etc...)
  • MH-Z19 Co2 Sensor (Around $25AUD on eBay)

Querying

$ python3 CO2Reader.py --tty=/dev/tty.SLAB_USBtoUART --timeout=2
Connected to /dev/tty.SLAB_USBtoUART
2019-02-25 07:44:48 558 58
2019-02-25 07:44:49 558 58
2019-02-25 07:44:51 558 58
...

3 fields separated by tab: timestamp, CO2 concentration (ppm), internal sensor temperature (Celsius)

Use stream redirection to save data series to file:

touch co2.log
python3 CO2Reader.py --tty=/dev/tty.SLAB_USBtoUART --timeout=2 >>co2.log

Options

  • --tty (optional) tty to connect to (default is /dev/tty.SLAB_USBtoUART)
  • --single (optional) perform a single measurement and exit
  • --quit (optional) connect to the sensor and quit immediately
  • --timeout (optional) time between requests (defaults to 10 seconds)
  • --command (optional) raw command to pass to the sensor - use carefully (default is to read Co2 levels)

Sensor Commands

Raw commands can be passed to the Co2 sensor, these to be used with caution.

Example:

python3 CO2Reader.py --tty=/dev/tty.SLAB_USBtoUART --timeout=1 --command='0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79'

Default operation (Reads Co2 levels)

0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79

Enable ABC

0xFF, 0x01, 0x79, 0xA0, 0x00, 0x00, 0x00, 0x00, 0xE6

Disable ABC

0xFF, 0x01, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86

Measurement Ranges

(Note: Untested)

  • 1000 = 0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x03, 0xE8, 0x7B
  • 2000 = 0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x07, 0xD0, 0x8F
  • 3000 = 0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x0B, 0xB8, 0xA3
  • 5000 = 0xFF, 0x01, 0x99, 0x00, 0x00, 0x00, 0x13, 0x88, 0xCB

Run Zero Point (400ppm) calibration

  • Run this for 10mins + in 400ppm Environment

WARNING: DO NOT RUN THIS UNLESS YOU KNOW WHAT YOU ARE DOING!

0xFF, 0x01, 0x87, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78

Visualizing

  1. Install npm dependencies npm install
  2. Start server python3 -m http.server 8088 --bind 127.0.0.1
  3. Open browser at http://127.0.0.1:8088/plot.html
  4. Select your log file in input field

Technical Specifications MH-Z19

Attribute Value
Target gas Carbon Dioxide CO2
Operating Voltage 3.6 to 5.5 Vdc
Operating current < 18mA average
Interface levels 3.3 Vdc
Output signal format UART or PWM
Preheat time 3 min
Response time <60 s
Accuracy ± (50 ppm+5% reading value)
Measuring range 0 to 5000 ppm
Operating temperature range 0 to + 50°C
Dimensions 33mm×20mm×9mm(L×W×H)

Wiring

Function UART / Signal MH-Z19 pin
Vcc +5V +5V 6 Vin
GND GND 7 GND
UART TXD0 2 RXD
UART RXD0 3 TXD

co2-sensor-mh-z19-pinout

Photos

MH-Z19 Sensors

41byp-zvj1l sx342 350px-mhz19

Connected to a USB -> UART adapter

mh-z19

Calibration

Don't use this function unless you know what you are doing or you may incorrectly calibrate the sensor!

(Australia has an average of around 400-410PPM and Sensor zero point is 400PPM)

mhz - calibration

Credits

Licence

MIT licence

About

Monitor CO2 concentration using MH-Z19 (or the older Z14) sensor connected with UART.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 65.4%
  • JavaScript 19.4%
  • HTML 15.2%