Integrated Systems and Photonics


Project CO2-Sensor

Winter is coming and therefore adequate ventilation is particularly important in Corona times. The CO2 value in the air is an indication of when the windows should be opened. In this project you can see how an MH-Z19B CO2 sensor and a DHT22 temperature and humidity sensor are connected to a microprocessor and read out. The programming is done in the Arduino IDE.






Left: Photo of the complete setup. Right: Screenshot from InfluxDB. The instantaneous values are given on the displays. In the time sequence below, the CO2 value initially rises and then falls quickly after opening the window.

These parts are required:


  • 1x MH-Z19B
  • 1x DHT22


  • 1x Heltec WiFi LoRa 32 (V2) (This selected for the integrated OLED display, WiFi and LoRa connection. Other microprocessors are also possible and cheaper.)
  • 1x Micro USB cable for programming and power
  • Power bank for mobile use

Other things:

  • 1x Breadboard
  • 1x LED “traffic” light (series resistors already included)
  • 1x LED yellow (may be used instead of LED traffic light)
  • 1x LED red (may be used instead of LED traffic light)
  • 2x Resistor 220 Ohm (for LED red and yellow)
  • 1x Resistor 10 kOhm (pull-up for DHT22, 4.7 kOhm - 10 kOhm works)
  • Wire for the connections


The project is carried out in several stages. There is a video on YouTube for each step (im German):

  1. Introduction to the project
  2. Heltec board with LED traffic light: Introduction to the Heltec board and the control of pins.
    File: Heltec_Ampel_v1.0.0.ino
  3. CO2sensor connection  and output on serial monitor
    File: CO2_Serial_v1.0.0.ino
  4. CO2 “traffic” light: Control of the LED traffic light depending on the CO2 values
    File: CO2_Ampel_v1.0.0.ino
  5. CO2 traffic light and display output: connection of the OLED display
    File: CO2_Ampel_Display_v1.0.0.ino
  6. Connect sensor for temperature and humidity
    File: Temp_Hum_v1.0.0.ino
  7. Read out all sensor values and transfer them to the InfluxDB database via WiFi
    File: CO2_Temp_Hum_WiFi_v1.0.0_blanko.ino
  8. Comparison of the built measurement device with two commercial devices


Note on threshold values:
Automatic ventilation systems are designed in such a way that an average of 1000 ppm CO2 is maintained over the duration of a teaching unit [1]. Therefore, we choose 1000 ppm as the switching value to the yellow light and 1200 ppm as the switching value to the red light.

[1] Stellungnahme der Kommission Innenraumlufthygiene am Umweltbundesamt, „Das Risiko einer Übertragung von SARS-CoV-2 in Innenräumen lässt sich durch geeignete Lüftungsmaßnahmen reduzieren“, 12. August 2020.


Note on calibration of the MH-Z19B:
In continuous operation, the sensor adjusts itself automatically to the lowest value measured within 24 hours. This is assumed to be outside air. Therefore, the sensor has to be at an open window once a day.

Data sheet: