Arduino Nano - SCD40 CO2 Sensor
This tutorial instructs you how to use Arduino Nano to read the carbon dioxide (CO2) level of a room from the SCD40 sensor. In detail, we will learn:
- How to connect Arduino Nano to the SCD40 CO2 sensor module through I2C
- How to program Arduino Nano to read the CO2 concentration in ppm and judge whether the air is fresh or stuffy
- How to read the temperature and humidity values that the same module also provides

We suggest:
- Utilizing the SCD40 (this tutorial) when you need the real CO2 value, for example to know when to open a window in a classroom or office.
- Utilizing an MQ2 gas sensor if you only want to detect smoke or flammable gas leaks.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of SCD40 CO2 Sensor
The SCD40 CO2 Sensor Pinout
The SCD40 from Sensirion measures true CO2 with photoacoustic NDIR sensing. Inside its small chamber, an infrared light flashes on and off. CO2 absorbs part of that light and creates a tiny pressure "sound", which a built-in microphone picks up: the more CO2, the stronger the signal. Because it measures the gas itself, its value is much more reliable than the "eCO2" estimate of sensors like the MQ135 or CCS811.
| SCD40 | |
|---|---|
| Operating Voltage | 2.4V to 5.5V |
| Interface | I2C (address 0x62) |
| CO2 Output Range | 0 to 40,000 ppm |
| CO2 Accuracy | ±(50 ppm + 5% of reading), from 400 to 2,000 ppm |
| Reading Rate | one value every 5 seconds (every 30 seconds in low-power mode) |
| Temperature Accuracy | ±0.8°C (15°C to 35°C) |
| Humidity Accuracy | ±6 %RH (15°C to 35°C, 20 to 65 %RH) |
| Average Current | about 15 mA at 3.3V |

The SCD40 module has four pins:
- VCC pin: must be connected to VCC (5V or 3.3V)
- GND pin: must be connected to GND (0V)
- SDA pin: I2C data line, must be connected to the SDA pin of Arduino Nano (A4)
- SCL pin: I2C clock line, must be connected to the SCL pin of Arduino Nano (A5)
Most SCD40 breakout boards already have I2C pull-up resistors, so no extra resistor is needed.
※ NOTE THAT:
The arrangement of pins on a module may differ from one manufacturer to another. Some boards label VCC as VIN. It is essential to always refer to the labels printed on the module when using it. Take a close look!
How To Read the CO2 Value
CO2 is measured in ppm (parts per million). The table below is a simple guide for indoor air:
| CO2 Level | Meaning |
|---|---|
| About 400 ppm | Fresh outdoor air |
| 400 to 1000 ppm | Good indoor air |
| 1000 to 2000 ppm | Stuffy air, open a window |
| Above 2000 ppm | Poor air, headache or drowsiness is possible |
The SCD40 has Automatic Self-Calibration (ASC), which is ON by default. It assumes that the sensor sees fresh, outdoor-level air (about 400 ppm) at least once a week, ideally for an hour or more. So, air the room from time to time. Also, the first few readings after power-up may be less accurate while the sensor warms up.
Wiring Diagram
The SCD40 module talks to Arduino Nano over I2C, so it uses the A4 (SDA) and A5 (SCL) pins of the Arduino Nano.

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
| SCD40 Module | Arduino Nano |
|---|---|
| VCC | 5V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
How To Program For SCD40 CO2 Sensor
- The first step is to include the libraries:
- Declare an SCD4x object:
- In setup(), start the I2C bus and attach the sensor at address 0x62:
- Make a clean start, then begin periodic measurement:
- In loop(), check if a new value is ready, then read it:
- Every function returns an error code. When it is not 0, it can be turned into text:
Arduino Nano Code for SCD40 CO2 Sensor
The code below prints the CO2 value in ppm, followed by a simple word (Good, Moderate or Poor) based on the guide table above.
Detailed Instructions
- If this is the first time you use Arduino Nano, see how to setup environment for Arduino Nano on Arduino IDE.
- Wire the components as shown in the diagram.
- Connect the Arduino Nano board to your computer using a USB cable.
- Open Arduino IDE on your computer, then select the Arduino Nano board and its COM port.
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search "SCD4x", then find the Sensirion I2C SCD4x library by Sensirion.
- Click the Install button to install the library.
- Search for Sensirion I2C SCD4x created by Sensirion and click the Install button.
- You will be asked to install the dependency. Click the Install All button to install the Sensirion Core library.
- Copy the code above and paste it into Arduino IDE.
- Click the Upload button to upload the code to Arduino Nano.
- Open the Serial Monitor and set the baud rate to 9600.
- Breathe gently toward the sensor from a short distance and watch the value go up, then let it settle.
A new line appears about every 5 seconds, because that is how often the SCD40 makes a new measurement.
Reading Temperature and Humidity from the SCD40
The SCD40 also has its own temperature and humidity sensor. The sensor uses it inside to correct the CO2 value, but you can read it too. In fact, readMeasurement() already returns all three values at once, so the code only needs to print them.
Arduino Nano Code for SCD40 - CO2, Temperature and Humidity
Detailed Instructions
- Keep the same wiring.
- Copy the code above and open it in Arduino IDE.
- Click the Upload button to upload the code to Arduino Nano.
- Open the Serial Monitor.
※ NOTE THAT:
The temperature value is mainly there to help the CO2 measurement, so it may differ a little from a room thermometer. For a dedicated temperature and humidity reading, a sensor like the DHT22 is a better choice.
Additional Knowledge
Let's compare the SCD40 and the MQ2 gas sensor.
| SCD40 | MQ2 | |
|---|---|---|
| What it measures | real CO2 in ppm | general level of LPG, smoke, alcohol, methane, etc. |
| Sensing method | photoacoustic NDIR | heated metal-oxide element |
| Output | digital (I2C) | analog voltage and digital threshold |
| Extra data | temperature and humidity | none |
| Warm-up | a few readings | 5-10 minutes (24-48 hours if stored long) |
It is evident that the SCD40 is the right choice for indoor air quality and ventilation, while the MQ2 is meant for gas leak and smoke alarms.