ESP32 MH-Z19 NDIR CO₂ Sensor

MH-Z19 NDIR CO₂ Sensor image

MH-Z19

Protocol: UART,PWM

Overview

The MH-Z19 is a high-accuracy CO₂ sensor using NDIR technology, suitable for air quality monitoring. It supports UART and PWM communication, with a detection range up to 2000 ppm (optionally 5000 ppm). Its compact design and long lifespan make it ideal for HVAC and indoor air quality systems.

About MH-Z19 NDIR CO₂ Sensor

The MH-Z19 is a Non-Dispersive Infrared (NDIR) CO₂ sensor designed for precise carbon dioxide (CO₂) measurement. With high sensitivity, selectivity, and a long lifespan, it is ideal for HVAC systems, indoor air quality monitoring, and industrial applications.

Key Features

  • NDIR Technology – Ensures accurate CO₂ detection with minimal interference.
  • Flexible Data Output – Supports both UART and PWM communication.
  • Long Lifespan & High Stability – Reliable for continuous air quality monitoring.
  • Ideal for Smart Air Quality Systems – Commonly used in HVAC, greenhouses, and CO₂ monitoring devices.

For VOC and multi-gas detection, consider the CCS811, which detects TVOCs and eCO₂. 🚀

The MH-Z19 offers a detection range of 0 to 2000 ppm (extendable to 5000 ppm upon request) with an accuracy of ±50 ppm + 5% of the reading. It also includes temperature compensation for reliable readings under varying environmental conditions. Compact in design, it is easy to integrate into a variety of projects.

Where to Buy

MH-Z19 NDIR CO₂ Sensor

Starting from

25$ per piece

Amazon com
Amazon.com Ships worldwide
View Price
Amazon de
Amazon.de Ships to EU
View Price
Aliexpress
AliExpress Best value
View Price

Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.

Technical Specifications

Operating Voltage 3.6V to 5.5V
Current Consumption Max 18 mA
Detection Range 0 to 2000 ppm (optional 5000 ppm)
Accuracy ±50 ppm + 5% of reading
Response Time <60 seconds
Operating Temperature 0°C to 50°C
Communication Protocols UART, PWM
Dimensions 33mm × 20mm × 9mm

Pinout Configuration

The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32.

The MH-Z19 pinout is as follows:

  • Pin 1 (Vout): 3.3V output (max 10mA).
  • Pin 2 (RXD): UART receive input (3.3V logic).
  • Pin 3 (TXD): UART transmit output (3.3V logic).
  • Pin 4 (SR): Factory reserved.
  • Pin 5 (HD): Zero calibration input (pull low for >7s).
  • Pin 6 (Vin): Power supply input (3.6V to 5.5V).
  • Pin 7 (GND): Ground.
  • Pin 8 (AOT): Factory reserved.
  • Pin 9 (PWM): PWM output for CO₂ concentration.

Wiring with ESP32

To interface the MH-Z19 with a microcontroller like an Arduino or ESP32, connect the sensor's Vin to a 5V power supply, GND to ground, TXD to the microcontroller's RX pin, and RXD to the microcontroller's TX pin. Ensure the microcontroller's logic levels are compatible with the sensor's 3.3V UART interface. Use a level shifter if necessary for voltage matching.

Troubleshooting Guide

Common Issues

❌ Sensor Initialization Failure

⚠️ Consistent High CO2 Readings

🌡️ Inaccurate CO2 Readings

🔌 Serial Communication Errors

Debugging Tips

🔍 Serial Monitor

⚡ Voltage Checks

Code Examples

Arduino Example

C++
🔧

ESP-IDF Example

C++
🏠

ESPHome Example

YAML
🛠️

PlatformIO Example

C++
🐍

MicroPython Example

Python

Conclusion

The ESP32 MH-Z19 NDIR CO₂ Sensor is a powerful Air Quality sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.

For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.

Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.