Arduino
Using the SGP41 gas sensor with Arduino involves wiring up the sensor to your Arduino-compatible microcontroller, installing the Adafruit_SGP41 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 SGP41 VIN.
Here is an Adafruit Metro wired up to the SGP41 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 SGP41 library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit SGP41, and select the Adafruit SGP41 library:
If asked about dependencies, click "Install all".
If the "Dependencies" window does not come up, then you already have the dependencies installed.
/**
* @file simpletest.ino
*
* Simple test for the Adafruit SGP41 sensor.
*
* Written by Limor 'ladyada' Fried with assistance from Claude Code for
* Adafruit Industries. MIT license, all text above must be included in any
* redistribution.
*/
#include <Adafruit_SGP41.h>
Adafruit_SGP41 sgp41;
void setup(void) {
Serial.begin(115200);
while (!Serial) {
delay(10);
}
Serial.println(F("Adafruit SGP41 simple test"));
if (!sgp41.begin()) {
Serial.println(F("Could not find SGP41! Halting."));
while (1) {
delay(10);
}
}
uint16_t serial_number[3];
if (sgp41.getSerialNumber(serial_number)) {
Serial.print(F("Serial Number: 0x"));
for (uint8_t i = 0; i < 3; i++) {
if (serial_number[i] < 0x1000) {
Serial.print(F("0"));
}
if (serial_number[i] < 0x100) {
Serial.print(F("0"));
}
if (serial_number[i] < 0x10) {
Serial.print(F("0"));
}
Serial.print(serial_number[i], HEX);
}
Serial.println();
} else {
Serial.println(F("Failed to read serial number! Halting."));
while (1) {
delay(10);
}
}
Serial.println(F("Conditioning (10 seconds)..."));
for (uint8_t i = 0; i < 10; i++) {
uint16_t sraw_voc = 0;
if (sgp41.executeConditioning(&sraw_voc)) {
Serial.print(F("SRAW_VOC: "));
Serial.println(sraw_voc);
} else {
Serial.println(F("Conditioning failed!"));
}
delay(1000);
}
Serial.println(F("Starting measurements."));
}
void loop(void) {
uint16_t sraw_voc = 0;
uint16_t sraw_nox = 0;
if (sgp41.measureRawSignals(&sraw_voc, &sraw_nox)) {
Serial.print(F("Raw VOC: "));
Serial.print(sraw_voc);
Serial.print(F("\tRaw NOx: "));
Serial.println(sraw_nox);
} else {
Serial.println(F("Measurement failed!"));
}
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 SGP41 sensor. Then, after conditioning the sensor, raw readings for VOC and NOx are printed to the Serial Monitor every second.
Page last edited February 13, 2026
Text editor powered by tinymce.