Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Interfacing SGP30 CO2 & TVOC Sensor with Arduino
Arduino Projects

Interfacing SGP30 CO2 & TVOC Sensor with Arduino

Mamtaz AlamBy Mamtaz AlamUpdated:May 28, 20232 Comments6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
SGP30 CO2 TVOC Sensor Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this post, we will be interfacing SGP30 CO2 & TVOC Sensor with Arduino and display the value on OLED Screen. The SGP30 Sensor is capable of detecting equivalent Carbon dioxide & Total Volatile Organic Compound from atmosphere. In earlier project, we measured CO2 & TVOC using CCS811 Gas Sensor & also BME680 integrated environmental sensor.

But SGP30 is a completely different sensor and has the ability to give proper reading quickly. While the CCS811 requires a burn-in of 48 hours and a run-in of 20 minutes the SGP30 is ready to go after just 15 seconds.

In this project, we will first read the CO2 & TVOC value from SGP30 Sensor using the Arduino Sparkfun library & display their value on Serial Monitor. The sensor can also measure the ethanol and Hydrogen (H2) values in raw values. Later we will display the sensor reading on a 0.96″ I2C OLED Display and test the sensor by introducing some perfume near the sensor.


Bill of Materials

You can purchase the following components from Amazon.

S.N.Components NameQuantityPurchase Links
1Arduino Nano Board1Amazon | AliExpress
2SGP30 Air Quality Sensor 1Amazon | AliExpress
30.96" I2C OLED Display1Amazon | AliExpress
4Connecting Wires20Amazon | AliExpress
5Breadboard1Amazon | AliExpress




SGP30 Air Quality Sensor

The SGP30 Gas Sensor is an air quality sensor used to measure VOC and eCO2. This is a very fine air quality sensor from the sensor experts at Sensirion. The sensor has an I2C interface. It gives fully calibrated output signals with a typical accuracy of 15% within measured values. The SGP combines multiple metal-oxide sensing elements on one chip to provide more detailed air quality signals. This module provides TVOC(Total Volatile Organic Compounds) and CO2eq output with outstanding long-term stability and low power consumption. This makes it a perfect choice for indoor air quality detection using Arduino or any other microcontroller.

SGP30 Sensor

The Sensirion SGP30 is a digital multi-pixel gas sensor that can easily integrate with air purifiers or demand-controlled ventilation. The sensor is powered by Sensirion’s CMOSens®technology that integrates a complete sensor system on a single chip featuring a temperature-controlled micro hotplate, and two preprocessed indoor air quality signals. As the first metal-oxide gas sensor featuring multiple sensing elements on one chip, the SGP30 provides more detailed information. Check SGP30 Datasheet for more information.

It outputs equivalent CO2 in ppm and Total Volatile Organic Compounds (TVOC) in ppb. The sensor also gives access to its raw measurement values of Ethanol and H2. The SGP30 boasts high stability with low long-term drift. With its continuous baseline compensation algorithm, readings stay accurate over time. You can even fine-tune your readings by interfacing with an external humidity sensor to add humidity compensation.


Features & Specifications

  • Sensiron SGP30 TVOC and eCO2 sensor
  • TVOC sensing from 0-60,000 ppb (parts per billion)
  • CO2 sensing from 400 to 60,000 ppm (parts per million)
  • 1Hz sampling rate
  • I2C interface(address 0x58)
  • 3.3V or 5V compatible
  • Raspberry Pi-compatible pinout (pins 1, 3, 5, 7, 9)
  • Compatible with all models of Raspberry Pi, and Arduino



Applications

  • Air purifier
  • demand-controlled ventilation
  • IoT applications
  • New house air condition monitor

SGP30 Sparkfun Arduino Library

The library for SGP30 is developed by Adafruit as well as Sparkfun. But we will use SGP30 Sparkfun Arduino Library in this project.

SGP30 Sparkfun Library

You can download the SGP30 Library from Github Link. Download the library and add to your Arduino IDE through library manager.


Interfacing SGP30 CO2 & TVOC Sensor with Arduino

Now let us interface the SGP30 Sensor with Arduino Board. The connection diagram between Arduino & SGP30 is very simple.

SGP30 Arduino Interfacing

