Ultimate Air Quality Monitor: Build with SGP30 & OLED Display

Ultimate Air Quality Monitor build with sgp30 oled display Ultimate Air Quality Monitor build with sgp30 oled display

Create a professional-grade air quality monitor using the industry-leading Seeed Studio Grove SGP30 sensor or GY-SGP30 sensor and crisp OLED display, delivering real-time insights into your environment’s health with precision and affordability.

Introduction: Why the SGP30 is Your Best Choice

Indoor air quality is a critical but often invisible aspect of our health. The SGP30 VOC & eCO2 Gas Sensor stands out as a premier solution for monitoring air quality, offering professional-grade accuracy in a compact, easy-to-use module. Unlike cheaper alternatives that provide unreliable readings or require complex calibration, the SGP30 leverages Sensirion’s advanced CMOSens® technology to deliver precise measurements of Total Volatile Organic Compounds (TVOC) and equivalent CO2 (eCO2) directly via I2C interface.

Grove-VOC and eCO2 Gas Sensor(SGP30)

What makes this sensor truly exceptional is its outstanding long-term stability and built-in compensation algorithms that minimize drift over time—a common issue with other gas sensors. The Grove ecosystem’s plug-and-play design makes it accessible to beginners while offering the precision demanded by professionals. Whether you’re monitoring air quality in your home, office, or classroom, this system provides actionable data to improve ventilation and reduce exposure to harmful pollutants.


Understanding the SGP30 Sensor Technology

How the SGP30 Works Its Magic

The SGP30 represents a breakthrough in gas sensing technology, combining multiple sensing elements on a single chip using metal oxide semiconductor (MOx) technology. The sensor’s surface is coated with a nanoscale film of metal oxide particles that react with various gas molecules in the air. When target gases (such as VOCs or hydrogen) interact with this film, they cause a measurable change in electrical resistance, which the sensor’s integrated circuit then converts to digital concentration values.

workflow of SGP30

The sensor integrates four separate gas sensing elements on a single chip, providing multiple data points that its internal algorithm processes to generate highly accurate TVOC and eCO2 readings. This multi-pixel approach allows the SGP30 to distinguish between different types of VOCs and maintain accuracy even when exposed to complex gas mixtures. The sensor also includes temperature compensation and can accept external humidity data for even greater precision.

Complete Technical Specifications

Parameter Specification Details & Implications
Measured Gases TVOC (Total Volatile Organic Compounds), eCO2 (equivalent CO2) Provides comprehensive air quality assessment through two key indicators
TVOC Measurement Range 0 – 60,000 ppb Covers from pristine air to heavily polluted environments
eCO2 Measurement Range 400 – 60,000 ppm Baseline 400ppm (fresh air) to heavily occupied spaces
TVOC Resolution 1 ppb (0-2008 ppb)
6 ppb (2008-11110 ppb)
32 ppb (11110-60000 ppb)
High precision at typical indoor concentrations
eCO2 Resolution 1 ppm (400-1479 ppm)
3 ppm (1479-5144 ppm)
9 ppm (5144-17597 ppm)
31 ppm (17597-60000 ppm)
Sufficient resolution to detect air quality changes
Sampling Rate 1 Hz Updates once per second for real-time monitoring
Interface I²C (Address: 0x58) Standard protocol, easy integration with all major microcontrollers
Operating Voltage 3.3V/5V (module level)
1.8V (chip level)
Grove module includes voltage regulation for direct connection
Current Consumption < 48mA during measurement
< 5µA in sleep mode
Low power suitable for battery-operated devices
Operating Temperature -40°C to +85°C Functional in extreme environments
Operating Humidity 10% to 95% RH (non-condensing) Works in most indoor and outdoor conditions
Dimensions 20mm × 20mm module Compact size for discreet installation
Lifespan > 5 years (continuous operation) Long-term reliability with proper calibration

Deep Dive: Understanding eCO2 vs. Real CO2

The SGP30 measures equivalent CO2 (eCO2) rather than actual CO2 concentration. This is calculated based on the detected hydrogen (H2) concentration in the air, which correlates strongly with human presence and respiration.

While not identical to NDIR CO2 sensors, eCO2 provides an excellent approximation for ventilation control in occupied spaces. The advantage is that the SGP30 can detect both VOCs and eCO2 in a single compact package at a fraction of the cost of separate sensors.


Required Components for Complete Air Quality System

Component Specification Purpose Approximate Price
Main Controller ESP32, ESP8266, or Arduino Processes sensor data and controls display $5 – $15
Gas Sensor Grove or GY-SGP30 Gas Sensor Measures TVOC and eCO2 concentrations $15 – $25
Temperature/Humidity Grove SHT31 or BME280 Provides data for humidity compensation $8 – $15
Display 0.96″ or 1.3″ I²C OLED (SSD1306) Shows real-time air quality readings $5 – $10
Cables & Connectors Grove cables, jumper wires System interconnection $2 – $5
Power Supply USB cable or battery pack Powers the system $3 – $10
Enclosure 3D printed case or project box Professional housing for your monitor $5 – $15

