A lightweight library for handling Sensirion SCD40/SCD41/SCD43 (SCD4x) CO₂ sensors on ESP32 using the I2C interface.
It provides easy access to CO₂ concentration, temperature, and humidity measurements.
- Initialization and configuration of the SCD4x sensor
- Reading:
- CO₂ concentration (ppm)
- Temperature (°C)
- Relative humidity (%)
- Automatic handling of measurement timing
- Support for continuous measurement mode
- Automatic self calibration by default
- ESP-IDF
- SCD40/SCD41/SCD43 sensor
Initializing the library:
#include "scd4x.h"
#define SDA_PIN GPIO_NUM_6
#define SCL_PIN GPIO_NUM_7
...
scd4x_init(SDA_PIN, SCL_PIN);Reading the measurements (only when the library is initialized):
#include "esp_log.h"
...
uint16_t co2;
int16_t temperature_x100;
uint16_t humidity_x100;
scd4x_get_co2_ppm(&co2);
scd4x_get_temperature_celsius_x100(&temperature_x100);
scd4x_get_humidity_percent_x100(&humidity_x100);
ESP_LOGI("SCD4x example", "CO2: %u ppm | Temperature: %.2f °C | Humidity: %.2f %%", co2, temperature_x100 / 100.0f, humidity_x100 / 100.0f);- temperature offset
- sensor altitude
- ambient pressure
- calibration related features
- low power measurements
- factory reset