tutorialspinouttools
Sensors · ESP32-C3

SGP30 on OLED: TVOC & eCO2 Air Quality

Free ESP32 & Arduino tutorial · wiring, code & parts · gokul.builds

Overview & Wiring

What it is: The SGP30 (Sensirion) is a digital indoor-air-quality sensor giving TVOC (0–60000 ppb) and equivalent CO2 (400–60000 ppm). It's more stable and better specified than the CCS811. How it works: I2C device at fixed address 0x58. You must call a measurement roughly once per second — the algorithm inside depends on that steady 1 Hz cadence. Shares SDA/SCL with the OLED. Wiring (shared I2C bus with the OLED): SGP30 SDA -> GPIO4 SGP30 SCL -> GPIO5 SGP30 VCC -> 3V3 SGP30 GND -> GND OLED VCC=3V3, GND=GND, SDA=GPIO4, SCL=GPIO5 Libraries: "Adafruit SGP30 Sensor" (installs "Adafruit BusIO"), plus "Adafruit SSD1306" and "Adafruit GFX Library". On screen / Serial: TVOC in ppb and eCO2 in ppm. Gotchas: For the first ~15 seconds it outputs the fixed baseline (TVOC 0, eCO2 400) while it initialises. Call IAQmeasure() once per second for correct behaviour. Address 0x58 is fixed, so only one per bus.

Circuit Diagram

SGP30 on OLED: TVOC & eCO2 Air Quality wiring diagram for ESP32-C3

Parts You Need

ESP32-C3 SuperMiniBuy →
0.96" SSD1306 OLEDBuy →

Source Code (Arduino / ESP32)

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_SGP30.h>

Adafruit_SSD1306 display(128, 64, &Wire, -1);
Adafruit_SGP30 sgp;

void setup() {
  Serial.begin(115200);
  Wire.begin(4, 5);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  if (!sgp.begin()) {
    Serial.println("SGP30 not found");
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 28); display.println("SGP30 not found");
    display.display();
    while (1) delay(10);
  }
}

void loop() {
  if (sgp.IAQmeasure()) {                      // call once per second
    int tvoc = sgp.TVOC;
    int eco2 = sgp.eCO2;

    display.clearDisplay();
    display.setTextColor(SSD1306_WHITE);
    display.setTextSize(1);
    display.setCursor(0, 0);  display.println("SGP30");
    display.setTextSize(2);
    display.setCursor(0, 16); display.printf("%d", tvoc);
    display.setTextSize(1);
    display.setCursor(0, 36); display.print("TVOC ppb");
    display.setCursor(0, 50); display.printf("eCO2 %d ppm", eco2);
    display.display();

    Serial.printf("TVOC %d ppb  eCO2 %d ppm\n", tvoc, eco2);
  }
  delay(1000);
}
Browse all tutorials ESP32-C3 pinout Calculators