MH-Z19B

From RevSpace
Revision as of 16:11, 1 October 2019 by Disasm (talk | contribs)
Jump to navigation Jump to search
Project MH-Z19B
Mhz19.jpg
Some research into the MH-Z19B CO2 sensor
Status Initializing
Contact Disasm
Last Update 2019-10-01

Introduction

MH-Z19B is an updated version of the MH-Z19 sensor.

Datasheet: https://www.winsen-sensor.com/d/files/infrared-gas-sensor/mh-z19b-co2-ver1_0.pdf

Hardware

  • STM32F051K86 MCU
  • Unknown analog light+temperature sensor
  • Two 3.3V regulators
  • 1.5V voltage reference
  • Lamp

Teardown

Back side of the MH-Z19B sensor with unlabeled SWD pads on the right:

MH-Z19B-back.jpg

Front side of the (4-layer) PCB:

MH-Z19B-pcb.jpg MH-Z19B-pcb-markings.jpg MH-Z19B-pcb-tracks.jpg

Partial schematics:

MH-Z19B-schematics.png

Firmware

MCU firmware can be easily dumped through SWD pads. Pinout:

Pin Signal
1 (square) 3V3
2 GND
3 SWDIO
4 SWCLK
5 RESET (active low)

Additionally, bootloader asks for a firmware update during the first 20s of startup.

Operation

Firmware turns on lamp for 400 ms and measures sensor response along with the voltage of the voltage reference. This happens again and again in cycle. Default cycle length is 5s.

MH-Z19B-operation.png

Firmware measures only a part of the response signal: 180..980 ms interval in 10ms steps. It integrates 180..680 ms interval and removes constant component (1.026V on the image above) based on values from the 930..980 ms interval. Obtained result after some smoothing is available (divided by 2) via command 0x84. This value is used for subsequent computations.

Another firmware turns on lamp for 500 ms and measures 450..500 ms and 1800..1850 ms intervals, then uses the second one to remove constant component from the first one.

As stated in the datasheet, MH-Z19B should be kept away from heat. Experiment showed that the light sensor inside MH-Z19B stops working when exposed to an air stream from a heat gun.

MH-Z19B-heating.png

Interface

Sensor provides UART, PWM and analog output interfaces. Both PWM and analog output provide CO2 measurement result limited by some bounds. UART interface implements one of several protocols. Default protocol ("operation mode 0") is the richest one.

Protocol (operation mode 0)

All commands and responses are 9 bytes in size. Most of the commands have a response, but some -- don't. Response contains command code, both command and response contain checksum value.

Command format: 0xFF, 0x01, CMD, (5 bytes of parameters), CKSUM

Response format: 0xFF, CMD, (6 bytes of response), CKSUM