Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

How to Use MH-Z19B: Examples, Pinouts, and Specs

Image of MH-Z19BDesign with MH-Z19B in Cirkit Designer

Introduction

The MH-Z19B is an infrared carbon dioxide sensor module capable of measuring CO2 concentrations in the air. This sensor is widely used in HVAC (Heating, Ventilation, and Air Conditioning) systems, indoor air quality monitoring, and other applications where monitoring of CO2 levels is necessary for environmental control or health standards.

Explore Projects Built with MH-Z19B

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of ESP32-Based Environmental Monitoring System with Solar Charging: A project utilizing MH-Z19B in a practical application
ESP32-Based Environmental Monitoring System with Solar Charging

This circuit features an ESP32 microcontroller interfaced with a BME/BMP280 sensor for environmental monitoring and an MH-Z19B sensor for CO2 measurement, both communicating via I2C (SCL, SDA) and serial (TX, RX) connections respectively. It includes a SIM800L module for GSM communication, connected to the ESP32 via serial (TXD, RXD). Power management is handled by two TP4056 modules for charging 18650 Li-ion batteries via solar panels, with a step-up boost converter to provide consistent voltage to the MH-Z19B, and voltage regulation for the SIM800L. Decoupling capacitors are used to stabilize the power supply to the BME/BMP280 and ESP32.

Open Project in Cirkit Designer
Image of Solar-Powered Environmental Monitoring System with ESP32 and Cellular Connectivity: A project utilizing MH-Z19B in a practical application
Solar-Powered Environmental Monitoring System with ESP32 and Cellular Connectivity

This circuit features an ESP32 microcontroller interfaced with a BME/BMP280 sensor for environmental data and an MH-Z19B sensor for CO2 measurement, both communicating via I2C (SCL, SDA) and serial (TX, RX) connections respectively. It includes a TP4056 module for charging an 18650 Li-ion battery from a solar panel, with a step-up boost converter to provide stable voltage to the MH-Z19B sensor and a voltage regulator for the SIM800L GSM module. The capacitors are likely used for power supply filtering or decoupling.

Open Project in Cirkit Designer

Common Applications and Use Cases

Technical Specifications

Key Technical Details

Pin Configuration and Descriptions

Pin Number Name Description
1 V_in Power supply (4.5 - 5.5 V DC)
2 GND Ground
3 TX UART Transmit (connect to RX of MCU)
4 RX UART Receive (connect to TX of MCU)
5 HD PWM/HD (selectable output)
6 NC Not connected

Usage Instructions

How to Use the Component in a Circuit

  1. Connect the V_in pin to a 5V power supply.
  2. Connect the GND pin to the ground of the power supply.
  3. For UART communication, connect the TX pin of the MH-Z19B to the RX pin of your microcontroller (e.g., Arduino) and the RX pin to the TX pin of the microcontroller.
  4. If using PWM output, connect the HD pin to a digital input on your microcontroller.

Important Considerations and Best Practices

Example Code for Arduino UNO

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
  if (mySerial.available() > 0) {
    int high = mySerial.read();
    int low = mySerial.read();
    if (high == 0xFF) {
      int ppm = (256 * high) + low;
      Serial.print("CO2 Concentration: ");
      Serial.print(ppm);
      Serial.println("ppm");
    }
  }
}

Note: This example assumes that the MH-Z19B is connected via UART using pins 10 and 11 on the Arduino UNO for software serial communication. Adjust the pin numbers as needed for your specific setup.

Troubleshooting and FAQs

Common Issues Users Might Face

Solutions and Tips for Troubleshooting

FAQs

Q: How often should the sensor be calibrated? A: The manufacturer recommends calibrating the sensor every six months or whenever there is a significant change in the operating environment.

Q: Can the sensor measure CO2 levels outdoors? A: While the MH-Z19B can measure CO2 levels outdoors, it is designed primarily for indoor use and may not perform optimally in outdoor conditions.

Q: Is the sensor resistant to humidity? A: The sensor can operate in 0 - 95% RH non-condensing environments. High humidity levels may affect the sensor's performance over time.

For further assistance, consult the manufacturer's datasheet and user manual.