SGP40 VOC Sensor with a Raspberry Pi Pico
The Sensirion SGP40 is an I2C metal-oxide gas sensor that reports a VOC Index (1-500) for total volatile organic compounds in indoor air.

On the Raspberry Pi Pico the SGP40 breakout is powered from 3V3, with SDA on GP4 and SCL on GP5, the I2C0 pins that arduino-pico's Wire uses by default. VIN has to stay on 3V3 here, because the breakout ties its SDA and SCL pull-ups to VIN and the Pico's GPIO is fixed at 3.3 V.
Wiring the SGP40 VOC Sensor to the Raspberry Pi Pico
Pin by pin.
| SGP40 VOC Sensor | Raspberry Pi Pico |
|---|---|
| VIN | 3V3 |
| GND | GND |
| SCL | GP5 |
| SDA | GP4 |
What to know on the Raspberry Pi Pico
- Wired to VBUS instead, the breakout's 10 kΩ pull-ups would lift GP4 and GP5 to 5 V. The Pico's GPIO is powered from its 3.3 V rail, so leave VIN on 3V3 and the bus stays at the Pico's own level.Adafruit SGP40 guide, Pinouts; Raspberry Pi Pico datasheet, release 21, section 4.2, p. 19
- GP4 and GP5 are Wire's defaults on the Pico. To move the sensor to another I2C0 pair, such as GP0 and GP1, call Wire.setSDA() and Wire.setSCL() before sgp.begin(), since the library starts Wire itself.arduino-pico documentation, Wire (I2C Master and Slave); arduino-pico variants/rpipico/pins_arduino.h
- Sensirion specifies the VOC Index at a 1 s sampling interval and the sensor needs under 60 s after switch-on before it reliably detects VOC events, so give the Pico a minute or so before trusting the numbers.Sensirion SGP40 datasheet v1.2, p. 3
- With the library's 25 °C and 50 %RH the SGP40 does no humidity compensation. Feeding it a real reading from a humidity sensor on GP4 and GP5 makes the raw signal, and so the index, steadier as the room's humidity changes.Sensirion SGP40 datasheet v1.2, p. 9; Adafruit_SGP40 library, Adafruit_SGP40.h
SGP40 VOC Sensor code for the Raspberry Pi Pico
Compiled for rp2040:rp2040:rpipico on 2026-10-30.
// SGP40 VOC Sensor on Raspberry Pi Pico: wiring and a free simulation at https://www.tinkered.ai/components/sgp40-voc-sensor/raspberry-pi-pico
#include <Wire.h>
#include "Adafruit_SGP40.h"
Adafruit_SGP40 sgp;
// The SGP40 compensates for humidity and temperature. With no sensor for them, pass the
// library's defaults, 25 °C and 50 %RH; with an SHT4x or a BME280 beside it, pass its readings.
const float TEMPERATURE_C = 25.0;
const float HUMIDITY_RH = 50.0;
void setup() {
Serial.begin(115200);
if (!sgp.begin()) { // fixed I2C address 0x59
Serial.println("SGP40 not found");
while (1) delay(10);
}
Serial.println("SGP40 ready: the VOC Index reads 0 for its first 45 s");
}
uint32_t lastSample = 0;
void loop() {
// Sensirion's VOC algorithm expects one sample a second. The library waits about 250 ms
// for each measurement, so time the loop with millis() rather than delay(1000).
if (millis() - lastSample < 1000) return;
lastSample = millis();
// Both calls take (temperature, humidity), in that order. measureVocIndex() measures and runs
// the algorithm: 100 is this air's recent average, higher means more VOCs than usual, lower fewer.
int32_t vocIndex = sgp.measureVocIndex(TEMPERATURE_C, HUMIDITY_RH);
Serial.print("VOC Index: ");
Serial.println(vocIndex);
}
SGP40 VOC Sensor on the Raspberry Pi Pico: questions
Which Pico pins does the SGP40 connect to?
SDA to GP4 and SCL to GP5 (arduino-pico's default Wire pins), VIN to 3V3 and GND to any GND pin.
Can I power the SGP40 breakout from the Pico's VBUS?
It would run, since VIN accepts 3 V to 5 V (Adafruit SGP40 guide), but its pull-ups to VIN would then put 5 V on GP4 and GP5. Use 3V3.
What range does the SGP40's VOC Index cover?
1 to 500 points, where 100 is the typical air the sensor has been in recently; higher values mean worse air, lower values better (Sensirion datasheet, p. 9).
Keep going
This guide as plain Markdown. /components/sgp40-voc-sensor/raspberry-pi-pico.md