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.

Connecting a particulate matter sensor to your PC or Mac

I’ve written before about what particulate matter sensors are and how they work. Many of these sensors come with a tiny 8-pin connector. With some luck, you even find an English data sheet. But you might just end up with a Chinese one. It might look like this:


Luckily, most signals have english names:


Ok, that’s all we need to know to connect this thing to a PC. You can see that the supply voltage is 5V and the I/O voltage is 3.3V. That’s perfect for most use cases. You also see that there is some kind of serial interface RX/TX and a SET and RESET input.

What do you need? The only thing you need is a USB to Serial (TTL) adapter. The come in different variants and might look like this:

usbser1 usbser2


Before buying check 2 things: The adapter should offer 5V AND 3.3V power outputs (for this project we only need 5V, but you might need the 3.3V for other projects) and have a DTR output (we will use this to turn the sensor on and off).

Now connect the sensor to the adapter as follows:

 VCC pin 1  5V
 GND pin 2 GND
 TX pin 4  RX
 RESET  pin 6  DTR

Note that the pin numbers are for the specific sensor shown above. Check the data sheet of your sensor, the pins might be different!

Why isn’t RX not connected? All the dust sensors I’ve seen do not use this signal at all. If it isn’t used, there is no need to connect it (but you can do if you like).

Finally this will look like this:


You can now connect this to you PC or Mac and read data from the sensor. We will show in another article how to do this.

Measuring air quality

When people think about comfort in their apartment, most people think first about temperature. But another important factor is air quality. I don’t have to tell you that smells from cooking aren’t always the best. There are much more particles in the air that impact the quality. These particles are generally named “Particulate matter”. The EPA defines PM as follows:

“Particulate matter, or PM, is the term for particles found in the air, including dust, dirt, soot, smoke, and liquid droplets. Particles can be suspended in the air for long periods of time. Some particles are large or dark enough to be seen as soot or smoke. Others are so small that individually they can only be detected with an electron microscope. ”

Today, most measurements you find are PM2.5 measurements. This measures particles smaller than 2.5µm. Roughly one out of every three people in the United States is at a higher risk of experiencing PM2.5 related health effects.

Do you know the PM2.5 values in your living environment? Most likely not, but it is relatively easy and cheap to do do these measurements today. While calibrated sensors is still very expensive, for home-use uncalibrated sensors do a good job to give you a rough idea about possible problems.

These sensors work as follows:


A light sends light into an air flow. Small particles will reflect the light. A receiver than measures these reflections. Seems very simple – right? It really is. The cheapest sensors are available for less than $20 on Chinese shopping sites. They use LEDs as a light source. Laser-based devices are a bit more expensive ($50 and up), but they can detect smaller particles.

Let’s have a look about a laser-based sensor like this:


The fan creates an continuos air flow through the device. Looking into the device you see the air channel and the detector.


The detector looks like this:

What else is inside?

This is the simple PCB. It is based on a small microcontroller and some external components.

The good thing about these (more expensive) sensors is that they already do the hard work for you. They have a serial output that already sends the PM1.0, PM2.5 and PM10 values.

You can use a simple USB-to-Serial converter and read the data directly from your PC. How to connect this sensor to the adapter is shown here.