Hardware · Sensor · CO₂

The MH-Z19.

Measures
True CO₂ (carbon dioxide)
Interface
UART (serial), and PWM
Open Agriculture Technology take
The cheap way to real CO₂

The MH-Z19 is a low-cost NDIR CO₂ sensor, which means it measures carbon dioxide directly with infrared light rather than guessing at it like the cheap “eCO₂” parts. For a sealed greenhouse, a grow room, or a mushroom house, it is the budget route to a real CO₂ reading you can act on.

An infrared NDIR CO2 sensor
Image: dfrobot.com (a representative NDIR CO₂ sensor)

What it is.

The MH-Z19 (sold as the MH-Z19B and MH-Z19C) is a Winsen sensor that shines infrared light through a small tube of air and measures how much the CO₂ absorbs, the proven NDIR method. That is real CO₂ measurement, not the volatile-compound estimate the eCO₂ sensors make. It reports parts-per-million over a serial (UART) connection, and also as a PWM signal. It measures CO₂ only, with no temperature or humidity.

MH-Z19 or SCD40.

Both measure real CO₂; the choice is about format and budget. The MH-Z19 is cheaper and a known quantity, but it is a larger tube-style part, runs on 5 volts, talks over UART, and measures CO₂ only. The SCD40 is smaller, speaks the tidy I²C bus, throws in temperature and humidity, and is the more modern design, at a higher price. Pick the MH-Z19 to save money or when you already have a free serial port; pick the SCD40 for a compact I²C build that also wants climate.

Key facts.

Wiring and calibration.

Power it from 5 V (it needs the current to run its infrared lamp), and connect its TX and RX serial lines to a UART on your microcontroller (the data lines are 3.3 V-friendly). In ESPHome it has a dedicated MH-Z19 component on a UART bus. The same calibration caution as any NDIR sensor applies: it self-calibrates with an automatic baseline that assumes the room regularly returns to fresh-air CO₂. In a room you keep enriched, turn that auto-calibration off and calibrate manually, or its zero will drift.

Where it fits, and where it doesn’t.

Where it fits

  • Real CO₂ on a budget for enrichment or ventilation.
  • Builds with a free serial (UART) port and 5 V power.
  • Greenhouses, grow rooms, and mushroom houses.
  • Reading with an ESP32 and ESPHome.

Where it doesn’t

  • Compact I²C builds; the SCD40 is smaller and adds climate.
  • Temperature or humidity; it reads CO₂ only.
  • An enriched room with auto-calibration left on.
  • Life-safety alarms; use a certified monitor.

Resources & where to buy.

ESPHome: MH-Z19 Winsen MH-Z19B Where to buy CO₂ & air overview

Frequently asked questions.

Does the MH-Z19 measure real CO2?

Yes. It uses the non-dispersive infrared (NDIR) method to measure carbon dioxide directly, so its parts-per-million reading is real, unlike cheap eCO2 sensors that only estimate CO2 from other gases. It is the budget route to a true CO2 reading.

What is the difference between the MH-Z19 and the SCD40?

Both measure real CO2. The MH-Z19 is cheaper, larger, runs on 5 volts, talks over UART, and reads CO2 only. The SCD40 is smaller, uses I2C, also reports temperature and humidity, and is more modern, at a higher price. Choose by budget and build format.

How do I connect an MH-Z19 to an ESP32?

Power it from 5 volts and wire its TX and RX serial lines to a UART on the ESP32. In ESPHome, configure a UART bus and the MH-Z19 component, and the CO2 reading appears in Home Assistant. The data lines work at 3.3 volts.

Why does my MH-Z19 reading drift over time?

Its automatic baseline calibration assumes the room regularly reaches fresh-air CO2 levels. In a room kept enriched above outdoor CO2, that assumption is wrong and the zero drifts. Turn the automatic baseline off and calibrate manually for enriched spaces.