Connect the VCC & GND pin of SGP30 to Arduino 3.3V & GND pin respectively. Since SGP30 is an I2C module, so connect its SDA & SCL pin to Arduino A4 & A5 pin respectively.

SGP30 CO2 TVOC Arduino



Source Code/Program: Reading CO2 & TVOC

The following code is taken from the example of Sparkfun SGP30 library. The code outputs measurements of total VOCs (TVOC) in parts per billion (ppb), carbon dioxide (CO2) equivalent in parts per million (ppm).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
#include <Wire.h>
 
SGP30 mySensor; //create an object of the SGP30 class
 
void setup()
{
  Serial.begin(9600);
  Wire.begin();
  //Initialize sensor
  if (mySensor.begin() == false)
{
    Serial.println("No SGP30 Detected. Check connections.");
    while (1);
  }
  //Initializes sensor for air quality readings
  //measureAirQuality should be called in one second increments after a call to initAirQuality
  mySensor.initAirQuality();
}
 
void loop()
{
  //First fifteen readings will be
  //CO2: 400 ppm  TVOC: 0 ppb
  delay(1000); //Wait 1 second
  //measure CO2 and TVOC levels
  mySensor.measureAirQuality();
  Serial.print("CO2: ");
  Serial.print(mySensor.CO2);
  Serial.print(" ppm\tTVOC: ");
  Serial.print(mySensor.TVOC);
  Serial.println(" ppb");
}

From the board manager, select the Arduino board that you are using. Also, select the COM port. Then hit the upload button to upload the code to the Arduino Board.

Once code uploading completes, open serial monitor.

Initially the Serial monitor will display the CO2 value as 400ppm & TVOC value as 0ppb. After 15-20 readings the sensor will get stable as it gets heated. Then the sensor value will be correctly displayed.



Source Code/Program: Reading Ethanol & Hydrogen (H2)

The SGP30 uses a dynamic baseline compensation algorithm and on-chip calibration parameters to provide two complimentary air quality signals. The baseline should be stored in EEPROM. When there is no baseline value in EEPROM at the first time power-ON or the baseline record is older than seven days. The sensor has to run for 12 hours until the baseline can be stored. You can refer to the program flow chart below.

The H2_Signal and Ethanol_signal, Both signals can be used to calculate gas concentrations c relative to a reference concentration cref by ln(C/Cref)=(Serf-Sout)/a with a = 512, sref the H2_signal or Ethanol_signal output at the reference concentration, and sout = Sout_H2 or Sout = Sout_EthOH.

For more accurate measurement, You can set the absolute humidity compensation, the Default value is 11.57g/m3, A little troublesome is that you should get the relative humidity value of the environment from another way Because there is no humidity measurement part integrated into SGP30.

Here is the complete code that reads CO2, TVOC, H2 & Ethanol value.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
#include <Wire.h>
 
SGP30 mySensor; //create an object of the SGP30 class
long t1, t2;
void setup() {
  Serial.begin(9600);
  Wire.begin();
  //Sensor supports I2C speeds up to 400kHz
  Wire.setClock(400000);
  //Initialize sensor
  if (mySensor.begin() == false) {
    Serial.println("No SGP30 Detected. Check connections.");
    while (1);
  }
  //Initializes sensor for air quality readings
  //measureAirQuality should be called in one second increments after a call to initAirQuality
  mySensor.initAirQuality();
  t1 = millis();
}
 
void loop() {
  //First fifteen readings will be
  //CO2: 400 ppm  TVOC: 0 ppb
  t2 = millis();
  if ( t2 >= t1 + 1000) //only will occur if 1 second has passed
  {
    t1 = t2;
    //measure CO2 and TVOC levels
    mySensor.measureAirQuality();
    Serial.print("CO2: ");
    Serial.print(mySensor.CO2);
    Serial.print(" ppm\tTVOC: ");
    Serial.print(mySensor.TVOC);
    Serial.println(" ppb");
    //get raw values for H2 and Ethanol
    mySensor.measureRawSignals();
    Serial.print("Raw H2: ");
    Serial.print(mySensor.H2);
    Serial.print(" \tRaw Ethanol: ");
    Serial.println(mySensor.ethanol);
  }
}

