Download PDF Parts List View on YouTube Download Code

Today, we are going to check out two sensors that can measure the amount of Carbon Dioxide, or CO₂, in the air you are breathing. Actually, only one of them really measures Carbon Dioxide directly; the other measures “eCO₂” or “Estimated Carbon Dioxide”.

Introduction

As concerns about indoor air quality and climate change grow, the ability to monitor carbon dioxide (CO₂) levels has become increasingly important. Whether you’re building a smart ventilation system, a classroom air monitor, or a personal environmental tracker, understanding how CO₂ behaves—and how to measure it accurately—is essential. This article explores two popular sensors: the ENS160, which estimates equivalent CO₂ (eCO₂), and the SCD41, a true CO₂ sensor. We’ll walk through their differences, how to connect them to a Seeeduino XIAO ESP32-S3, and how to use both in tandem for more robust air quality monitoring.

 

Carbon Dioxide

Carbon dioxide is a naturally occurring gas in Earth’s atmosphere, playing a vital role in the carbon cycle—the process by which carbon moves through the biosphere, atmosphere, oceans, and geosphere. Plants absorb CO₂ during photosynthesis, while animals and humans release it through respiration. Volcanoes, forest fires, and decomposition are natural sources of CO₂, but human activities—especially fossil fuel combustion, deforestation, and industrial processes—have dramatically increased atmospheric CO₂ levels.

Elevated CO₂ indoors can lead to poor air quality, fatigue, headaches, and reduced cognitive performance. Outdoors, excess CO₂ contributes to the greenhouse effect, trapping heat and accelerating climate change.

Indoors, the primary source of pollution is simply people breathing. Combustion devices (such as gas stoves, heaters, and fireplaces), candles/incense, and idling vehicles in attached garages also contribute.

Outdoor air contains ~420 ppm of CO₂. Well-ventilated indoor spaces aim for < 800–1000 ppm. As levels rise:

  • 1000–2000 ppm: drowsiness, reduced concentration.
  • 2000–5000 ppm: headaches, poorer cognition—ventilate now.
  • ≥ 5000 ppm (8-hr exposure limit in many standards): avoid sustained exposure.

Very high concentrations (several percent) can be dangerous.

Measuring CO₂ vs. eCO₂

There are two primary ways to measure carbon dioxide:

  • True CO₂ Sensors (like the SCD41) utilize NDIR (Non-Dispersive Infrared) technology to measure CO₂ concentration directly. These sensors are highly accurate and ideal for scientific or regulatory applications.
  • eCO₂ Sensors (like the ENS160) estimate CO₂ levels based on volatile organic compounds (VOCs) detected in the air. While not a direct measurement, eCO₂ readings are helpful in tracking trends in indoor air quality and are often more affordable and compact.

ENS160 (with AHT21)

The ScioSense ENS160 is a digital MOX air-quality sensor that reports TVOC, eCO₂, and a 5-step AQI. The breakout board we will be using also includes an AHT21 for temperature and humidity sensing, which improves ENS160’s internal compensation.

These modules are very inexpensive and are ideal for use in automated ventilation systems.

ENS160 Pinout

The sensor communicates using I²C, and has the following pinouts:

Note the use of the AD0 connection; it can set the I²C address as follows:

  • OPEN – Address 0x53 (default)
  • GROUNDED – Address 0x52

The sensor should be powered by 3.3 volts on the VIN pin. The 3V3 pin is an OUTPUT, and it only provides a reference voltage – don’t use this to power anything!

The included AHT21 temperature and humidity sensor has an I²C address of 0x38. Bear in mind that its proximity to the ENS160, which uses an internal heating element, causes the temperature to read slightly higher.

ENS160 Hookup

We will conduct our experiments using the ENS160 with an ESP32. I used a Seeeduino XIAO ESP32-S3 board, but any ESP32 (or just about any 3.3-volt microcontroller) will work.

Here is how we will hook everything up:

ENS160 Code

We will be using libraries from both Sparkfun and Adafruit to program our ESP32. This will allow us to retrieve data from both the ENS160 and the AHT21 temperature and humidity sensors.

Here is some code that will display the parameters from all the sensors, output in a convenient table format:

 

 

Load the code onto the XIAO and let it run for at least three minutes to give the ENS160 time to stabilize. You should see the results on your Serial Monitor.

While this is just an eCO₂ sensor, it remains a valuable tool, as it can also measure other parameters, such as air quality and TVOC.

SCD41 CO₂ Sensor

The SCD41 by Sensirion is a compact, high-precision NDIR CO₂ sensor capable of measuring up to 5,000 ppm. It also includes temperature and humidity sensing, making it ideal for indoor air quality applications.

