The MH-Z19B CO2 Sensor Bible

Last modified January 12, 2021

The MH-Z19B CO2 sensor is fantastic. A cheap, accurate CO2 sensor (for the price it has) and very easy to use. The same one that I used to make the CO2 meter.

In this article you will find everything you want to know about it (and if you can't find it, ask in the comments).

Maybe calling it bible, at this moment (12/27/2020, when I start to write it), is a bit pretentious, but I give you my word that it will become. Give it time…

This article is alive and it never stops growing. Subscribe to the Newsletter and don't miss a thing.

During the next few weeks I plan to include a lot of information that I have been collecting, but, If you want any special information, tell me in the comments, to give it priority.

General data of the CO2 sensor MH-Z19B

CO₂ sensor MH-Z19B

The MH-Z19B Carbon Dioxide Gas Sensor is a small-sized, general-purpose smart sensor that uses the principle of non-scattered infrared (NDIR) to detect the presence of CO₂ in the air.

It has good selectivity, long service life, and other characteristics, such as built-in temperature compensation.

It has simultaneous serial, analog and PWM output and is easy to use.

It is a high-performance sensor that combines reliable infrared absorption gas detection technology with good design and an attractive price.

MH-Z19B sensor parameters

Gas detectedCarbon dioxide
Operating voltage4.5 ~ 5.5 V DC
Average current<60m A (@ 5V supply)
Peak current150 mA (supply @ 5V)
Interface level3.3 V (compatible with 5V)
Measuring range0 ~ 2000 ppm
0 ~ 5000 ppm
exit signSerial (UART) - TTL level 3.3 V - PWM analog output
Preheating time3 minutes
Response timeT90<120s
Operating temperature0 ~ 50 ° C
Operating humidity0 to 90% RH (non-condensing)
Dimensions33mm × 20mm × 9mm (Length * Width * Height)
Weight5 grams
Lifetime> 5 years

MH-Z19B Features

Gold-plated gas chamber, waterproof and corrosion resistant
High sensitivity, low power consumption
Excellent stability
Temperature compensation, excellent linear output
Long duration

MH-Z19B Sensor Applications

HVAC Refrigeration Equipment
Surveillance and air quality equipment
Fresh air systems
Air purification equipment
Smart home
Schools and educational centers

What versions of the MH-Z19 sensor are there?

It is difficult to know exactly, since Chinese manufacturers are quite used to making changes to their products without communicating them and, sometimes, there is a parallel market for units marked with other names or references.

Rest assured, there are the following versions:

  1. The original 400 ~ 2000ppm range MH-Z19 model, with 50ppm + 5% precision accuracy of the measurement.
  2. The original 400 ~ 5000ppm range MH-Z19 model, with 50ppm + 5% precision accuracy of measurement.
  3. Model MH-Z19B with range 400 ~ 2000 ppm, which is a more modern and improved version. This version has a precision of 50 ppm + 3% of the measurement.
  4. Model MH-Z19B with range 400 ~ 5000 ppm, which is a more modern and improved version. This version has a precision of 50 ppm + 3% of the measurement.
  5. Model MH-Z19C with range 400 ~ 2000 ppm. This version has an accuracy of 50 ppm + 5% of the measurement.
  6. Model MH-Z19C with range 400 ~ 5000 ppm. This version has an accuracy of 50 ppm + 5% of the measurement.
  7. Model MH-Z19B with range 400 ~ 10000 ppm. All that I discover up to this moment, makes me think it's fake.
  8. Model MH-Z19B with ranges 400 ~ 2000 ppm, 400 ~ 5000 ppm and 400 ~ 10000 ppm with black printed circuit board. Everything indicates that these versions are false.

Zero Point Calibration

The MH-Z19B sensor is pre-calibrated at the factory and, under normal conditions, manual calibration should not be necessary.

Like all sensors of this type, changes in environmental conditions, such as temperature and humidity, and the aging of the sensor itself, cause its measurements to vary over time.

Zero point calibration refers to the method by which the sensor learn at what concentration of CO2 corresponds to a concentration of 400 ppm, or zero point.

This sensor has two methods to perform the zero point calibration: manual calibration and self-calibration.

MH-Z19B Sensor Zero Point Manual Calibration

VERY IMPORTANT: It is essential that, during this manual calibration process, the sensor is pre-operating for at least 20 minutes in a stable CO2 environment (400ppm) (outdoors, for example).

Hardware calibration

If we have physical access to the sensor connections, we can easily begin the zero point calibration procedure, bypassing terminals 5 (HD) and 7 (GND) for 7 seconds.

Software calibration

The sensor has a command, which will order it to perform the zero point calibration at the same time.

We only have to send the command 0xFF, 0x01,0x87,0x00,0x00,0x00,0x00,0x00,0x78

Calibration using ESPEasy

If we are using ESPEasy, among the available commands, we have the mhzcalibratezero command.

We can send the command, for example, loading the page http: // xxxx / tools? Cmd = mhzcalibratezero (we will replace the xxxx with the ESPEasy IP address).

Note: The command should be mhzCMDCalibrateZero, but for some reason it doesn't work (at least in the current version of ESPEasy, at the time of writing this article).

If ESPEasy does not recognize the command mhzcalibratezero, test mhzCMDCalibrateZero (You will know because ESPEasy responds with «Command unknown: mhzCMDCalibrateZero"Or"Command unknown: mhzcalibratezero«).

MH-Z19B sensor zero point auto-calibration

To avoid the user having to perform a manual calibration periodically, the sensor incorporates in its firmware an autocalibration routine, called ABC, which works as follows:

Since the natural CO2 concentration in the atmosphere is approximately 400 ppm, when ABC is enabled, the sensor assumes that, over a 24 hour period, the minimum measurement it takes will be equivalent to 400 ppm.

This means that, in a well-ventilated room, which at some time of the day has clean air, the lowest measurement will be 400 ppm and the sensor will assume it as the zero point, or 400 ppm.

In other words, the sensor will assume that the lowest measurement in each 24 hour period will be 400 ppm.

This is a very convenient way to keep the sensor calibrated, using clean air as a reference value and automating the process.

In addition, we can easily activate and deactivate the ABC routine, so that we can adapt the way the sensor works to our particular needs.

Where can I find more information about the MH-Z19B sensor?

There are a number of sources of information, official and unofficial, very interesting, if you want to get more information about the sensor.

Official sources

The official source par excellence of any electronic component is its datasheet, or data sheet. It is the document in which the manufacturer includes all the information about its product.

Manufacturer data sheets:

Datasheet of the MH-Z19 (an earlier version than the MH-Z19B) in English from 03-03-2015

MH-Z19 DatasheetB in English from 01-21-2016

MH-Z19 DatasheetB in Chinese on 10-15-2020

MH-Z19 DatasheetC in english from 02-04-2020 (available on AliExpress I have not tested this version with ESPEasy yet, nor do I have direct references on how it works.

Unofficial sources


On the blog of RevSpace you have two pages with a lot of information, especially technical, very useful and interesting about the MH-Z19 and about him MH-Z19B


You can find a lot of information, although scattered, in the ESPEasy official forum.

Source code

Although it is not easy to locate, because it is very scattered, I have learned a lot by studying the source code that I have been able to find to use the MH-Z19B. GitHub is a great source of information, in this regard.

MH-Z19B connection

The basic connection of the MH-Z19B sensor is very easy, it only requires four connections. Two for power and two for data transmission.


I recommend looking carefully at the power requirements for your specific sensor. Depending on the version, the acceptable operating voltage may vary.

According to the manufacturer's data sheets, the following operating voltages are accepted:

MH-Z19: 3.6 to 5.5 Volts DC

MH-Z19B: 4.5 to 5.5 Volts DC

MH-Z19C: 4.9 to 5.1 Volts DC

Have watch out for the MH-Z19C. Getting a supply of between 4.9 volts and 5.1 volts (a very narrow range) from a USB port can be "delicate" And if you do not have a multimeter to measure that the voltage that reaches the MH-Z19C is within these ranges, I recommend avoiding it.


It is important that you check the pins for your specific sensor, as some users have reported variations.

As a general rule, most MH-Z19B sensors follow the following pinning (images taken from the MH-Z19 and MH-Z19B sensor datasheets)

MH-Z19 pins


MH-Z19B pins


Is it true that there are fake MH-Z19Bs?

It seems that it does, unfortunately, so you have to be careful where you buy it.

These are especially warning signs:

  • MH-Z19B models with measuring range up to 10,000 ppm. All that I discover up to this moment, It makes me think that all models with a measuring range up to 10,000 ppm are fake.
  • Model MH-Z19B with black printed circuit board. Everything indicates that these versions with black printed circuit board are fake.

Updated Jan 8, 2021: I recently received a fake MH-Z19B (with black plate) that I bought from AliExpress.

I will take the opportunity to write an article with detailed information about fake sensors, how to detect them and the differences in the measurements they provide.

I already tell you that, at least in the one I have with a black plate, the differences in the measurements are enormous (compared to the meter with the Senseair S8 LP detector that I am using as a reference).

Precautions and things to keep in mind

There are a few basic things to watch out for, and while most are obvious, it doesn't hurt to put them together here under one point:

  • Avoid any pressure, in any direction, on the plastic housing during its welding, installation and use.
  • When installed in a small space, the space should be well ventilated, especially its diffusion windows.
  • The module must be away from heat sources and its direct exposure to the sun or other heat sources must be avoided.
  • The module must be calibrated periodically. The manufacturer suggests that it be done every six months. Logically this will depend on the use made of it and the environment in which it is used.
  • Please do not use the sensor in a dusty environment for too long.
  • To ensure normal work, the power supply must be in a range between 5.0V ± 0.1V DC (check your specific version in the "Connecting the MH-Z19B" section of this article). The source current must not be less than 150mA. Outside of this range, it will cause a sensor malfunction (it may indicate a CO2 concentration lower than actual, or the sensor may not function properly).
  • During the manual zero point calibration procedure, the sensor must operate in a stable gas environment (400ppm) for more than 20 minutes. Connect the HD pin low (0V) for more than 7 seconds.
  • Do not use wave or dip solder for the sensor.
  • When welding with a soldering iron, the temperature should be set at (350 ± 5) ° C, and the welding time should be 3 seconds maximum.
If you liked this page, share it.

7 thoughts on “La biblia del sensor de CO2 MH-Z19B”

  1. Very complete information about the sensor ... it will become more than a bible ... hehe
    Tell you that the web link that you put in "Manufacturer's data sheets" about the MH-Z19C leads to the same sheet as the Z19B. And I see it for sale on Aliexpress: (web link shortened, the original spans a bunch of lines). I think I understand that the differences with the B are in a shorter start-up time, a greater amplitude of working humidity and others related to voltages and intensities in mA, which I don't know exactly what they imply ... I suppose a better operation. Also that the precision raises it to the 5%, but I see this of little importance, since the range is still + -50 ppm. Since it is newer, do you recommend buying the C model over the B model as better?
    Greetings again

    • I had made a mistake in linking to the MH-Z19B datasheet and had repeated the one for the MH-Z19C. It is already corrected. Thank you very much for the warning.

      It seems, as you say, that the sensor is already on sale. The link you have put does not look good (in the photograph it is not like the official manufacturer). You can find here one that seems to be the official one:

      Now that it's available, I'll calmly study the differences and expand the table with the new data. By boat soon, it seems like a step backwards: lower precision (5% vs. 3% of the old one) and lower operating voltage range (4.9 to 5.1 V vs. 4.5 to 5.5 V of the old one).

      What does seem to improve, as you have pointed out, is in the preheating time (1 minute, compared to 3 minutes in the old one) and the consumption somewhat lower. This can be interesting for users who want to use it in a portable or portable format with batteries.

      I still do not recommend its purchase, until I know if it will work for the 100% with ESPEasy or it will be necessary to adapt the code (as it had to be done when the previous ones appeared, because, although there are no major differences, there are some, and adjustments must be made)
      I know, almost rebound, from a person who is testing the HM-Z19C with ESPEasy and, for the moment, it seems that it is working correctly.

      If someone is encouraged to try it, tell us how it went.

  2. Hello Mariete,

    Thanks for all this information. I'll tell you how I am doing because in my life I have soldered nothing, but for this project I have encouraged myself.

    I have a question about the sensor that has come to my house regarding the list you put ... On the label of my sensor it says:

    Model MH-Z19B with range 0 ~ 5000 ppm

    But I don't see this range on any of the sensors you've listed.

    It is specifically this one, the one with the green printed circuit:

    Do I have one of the good ones?
    Thank you!

    • Hello Israel.

      Great, that you have cheered up. You'll tell us ... Be careful, the gadget hooks!

      The sensors I have listed have all been at 5000ppm (can be changed by software anyway). I just changed it, because I just saw that the one that was on is no longer available.

      Knowing if it is authentic or not is very difficult, unless it has a black plate. Last week I got a fake one (with a black plate) and I'm going to take the opportunity to make a video explaining the differences.

  3. Although you already mentioned it in a recent post, there is a difference in the sensor supply voltage that can be critical for the project: less than 4.9V and it will not measure exactly: extract from my post from the general:

    Ps: by the way, the use of a good charger cannot be because the ESP does not get to give 4.5V for the Vin for the 19B? Because consume, consume less than 0.1A

    The third is more relevant and is related to the sensor: it can even screw up the project for many people. The point is that even though I bought the MH-Z19B, after many dizziness with the aliexpress seller, he sent me the MH-Z19C. It is physically different ... but also electronically, as you will see. I tried to assemble the circuit with the tutorial, but instead of soldering I did it with a breadboard that I had also bought for fretting (I am very new to this). The point is that after having connected everything ... it did not work well. The red light was blinking. Values came out, I even connected them to Thingspeak with the partner's tutor. But the values were very unstable: they jumped 50 or more PPM up and down, and the temperature did not add up either. It came out 2 or 3 degrees less than the real thing.

    Total, I thought they had put a fake on me and it bothered me a lot ... until I saw the 19C sheet. It turns out that there is a substantial difference between the 19B and the 19C in electronics: while the 19B works by powering it with 5V + -0.5 (from 4.5 to 5.5V), the 19C needs 5V + -0.1 (from 4, 9 to 5.1V). Also at the end of the sheet he insists that if the voltage is not in that range ... the measurements become UNSTABLE. I looked at what the ESP was giving it on the Vin / GND… et voila, 4.57V. Insufficient.

    I have been documenting myself and it turns out that the ESP is unable to give 5V. The Vin / GND is to supply it with "unregulated" voltage between 5V and 12V. But not to get 5V out of there. In fact, the power supply when connecting with micro USB is a by-product, not a specification. In fact, in any project that needs 5V (motors), you need a specific power supply, you can't pull Vin (from what I've been reading). With the MH-Z19B you are lucky because its input range is wider (although it is so close to the limit that it is almost certain that it is not working for some and it comes out jumping values), but not with the MH-Z19C.

    When buying the breadboard came a feeder. I connected the MH-Z19C to 5V (by the way, it gives 4.92V, a little low) and… BINGO, everything perfect:



    • Hi Jesus,

      what was the response of the MH-Z19C while being undervolted? Did the measurement lamp blink? Did you receive responses on the serial port?

      I have received today a MH-Z19C where the measurement lamp blinks but gives Unknown response: 0 0 0 0 0 0 0 0 0 in espeasy (setup has worked with a MH-Z19B before).


      • Hi Wolfgang.

        I understand that what was happening to Jesus was that his sensor was giving unstable results, with jumps up and down of about 50 ppm.

        In his message, he indicates that the sensor's lamp went on and off, as it should.

        The symptoms of what is happening to you with the unknown response are described in some messages in the main article of the CO2 meter at

        Additional information and some tips for using the MH-Z19C can be found at:


Leave a Comment