Pro Tip: While the SGP30 can operate without humidity compensation, adding a temperature/humidity sensor significantly improves accuracy, especially in environments with high humidity variability. The investment is well worth it for precise measurements.


Build a Professional Air Quality Monitor with PCBWay’s Precision Manufacturing

Elevate your air sensing project with PCBWay’s complete fabrication services, designed to turn your SGP30 and OLED display prototype into a refined, market-ready air quality monitor. Achieve both performance and polish through integrated PCB assembly and 3D-printed enclosures.

High-Performance Custom PCB:
Design a unified PCB that integrates the SGP30 VOC/CO₂ sensor, OLED display, microcontroller, and environmental compensation circuits. Our advanced SMT assembly ensures precise soldering of sensitive I²C traces, minimizing noise and maximizing sensor accuracy. Dedicated power planes and shielding maintain signal integrity for reliable, real-time air quality readings.

Elegant 3D-Printed Enclosure:
Create a sleek, vented housing using our high-resolution 3D printing services. Choose from materials like fine-finish PLA+, durable ABS, or transparent PETG for display windows. Design optimized airflow channels to facilitate sensor sampling while protecting components from dust and physical impact. Incorporate snap-fit designs and professional button cutouts for a refined user experience.

Why PCBWay Delivers Superior Results:

  • Sensor-Ready PCBs: Clean layouts and thermal management for stable SGP30 operation
  • Aesthetic Precision: Smoothed finishes and precise tolerances for premium enclosures
  • End-to-End Integration: Perfect alignment from board mounting to display fitting
  • Scalable Production: From one prototype to hundreds, with consistent quality

Bring Your Air Quality Monitor to Life
Upload your PCB Gerber and enclosure STL files for instant DFM feedback and a seamless manufacturing experience. Start Building Your Professional Monitor Today with PCBWAY.COM


System Architecture

System Architecture of Air Quality Monitoring system using SGP30


Circuit Diagram and Wiring Instructions

The Grove system makes wiring incredibly simple with color-coded cables and standardized connectors:

Grove Cable Color Function Connection to Microcontroller
Red VCC (Power) 3.3V or 5V (depending on module)
Black GND (Ground) GND pin
White SDA (Data) I²C SDA pin (GPIO 21 on ESP32, A4 on Arduino)
Yellow SCL (Clock) I²C SCL pin (GPIO 22 on ESP32, A5 on Arduino)

Advanced Wiring: Direct Connection with Arduino (Without Grove Shield)

interfacing SGP30 with arduino to build Air quality monitoring system

 

If you’re not using a Grove shield, you can connect the SGP30 directly to your microcontroller using jumper wires:

  • SGP30 VCC → 3.3V (or 5V if your module supports it)
  • SGP30 GND → GND
  • SGP30 SDA → SDA pin (GPIO 21 on ESP32, A4 on Arduino Uno)
  • SGP30 SCL → SCL pin (GPIO 22 on ESP32, A5 on Arduino Uno)

Remember to add 4.7kΩ pull-up resistors to both SDA and SCL lines if they’re not already present on your board.


Coding and Software Implementation

After connecting all the required components, upload the code to Arduino through Arduino IDE

Required Libraries

For Arduino development, you’ll need to install these libraries via the Library Manager:

  1. Adafruit SGP30 Library – Primary driver for the SGP30 sensor
  2. Adafruit SSD1306 Library – Controls the OLED display
  3. Adafruit Unified Sensor Library – Dependency for sensor libraries
  4. Wire Library – Built-in I²C communication (usually pre-installed)

Complete Code Example

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

// Display settings
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// Sensor objects
Adafruit_SGP30 sgp;

// Compensation variables
uint32_t getAbsoluteHumidity(float temperature, float humidity) {
  // Approximation formula from Sensirion SGP30 Driver Integration chapter 3.15
  const float absoluteHumidity = 216.7f * ((humidity / 100.0f) * 6.112f * exp((17.62f * temperature) / (243.12f + temperature)) / (273.15f + temperature)); // [g/m^3]
  const uint32_t absoluteHumidityScaled = static_cast<uint32_t>(1000.0f * absoluteHumidity); // [mg/m^3]
  return absoluteHumidityScaled;
}

