Arduino
Using the STCC4 CO2, temperature and humidity sensor with Arduino involves wiring up the sensor to your Arduino-compatible microcontroller, installing the Adafruit_STCC4 library and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the STCC4 VIN.
Here is an Adafruit Metro wired up to the STCC4 using the STEMMA QT connector:
-
Board 5V to breakout STEMMA VIN (red wire)
-
Board GND to breakout STEMMA GND (black wire)
-
Board SCL to breakout STEMMA SCL (yellow wire)
- Board SDA to breakout STEMMA SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to breakout VIN (red wire)
-
Board GND to breakout GND (black wire)
-
Board SCL to breakout SCL (yellow wire)
- Board SDA to breakout SDA (blue wire)
Library Installation
You can install the Adafruit STCC4 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit STCC4, and select the Adafruit STCC4 library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
// Continuous measurement example for Adafruit STCC4 CO2 sensor
#include <Adafruit_STCC4.h>
Adafruit_STCC4 stcc4;
void printStatus(uint16_t status) {
Serial.print(F("Status: 0x"));
Serial.print(status, HEX);
Serial.print(F(" ("));
bool first = true;
if (status & STCC4_STATUS_VOLTAGE_ERROR) {
if (!first) Serial.print(F(", "));
Serial.print(F("VOLTAGE_ERROR"));
first = false;
}
if (status & STCC4_STATUS_DEBUG_MASK) {
if (!first) Serial.print(F(", "));
Serial.print(F("DEBUG"));
first = false;
}
if (status & STCC4_STATUS_SHT_NOT_CONNECTED) {
if (!first) Serial.print(F(", "));
Serial.print(F("SHT_NOT_CONNECTED"));
first = false;
}
if (status & STCC4_STATUS_MEMORY_ERROR_MASK) {
if (!first) Serial.print(F(", "));
Serial.print(F("MEMORY_ERROR"));
first = false;
}
if (status & STCC4_STATUS_TESTING_MODE) {
if (!first) Serial.print(F(", "));
Serial.print(F("TESTING_MODE"));
first = false;
}
if (first) {
Serial.print(F("OK"));
}
Serial.println(F(")"));
}
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
Serial.println(F("Adafruit STCC4 test"));
if (!stcc4.begin()) {
Serial.println(F("Failed to find STCC4 chip"));
while (1) delay(10);
}
Serial.println(F("STCC4 found!"));
if (!stcc4.reset()) {
Serial.println(F("Failed to reset STCC4"));
while (1) delay(10);
}
Serial.println(F("Reset successful"));
// Test getProductID function after reset
uint32_t productID = stcc4.getProductID();
Serial.print(F("Product ID: 0x"));
Serial.println(productID, HEX);
// Uncomment to perform factory reset (clears calibration history)
// Serial.println(F("Performing factory reset..."));
// if (stcc4.factoryReset()) {
// Serial.println(F("Factory reset complete"));
// } else {
// Serial.println(F("Factory reset failed"));
// }
if (!stcc4.enableContinuousMeasurement(true)) {
Serial.println(F("Failed to start continuous measurement"));
while (1) delay(10);
}
Serial.println(F("Continuous measurement started"));
// Uncomment to perform conditioning (takes 22 seconds)
// Serial.println(F("Performing conditioning..."));
// if (stcc4.performConditioning()) {
// Serial.println(F("Conditioning complete"));
// } else {
// Serial.println(F("Conditioning failed"));
// }
}
void loop() {
uint16_t co2;
float temperature, humidity;
uint16_t status;
if (stcc4.readMeasurement(&co2, &temperature, &humidity, &status)) {
Serial.print(F("CO2: "));
Serial.print(co2);
Serial.print(F(" ppm, Temp: "));
Serial.print(temperature);
Serial.print(F(" C, Humidity: "));
Serial.print(humidity);
Serial.print(F(" %, "));
printStatus(status);
} else {
Serial.println(F("Failed to read measurement"));
}
delay(1000);
}
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You should see that the sketch has found your connected STCC4 sensor. Then, you'll see the CO2, temperature, humidity and status readings printed to the Serial Monitor every second.
Page last edited March 16, 2026
Text editor powered by tinymce.