Once the code is uploaded, you can again open the Serial monitor. Observe the reading after 15-20 readings, you will be able to see CO2, TVOC, H2 & Ethanol values. Note: The H2 & Ethanol values are only the raw values.


Displaying CO2 & TVOC value on OLED Display

Now lets display the CO2 & TVOC value on some display module instead of displaying on Serial Monitor. The best module for that is 0.96″ I2C OLED Display. The connection diagram is fairly simple again.

SGP30 Arduino OLED

The OLED display is also an I2C Module. Therefore connect it directly with the I2C Pin of the Arduino Board.

SGP30 Arduino OLED


Source Code/Program for OLED Display

The SSD1306 OLED Display requires two libraries for compilation. Download the following libraries and add them to the library folder.

  1. Adafruit SSD1306 Library: https://github.com/adafruit/Adafruit_SSD1306
  2. Adafruit GFX Library: https://github.com/adafruit/Adafruit-GFX-Library


Copy the following code and upload it to the Arduino Board.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
#define SCREEN_WIDTH 128    // OLED display width, in pixels
#define SCREEN_HEIGHT 64    // OLED display height, in pixels
#define OLED_RESET     4    // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C // 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
 
SGP30 mySensor; //create an object of the SGP30 class
 
void setup()
{
  Serial.begin(9600);
  Wire.begin();
 
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS))
  {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
  
  //Initialize sensor
  if (mySensor.begin() == false)
  {
    Serial.println("No SGP30 Detected. Check connections.");
    while (1);
  }
  //Initializes sensor for air quality readings
  //measureAirQuality should be called in one second increments after a call to initAirQuality
  mySensor.initAirQuality();
}
 
void loop()
{
  //First fifteen readings will be
  //CO2: 400 ppm  TVOC: 0 ppb
  delay(1000); //Wait 1 second
  //measure CO2 and TVOC levels
  mySensor.measureAirQuality();
  Serial.print("CO2: ");
  Serial.print(mySensor.CO2);
  Serial.print(" ppm\tTVOC: ");
  Serial.print(mySensor.TVOC);
  Serial.println(" ppb");
 
  display.setCursor(0, 10); //oled display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.print("CO2:");
  display.print(mySensor.CO2);
  display.setTextSize(1);
  display.print("ppm");
 
  display.setCursor(0, 40); //oled display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.print("TVOC:");
  display.print(mySensor.TVOC);
  display.setTextSize(1);
  display.print("ppb");
 
  display.display();
  display.clearDisplay();
 
}



The OLED Display will initialize and start displaying the CO2 & TVOC Value. Initially, it will display the CO2 & TVOC value as 400ppm & 0ppb respectively.

After 15-20 reading the OLED will start displaying the correct stable value.

To test the sensor working, you can bring perfume, spray, or any organic compound near the sensor. The sensor will display the value in large digits in ppm & ppb.

SGP30 Sensor Arduino CO2 TVOC


Video Tutorial & Guide

SGP30 Air Quality Sensor - Measuring Equivalent CO2 & Total Volatile Organic Compound (TVOC)
Watch this video on YouTube.

This is how you can use SGP30 CO2 & TVOC Sensor with Arduino. You can also use this sensor in Indoor Environment Monitoring with ESP32 & TFT LCD Display.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleDIY Homemade PCB – Etching PCBs with 3D Printers
Next Article Real Time GPS Tracker using ESP8266 & Blynk with Maps

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 2 Comments

2 Comments

  1. Eric on August 25, 2022 11:24 AM

    Great tutorial, thank you!
    When I use the sensor, it displays only CO2 values above 400 ppm, even outside.
    This seems odd to me. Are those readings trustworthy?

    Reply
  2. tantris on September 28, 2022 9:07 PM

    “Based on analysis from NOAA’s Global Monitoring Lab, global average atmospheric carbon dioxide was 414.72 parts per million (“ppm” for short) in 2021..”

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • IoT Based Drinking Water Quality Monitoring with ESP32
    IoT Based Drinking Water Quality Monitoring with ESP32
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • DIY IoT Water pH Meter using pH Sensor & ESP32
    DIY IoT Water pH Meter using pH Sensor & ESP32
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.