Monitor CO2 levels in your house

When breathing, humans and animals increase the concentration if CO2 in the exhaled air. This is a normal biological process. In the outside this is not a problem as plants consume the additional CO2 (I’m not talking about the long-term effects of increasing CO2 concentration by burning fossil fuels).
However in closed living rooms without enough ventilation, CO2 levels can increase quite a lot. Especially modern buildings without a well-designed ventilation system can be a bit problematic. Therefore, monitoring CO2 levels in living rooms is a good idea as it gives you a good indication when you should increase the ventilation (e.g. by opening the windows for some time).

While outside CO2 levels are normally between 250 and 350ppm (parts per million), inside levels can be up to multiple 1000 ppm. You can see here that CO2 levels above 1000ppm can lead to drowsiness, poor concentration, loss of attention or increased heart rate.

An easy method to monitor CO2 levels are nondispersive infrared sensors. If you want to use a PC or Raspberry Pi a sensor with a serial interface is a good choice. The MH-Z19 features a serial interface and 3.3V power supply and IO levels. This makes is easy to connect it directly to a Raspberry Pi or to a PC (using an USB/serial converter).

Looking at the sensor from the bottom, you will see the following pins:


The pins have a 2.54mm (0.1″) pitch, that makes it easy to solder a simple one-row pin header like this:


After this, you can connect the sensor with jumper cables:


Connecting to a Raspberry Pi

You can connect the sensor directly to the 40-pin GPIO interface:

Function Pin MH-Z19 Pin RPI
VCC 6 1
GND 7 6
RX 2 8
TX 3 10

Connecting to a PC

To connect the sensor to a PC or Mac, you need an USBserial converter like this:


These converters have different pinout. Check the board that you’re using and connect VCC to 3.3V, TX to RX, RX to TX and GND to GND.


While it is quite easy to read out data from this sensor with your own software, you don’t have to be a programmer to use it.
The easiest way to use it is Home Assistant. We’ve created a small module for this sensor that you only have to activate in the configuration:

sensor 3:
  platform: mhz19
  serial_device: /dev/serial0

If you want to write your own program, you can use our pmsensor library that now also supports this CO2 sensor.

12 thoughts on “Monitor CO2 levels in your house”

    1. Unfortunately I can’t say this as I don’t have a calibrated device to compare. However, approximately 400ppm CO2 outside levels seems to be quite accurate.

  1. i want to monitor CO2 levels on homeassistant, all i need is type the characters below in configration.yaml ?
    sensor 3:
    platform: mhz19
    serial_device: /dev/serial0
    but it does not works~
    is there any help ? ~thanks~

  2. I just realised that your wiring is wrong. The input voltage should be 5V according to the datasheet of the MH-Z19 (section 7.2)
    Therefore it should be connected to pin 2 or 4 on the Raspberry Pi
    I got way too high readings on 3.3V which makes sense as the LED inside is less bright at lower voltage and the sensor thinks all the light got absorbed by CO2.

  3. I have installed on my raspberry 3 and enabled the sensor as described above, however I am getting this error:

    Could not open serial connection to /dev/serial0 ([Errno 2] could not open port /dev/serial0: [Errno 2] No such file or directory: ‘/dev/serial0’)
    23:50 components/sensor/ (ERROR)

    Any idea how to fix this?

  4. I tried to set this up and I cannot get it to work. Not sure why and could not find anyone else with this issue. Where would I go to get help?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.