void setup() {
  Serial.begin(115200);
  
  // Initialize I2C
  Wire.begin();
  
  // Initialize display
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0,0);
  display.println("Air Quality Monitor");
  display.println("Initializing...");
  display.display();
  
  // Initialize SGP30
  if (!sgp.begin()){
    Serial.println("Sensor not found :(");
    while (1);
  }
  Serial.print("Found SGP30 serial #");
  Serial.print(sgp.serialnumber[0], HEX);
  Serial.print(sgp.serialnumber[1], HEX);
  Serial.println(sgp.serialnumber[2], HEX);
  
  // If you have a baseline measurement from before you can assign it to start
  // sgp.setIAQBaseline(0x8E68, 0x8F41); // Uncomment to set specific baseline
  
  delay(2000); // Allow sensor to stabilize
}

int counter = 0;
void loop() {
  // Read temperature and humidity from your sensor here
  // For this example, we'll use dummy values - replace with actual sensor readings
  float temperature = 22.1; // [°C]
  float humidity = 45.2;    // [%RH]
  
  // Set humidity compensation for better accuracy
  sgp.setHumidity(getAbsoluteHumidity(temperature, humidity));
  
  // If you have a temperature/humidity sensor, you would get the actual values here
  
  // Measure air quality
  if (! sgp.IAQmeasure()) {
    Serial.println("Measurement failed");
    return;
  }
  
  // Clear and update display
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  
  // Display temperature and humidity
  display.setCursor(0,0);
  display.print("Temp: "); display.print(temperature, 1); display.println(" C");
  display.setCursor(0,10);
  display.print("Hum:  "); display.print(humidity, 1); display.println(" %");
  
  // Display TVOC and eCO2 readings
  display.setCursor(0,25);
  display.print("TVOC: "); display.print(sgp.TVOC); display.println(" ppb");
  display.setCursor(0,35);
  display.print("eCO2: "); display.print(sgp.eCO2); display.println(" ppm");
  
  // Calculate and display air quality index
  int aqi = 0;
  if (sgp.TVOC < 220) aqi = 0;      // Good
  else if (sgp.TVOC < 660) aqi = 50; // Moderate
  else if (sgp.TVOC < 2200) aqi = 100; // Unhealthy for sensitive
  else if (sgp.TVOC < 5500) aqi = 150; // Unhealthy
  else if (sgp.TVOC < 11000) aqi = 200; // Very Unhealthy
  else aqi = 300;                      // Hazardous
  
  display.setCursor(0,50);
  display.print("AQI: "); display.println(aqi);
  
  display.display();
  
  // Print to serial monitor for debugging
  Serial.print("TVOC "); Serial.print(sgp.TVOC); 
  Serial.print(" ppb\t");
  Serial.print("eCO2 "); Serial.print(sgp.eCO2); 
  Serial.println(" ppm");
  
  // Every 30 seconds, save baseline values to non-volatile memory
  if (counter % 30 == 0) {
    uint16_t TVOC_base, eCO2_base;
    if (! sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) {
      Serial.println("Failed to get baseline readings");
      return;
    }
    Serial.print("****Baseline values: eCO2: 0x"); Serial.print(eCO2_base, HEX);
    Serial.print(" & TVOC: 0x"); Serial.println(TVOC_base, HEX);
  }
  
  counter++;
  delay(1000); // Wait 1 second between measurements
}

Calibration and Optimization

The SGP30 features automatic baseline calibration that continuously learns the environment’s typical air quality profile. However, for best results:

  1. Initial 12-24 Hour Burn-In: The sensor needs time to establish its initial baseline. Keep it powered in fresh air for at least 12 hours before relying on readings.
  2. Save Baseline Values: The code above demonstrates how to save and restore baseline values. Store these in EEPROM or flash memory to avoid re-learning after power cycles.
  3. Humidity Compensation: Always provide humidity data when possible. High humidity can significantly affect TVOC readings, causing underestimation of pollution levels.
  4. Avoid Exposure to Siloxanes: Common in personal care products, siloxanes can permanently damage the sensor’s sensing elements. Avoid using products containing them near your monitor.

Output on OLED display

Air quality monitoring system with sgp30 output on Oled display


Advanced Applications and Modifications

1. IoT Integration with ESP8266/ESP32

Transform your Air Quality monitor into an IoT device by adding Wi-Fi connectivity from the below code by merging it with the main program code:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>

// WiFi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

// MQTT settings
const char* mqtt_server = "broker.hivemq.com";
const char* mqtt_topic = "home/airquality";

WiFiClient espClient;
PubSubClient client(espClient);

void setupWiFi() {
  delay(10);
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void reconnect() {
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      delay(5000);
    }
  }
}

void publishData() {
  StaticJsonDocument<200> doc;
  doc["tvoc"] = sgp.TVOC;
  doc["eco2"] = sgp.eCO2;
  doc["temperature"] = temperature;
  doc["humidity"] = humidity;
  
  String payload;
  serializeJson(doc, payload);
  
  client.publish(mqtt_topic, payload.c_str());
  Serial.print("Published data: ");
  Serial.println(payload);
}