This sensor is more expensive than the ENS160, but it is very accurate. It features a self-calibration function that ensures its accuracy.

SCD41 Pinout

The interface on the SCD41 is nearly identical to the ENS160.  This is another I²C sensor that also includes a low-current 3.3-volt reference output.

Once again, you will want to power this with a regulated 3.3 volts to the VIN pin. The device has internal pull-ups on the SDA and SCL lines.  It has an I²C address of 0x62.

SCD41 Hookup

The hookup is quite similar to the arrangement with the ENS160. Again, I’m using a Seeeduino XIAO ESP32-S3 as the microcontroller.

Try to keep the I²C lines as short as possible, as they are susceptible to electrical noise, which can affect the readings.

SCD41 Code

Sensirion manufactures the SCD41, and they have provided a library for using it with the Arduino IDE. Look for the Sensirion Scd4x Library in your Library Manager.

Once you have the library installed, you can run the folowing code to display the CO₂ levels in your environment:

 

 

Load the code to the XIAO and watch the serial monitor.  Unlike the previous sketch, this only outputs data approximately once every 5 seconds.  As with all these sensors, give the readings time to stabilize.

Here is what the output should look like:

The readings made more sense to me than the ENS160 readings. I also noted that the temperature and humidity were more in line with my ambient conditions.

I also noted that the CO₂ levels steadily increased as I was filming the video associated with this article. This makes perfect sense – I have a tiny workshop, I close the doors when I record videos, and I’m a considerable source of CO₂!

Using Multiple Sensors

Combining the ENS160 and SCD41 in a single circuit offers several advantages:

  • Redundancy: eCO₂ readings can be cross-validated with true CO₂ data.
  • Trend Analysis: VOC spikes (from cooking, cleaning, etc.) can be tracked alongside CO₂ levels.
  • Environmental Context: Temperature and humidity from both sensors improve compensation and calibration.
  • Smart Control: More data enables smarter decisions for ventilation, alerts, or automation.

The sensors work well together as they have different I²C addresses.

Multiple Sensor Hookup

As both devices have essentially identical I2C interfaces, hooking them up to a microcontroller like the Seeeduino XIAO is very easy. Here is a diagram of the connections required:

Try to keep the sensors fairly close together to reduce the length of the wires on the I²C bus. Both sensors have internal pull-up resistors, so no additional ones are required.

Multiple Sensor Code

As you might expect, the code we are using to read data from both sensors is essentially an amalgamation of the two sketches we have already examined.  We’ll format the output to include values from both sensors.

Here is the sketch:

 

 

Load the code onto the XIAO and give both sensors time to warm up. While you will start getting readings instantly, please wait at least three minutes for them to become accurate. In my experience, I found that it took nearly an hour for them to stabilize fully.

The combination of both sensors will provide you with a great deal of insight into the quality of the air you are breathing. By combining the ENS160 and SCD41, you gain a more comprehensive understanding of indoor air quality and the tools to respond intelligently.

Conclusion

CO₂ and eCO₂ sensors, such as the ENS160 and SCD41, enable us to effectively monitor and improve indoor air quality. 

For future projects, consider building a portable CO₂ meter with OLED display for real-time feedback, or an automated ventilation fan that activates above 1,000 ppm using relays and ESP32’s Wi-Fi for IoT integration (e.g., Home Assistant). Expand to data logging on SD cards or cloud services for long-term analysis, or incorporate machine learning to predict air quality trends. With climate awareness growing, these sensors open doors to innovative solutions—start experimenting today!

 

Parts List

Here are some components that you might need to complete the experiments in this article. Please note that some of these links may be affiliate links, and the DroneBot Workshop may receive a commission on your purchases. This does not increase the cost to you and is a method of supporting this ad-free website.

ENS160            Amazon

SCD41             Amazon

 

Resources

Code – All the code used in the article, in a handy ZIP file!

PDF Version – PDF version of the article.

ENS160 – ENS160 datasheet.

SCD41 – SCD41 users manual.

 

Carbon Dioxide Sensors for Microcontrollers
Summary
Carbon Dioxide Sensors for Microcontrollers
Article Name
Carbon Dioxide Sensors for Microcontrollers
Description
Learn the difference between eCO₂ and CO₂ sensors by experimenting with the ENS160 and SCD41. We'll see how to use these sensors together and independently with an ESP32 to read the levels of CO₂ in your environment.
Author
Publisher Name
DroneBot Workshop
Publisher Logo
Tagged on:     

0 Comments
Oldest
Newest
Inline Feedbacks
View all comments