Simple LED Bar Graph CO2 Sensor




Introduction: Simple LED Bar Graph CO2 Sensor

About: I am a physicist, part time maker and electronics enthusiast. My projects revolve mainly around daily-use items, toys and decoration with a focus on unconventional mechanisms and high standard of design.

There is a special interest in CO2 sensors lately because they are also useful to help prevent the spreading of the Coronavirus. Since the virus is mainly transmitted via aerosols it is important to assure good ventilation indoors. Since CO2 is exhaled together with aerosols (VOC = volatile organic compounds) the concentration of both are correlated and a CO2 sensor can be used to indicate when you should open a window to let fresh air into the room. Apart from that of course also a too high CO2 concentration is in itself harmful and can cause fatigue or headaches.

There have been a number of DIY CO2 projects perhaps the most notable one is that of Stephan Schulz who together with his daughter made a CO2 sensor pendant for her to wear at school. Building a CO2 sensor is a great project for students as they can learn about gas sensing, electronics, programming while making a device that is really useful for their everyday life in school.

In my workplace, we also use CO2 sensors to monitor the air quality to help mitigate the spreading of the Coronavirus. TOPTICA, the company I work at, even designed their own CO2 sensor shield for the Arduino UNO and the bare PCB was given away for free to everybody interested in building their own sensor. This inspired me to build my own variation of a CO2 sensor using the SCD30 sensor that I generously received for free from my employer. The SCD30 is relatively expansive compared to some other gas sensors because it is a non-dispersive infrared (NDIR) sensor. It measures the absorption of specific wavelengths of light characteristic for the gas molecule. This has the advantage that it only measures CO2 in contrast to chemical sensors which are also sensitive to other gases.

The aim of this project was to use only a minimal amount of components while still having advanced functionality. My CO2 sensor offers the following features

  • simple display of CO2 concentration by LED bar graph
  • readout and data logging of CO2 concentration, relative humidity, and temperature via Sensirion smartphone app


  • SCD30 CO2 and RH/T sensor (e.g.
  • ESP32 NodeMCU (e.g.
  • LED 10 segment bargraph (blue,green,yellow,red) (e.g.
  • 10x 0805 resistor between 300Ohm to 1kOhm (e.g.
  • Custom PCB (see below)
  • 3D printed enclosure (see below)
  • 4x M2 x 20 mm bolts

Step 1: Custom PCB

All components are mounted on a custom PCB that was designed in KiCAD. The schematic is depicted above. The SCD30 sensor communicates with the ESP32 MCU via the I2C interface. Each segment of the LED bar graph is connected to an IO pin of the MCU with a series resistor that limits the current and therefore brightness of the LEDs. I originally planned to use 150 Ohm for all segments but then increased the value because the segments were very bright. In addition, I used different resistors for the differently colored LEDs since they have different forward voltages and also appear very different in brightness according to photopic vision. In the end, I used the following resistor values

  • blue: 680 Ohm
  • green: 1k Ohm
  • yellow/red: 330 Ohm

The green segments are still very bright though so you may wanna test which resistor values to use on a breadboard before. One could also use PWM dimming to turn down the brightness to the desired value.

The PCB files can be found on my GitHub. I ordered 3 pieces for just 12 EUR from

Step 2: Assembling the PCB

Except for the resistors all components are thru-hole mounted. The LED bar graph should be placed on the front so that the model designation on the side faces downwards. The ESP32 and SCD30 are mounted on the back. For the SCD30 it is recommended to leave a small distance between sensor and PCB which can be achieved by inserting a 5 cent euro coin between sensor and PCB as spacer before soldering. The SMD footprints for the resistors are hand-solder friendly. As you can see in the picture I had to use some botch wires because of a design mistake but this has been corrected in the PCB files on my GitHub.

Step 3: Adding the Enclosure

I designed an enclosure for my 3D printer using Fusion360 and printed it using green PETG. The enclosure consists of two halves that are held together by four M2 x 20 mm bolts.

The STL files for the enclosure can be found on my GitHub.

Step 4: Uploading the Code

The code that runs on the ESP can be downloaded from my GitHub. It requires the Sensirion BLE gadget library and the Seeed Studio SCD30 library.

The LED bar graph indicates the CO2 concentration based on the following table

  • 400 - 1000 ppm: blue/green LEDs (segments 1-5)
  • 1000 - 1600 ppm: yellow LEDs (segments 6-8)
  • >1600 ppm: red LEDs (segments 9-10)

When all 10 segments are on the LEDs also start blinking.

If you want to use the data logging functionality you also have to download the Sensirion MyAmbience app from the Google Play or Apple app store. When you are close to the sensor you can connect to it in the app via Bluetooth. In the app, you can display the current CO2 concentration, RH, and temperature values. You can also specify a data logging interval, data is logged on the device and can then be downloaded to your smartphone.

The code also includes the auto-calibration feature of the SCD30 but in order for it to work the sensor needs 7 days of continuous readings with at least 1 hour a day of fresh air.

STEM Contest

Participated in the
STEM Contest

Be the First to Share


    • First Time Author Contest

      First Time Author Contest
    • Backyard Contest

      Backyard Contest
    • Eggs Challenge

      Eggs Challenge