2. Data Logging and Analysis

For long-term air quality assessment, add data logging capabilities:

  • SD Card Module: Log readings to a microSD card for later analysis
  • Google Sheets Integration: Use webhooks to send data directly to Google Sheets for visualization
  • InfluxDB + Grafana: Create a professional time-series database dashboard for your data

3. Alert System Implementation

Add visual and audible alerts when air quality exceeds thresholds by adding an LED light and a Buzzer using the below code:

void checkAirQuality() {
  int aqi = calculateAQI(sgp.TVOC, sgp.eCO2);
  
  if (aqi > 100) {
    digitalWrite(LED_BUILTIN, HIGH); // Turn on built-in LED
    if (aqi > 200) {
      // Add buzzer alert for hazardous conditions
      tone(BUZZER_PIN, 1000, 500);
    }
  } else {
    digitalWrite(LED_BUILTIN, LOW); // Turn off LED
    noTone(BUZZER_PIN); // Ensure buzzer is off
  }
  
  displayAQIStatus(aqi);
}

Practical Applications and Use Cases

Environment Target Parameters Action Thresholds Recommended Actions>
Home Living Room TVOC < 220 ppb, eCO2 < 1000 ppm TVOC > 500 ppb or eCO2 > 1200 ppm Increase ventilation, identify sources
Bedroom TVOC < 100 ppb, eCO2 < 800 ppm TVOC > 300 ppb or eCO2 > 1000 ppm Open windows, run air purifier
Office/Classroom TVOC < 300 ppb, eCO2 < 1000 ppm eCO2 > 1200 ppm Increase fresh air intake, check ventilation
Kitchen TVOC < 500 ppb (cooking spikes expected) TVOC > 1000 ppb sustained Increase exhaust ventilation, check combustion sources
Workshop TVOC < 1000 ppb, eCO2 < 1500 ppm TVOC > 2000 ppb or eCO2 > 2000 ppm Improve ventilation, use respirators if needed

Frequently Asked Questions

1.How accurate is the SGP30 compared to professional sensors?
The SGP30 offers typical accuracy of ±15% for TVOC measurements and ±15% for eCO2 readings under standard conditions.
While not as precise as laboratory-grade equipment costing thousands of dollars, it provides excellent accuracy for its price point and is suitable for most air quality monitoring applications. For absolute precision measurements, professional calibration services are available.

2. Can I use multiple SGP30 sensors on the same I²C bus?
Unfortunately, no. The SGP30 has a fixed I²C address of 0x58, meaning only one sensor can be used per I²C bus. To use multiple sensors, you would need an I²C multiplexer or separate microcontrollers for each sensor.

3. How long does the sensor last, and when should I replace it?

Under normal operating conditions, the SGP30 has a lifespan of over 5 years of continuous operation. The sensor’s performance may gradually decline over time, but its built-in baseline compensation helps maintain accuracy. If you notice readings becoming consistently erratic or failing to respond to known air quality changes, it may be time to replace the sensor.

4. Why are my initial readings always 400 ppm eCO2 and 0 ppb TVOC?

This is normal behavior during the sensor’s initial burn-in period. The SGP30 outputs default values (400 ppm for eCO2 and 0 ppb for TVOC) for approximately the first 15-30 seconds of operation while it initializes its sensing elements. After this period, you should start seeing realistic readings as the sensor begins to sample the actual air quality.

5. Can I use this sensor outdoors?

While the SGP30 is rated for operation from -40°C to +85°C and 10-95% relative humidity, it is primarily designed for indoor air quality monitoring. Outdoor use exposes the sensor to environmental extremes and contaminants that may affect its accuracy and lifespan. If outdoor monitoring is required, additional protection and more frequent calibration may be necessary.


Conclusion: Building Your Professional Air Quality Monitor

The SGP30 gas sensor represents an excellent balance of accuracy, affordability, and ease of use for air quality monitoring projects. Its digital I²C interface, built-in compensation algorithms, and Grove ecosystem compatibility make it accessible to beginners while providing the precision demanded by more advanced users.

By combining this sensor with a microcontroller, temperature/humidity sensor, and OLED display, you can create a comprehensive air quality monitoring system that provides real-time insights into your environment’s health. The addition of IoT capabilities enables remote monitoring and data logging for long-term analysis and trend identification.

Whether you’re monitoring air quality in your home, office, classroom, or workshop, this system provides the data you need to make informed decisions about ventilation, air purification, and overall health. The investment in this project will pay dividends in improved air quality awareness and better health outcomes for you and your family.


Disclaimer: This air quality monitoring system is designed for educational and informational purposes only. It should not be used as a substitute for professional air quality assessment or safety-critical applications. Always follow manufacturer guidelines and local regulations when working with electronic components and air quality monitoring equipment.

Add a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *