Arduino UNO R4 - SCD40 CO2 Sensor
In this guide, we will learn how to use the SCD40 CO2 sensor with the Arduino UNO R4 WiFi or Minima to find out how much carbon dioxide is in the air around your desk. A room full of people slowly fills with CO2, and high levels make us tired. With this project you can see the number and know when to open a window. In detail, we will learn:
- How the SCD40 measures real CO2 and what its four pins do.
- How to connect the SCD40 module to the I2C pins of the Arduino UNO R4.
- How to write a program for the Arduino UNO R4 that reads CO2 in ppm and labels the air as Good, Moderate or Poor.
- How to read the extra temperature and humidity values from the same sensor.

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables STEM V4 IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables STEM V4B IoT Starter Kit (Arduino included) | |
| 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 is a small sensor from Sensirion (part of the SCD4x family). Many cheap "air quality" sensors only guess the CO2 level from other gases. For example, the MQ2 in our Arduino UNO R4 - Gas Sensor tutorial reacts to many gases at once. The SCD40 measures CO2 itself, using a method called photoacoustic NDIR: a tiny infrared light pulses inside the sensor, CO2 absorbs some of that light and makes a very small pressure "sound", and a microphone picks it up. More CO2 gives a stronger sound.
| SCD40 | |
|---|---|
| Supply voltage | 2.4V to 5.5V |
| Interface | I2C, address 0x62 |
| Output range | 0 to 40,000 ppm |
| Accuracy | ±(50 ppm + 5% of reading), from 400 to 2,000 ppm |
| New reading | 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 sensor has Automatic Self-Calibration (ASC), and it is on by default. It expects to see fresh, outdoor-level air (about 400 ppm) at least once a week, best for an hour or more. A room that is aired out from time to time is enough. Also, the first few readings after power-on can be a bit off while the sensor warms up.
What the numbers mean:
| CO2 (ppm) | Air quality |
|---|---|
| About 400 | Fresh outdoor air |
| 400 - 1000 | Good indoor air |
| 1000 - 2000 | Stuffy, open a window |
| Above 2000 | Poor, may cause headache or drowsiness |

The SCD40 module has four pins:
- VCC pin (may be labeled VIN): connect to 5V or 3.3V of the Arduino UNO R4.
- GND pin: connect to GND (0V).
- SCL pin: I2C clock, connect to the SCL pin of the Arduino UNO R4.
- SDA pin: I2C data, connect to the SDA pin of the Arduino UNO R4.
Most SCD40 modules already have I2C pull-up resistors on board, so there's no need to add them yourself.
Wiring Diagram
The Arduino UNO R4 has its main I2C bus on A4 (SDA) and A5 (SCL). The same two signals also come out on the SDA and SCL header pins near the AREF pin, so you can use either place.

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
| SCD40 Module | Arduino UNO R4 |
|---|---|
| VCC | 5V |
| GND | GND |
| SCL | SCL (A5) |
| SDA | SDA (A4) |
※ NOTE THAT:
The Qwiic connector on the Arduino UNO R4 WiFi is a different I2C bus (Wire1) and works at 3.3V. This guide uses the normal pins and Wire, so it works the same on the WiFi and the Minima.
How To Program For SCD40 Sensor
- Include the libraries.
- Create an SCD40 sensor object.
- Start the I2C bus and connect the sensor at address 0x62:
- Start the periodic measurement:
- Check if a new reading is ready, then read it:
Every library function returns an error code. When it is not 0, errorToString() turns it into readable text, and the code prints it to the Serial Monitor.
Arduino UNO R4 Code - SCD40 CO2
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Click on the Libraries icon on the left side of the Arduino IDE.
- Type "SCD4x" in the search box and find the Sensirion I2C SCD4x library by Sensirion.
- Click the Install button. When the IDE asks to install the dependency Sensirion Core, click Install All.
- Search for Sensirion I2C SCD4x created by Sensirion and click the Install button.
- Copy the code above and paste it into the Arduino IDE.
- Click the Upload button to upload the code to the Arduino UNO R4.
- Open the Serial Monitor and wait about 5 seconds for the first value.
- Breathe slowly toward the sensor for a few seconds and watch the number rise, then fall again.
A new line appears about every 5 seconds, because that is how often the SCD40 makes a new measurement.
※ NOTE THAT:
If you only see error messages, check the SDA and SCL wires first. They are easy to swap by mistake.
Reading Temperature and Humidity from the SCD40
The SCD40 also has its own temperature and humidity sensor inside. The chip uses it to correct the CO2 value, and you can read it too. In fact, readMeasurement() already returns all three values in one call. The first sketch simply did not print them. The code below prints CO2, temperature and humidity on one line.
Detailed Instructions
- Keep the same wiring.
- Copy the code above and paste it into the Arduino IDE.
- Click the Upload button to upload the code to the Arduino UNO R4.
- Open the Serial Monitor.
The temperature can read a little higher than the room, because the sensor and the board warm up slightly while they work.