blog

SGP30 Gas Sensor eCO2 and TVOC

Cover image

Dive into the world of SGP30 calibration and unlock the full potential of your SGP30 sensor! Designed by Sensirion, this versatile module offers precise air quality detection—let’s get started with your SGP30 journey.

SGP30 first image

What is SGP30 Gas Sensor?

The SGP30 air quality sensor is an indoor gas sensor with multiple sensing elements integrated onto a single chip. It internally incorporates 4 gas sensing elements and provides a fully calibrated air quality output signal, mainly for air quality detection. It can output: TVOC (Total Volatile Organic Compounds), with a range of 0 to 60,000 ppb; CO2 concentration, with a range of 400 to 60,000 ppm.

sgp30 air quality sensor

SGP30 Working Principle

SGP30 Schematic Diagram

SGP30 Schematic Diagram

The working principle of the sgp30 gas sensor is based on electrochemical gas sensing technology and optical measurement technology.

For the measurement of carbon dioxide (CO2) concentration, the SGP30 sensor employs electrochemical gas sensing technology. It contains an electrochemical sensor element, which has an oxide electrode and a reference electrode. When CO2 molecules in the air enter the sensor and react with the electrolyte on the oxide electrode, an electrical current change occurs. By measuring this current change, the value of CO2 concentration can be determined.

For the measurement of volatile organic compounds (VOCs) concentration, the SGP30 sensor utilizes optical measurement technology. It contains a photosensitive element, which can sense specific wavelengths of light. When VOCs molecules in the air enter the sensor and react with the oxidant inside the sensor, oxidation reaction products are produced. These products absorb specific wavelengths of light, causing a change in the light signal received by the photosensitive element. By measuring this change in the light signal, the value of VOCs concentration can be determined.

The SGP30 sensor provides accurate air quality monitoring data by measuring the concentrations of CO2 and VOCs, combined with its internal algorithms and calibration data.

SGP30 Working Principle

Communication Protocol (I2C communication)

  1. Introduction to I2C Bus

The I2C bus (Inter IC bus) is a universal data bus developed by Philips.

Two communication lines: SCL (Serial Clock) and SDA (Serial Data).

Synchronous, half-duplex, with data response.

Note: Synchronous (because it has a separate clock line) and half-duplex (SDA has only one line and needs to communicate back and forth).

The universal I2C bus can unify the communication standards of various devices. For manufacturers, using a mature solution can shorten the chip design cycle and improve stability. For users, using a universal communication protocol can avoid learning various custom protocols, reducing the difficulty of learning and application.

  1. I2C Circuit Specification

All the SCL lines of the I2C devices are connected together, and the SDA lines are also connected together. The SCL and SDA of each device should be configured in open-drain output mode (hardware IIC).

Open-drain output mode — when the pin is disconnected, it becomes floating (the circuit is disconnected, and the voltage is unstable).

An upper pull-up resistor is added to each SCL and SDA line, with a resistance value generally ranging from 4.7K to 10K.

The combined action of open-drain output and a pull-up resistor enables the “wire-AND” functionality. This design primarily implemented to address interference issues in multi-device communication.

  1. I2C Timing Structure

Starting signal: During the high level of SCL, SDA switches from a high level to a low level.

Stopping signal: During the high level of SCL, SDA switches from a low level to a high level.

I2C Timing Structure 1

Sending response: After receiving one byte, the host sends one bit of data in the next clock cycle. Data 0 indicates a response, while data 1 indicates no response.

Receiving response: After sending one byte, the host receives one bit of data in the next clock cycle to determine if the slave device responds. Data 0 indicates a response, while data 1 indicates no response (the host needs to release SDA before receiving).

I2C Timing Structure 2

Send a byte: During the low level of SCL, the host will sequentially place the data bits onto the SDA line (with the higher bits coming first), then raise SCL. The host will read the data bits during the high level of SCL. Therefore, during the high level of SCL, the SDA line is not allowed to have any data changes. Repeat this process in sequence for 8 times, and then one byte can be sent.

I2C Timing Structure 3

Receive a byte: During the low level of SCL, the slave device will sequentially place the data bits onto the SDA bus (with the most significant bit first), then raise SCL. The slave device will read the data bits during the high level of SCL. Therefore, during the high level of SCL, the SDA is not allowed to have any data changes. This process is repeated in sequence 8 times, and then one byte is received (the host needs to release the SDA before receiving).

I2C Timing Structure 4
  1. SGP30 Data Reading
SGP30 Data Reading

The I2C slave address is 0X58. Since the address only uses 7 bits, the most significant bit is not used. The least significant bit is used to determine whether it is a read or write operation, with 0 indicating read and 1 indicating write. Therefore:

  • For writing to SGP30, the address is (0X58)
  • For reading from SGP30, the address is (0X58)

All the commands of SGP30 are double bytes. The high byte is sent first, and the following commands are:

SGP30 Data Reading 2

There are two commonly used ones. One is 0x2003 which is the initialization command for SGP30, and the other is 0x2008 which is the command for obtaining air quality values.

The data format obtained by SGP30 is: 2 bits of CO2 data + 1 bit of CRC check for CO2 + 2 bits of TVOC data + 1 bit of CRC check for TVOC. The module needs about 15 seconds to initialize after power-on. During the initialization stage, the CO2 concentration read is 400 ppm, and TVOC is 0 ppd and remains constant. Therefore, it keeps reading until TVOC is not 0 and CO2 is not 400, and then the SGP30 module is fully initialized.

After initialization, the data read at the beginning will fluctuate significantly, which is a normal phenomenon. After a period of time, it will gradually stabilize. Gas sensors are more susceptible to environmental influences, and the measurement data fluctuation is normal. A filtering function can be added for filtering.

Air Quality Signals
  1. Process Design

① Initialize the pins.

② Send the initialization command 0x2003.

③ Send the read data command 0x2008.

④ Start to obtain the data:

Obtain the high 8-bit data of CO2, then obtain the low 8-bit data of CO2, and then obtain one CRC check value.

Obtain the high 8-bit data of TVOC, then obtain the low 8-bit data of TVOC, and then obtain one CRC check value.

⑥ Integrate the data

Combine the high 8-bit data and low 8-bit data of CO2 into one data, which is the CO2 value.

Combine the high 8-bit data and low 8-bit data of TVOC into one data, which is the TVOC value.

SGP30 Gas Sensor Pin Function

Pin

Definition

VCC

Positive pole

GND

Grounding

SDA

Serial address and data input/output

SCL

Serial clock input

SGP40 vs SGP41 vs SGP30 Parameter

Model

SGP30

SGP40

SGP41

Sensor output

Two 16-bit digital original signals

Two 16-bit digital original signals

16-bit digital original signal

Handling output

VOC total quantity(ppb),

CO2 equivalent (ppm)

0-500 Volatile Organic Compound Index

0-500 Volatile Organic Compound Index

Measuring range(TVOC)

0 – 1000 ppm

0-1000ppm

0-1000ppm

Measuring range(CO2-eq)

0 – 1000 ppm

Device-to-device variables(TVOC)

15~25%

±15% meas.value

±15% meas.value

Device-to-device variables(CO2-eq)

10~20%

Power voltage

1.8V-5V

3.3-5V

3.3-5V

Average power current

49mA

2.6mA

3mA

SGP30 Arduino Tutorial

SGP30 Pinout

  • SGP30      Arduino

      VCC  ——>  3.3V

      GND  ——>  GND

      SCL  ——>  A5

      SDA  ——>  A4

  • OLED        Arduino

      VCC  ——>  3.3V

      GND  ——>  GND

      SCL  ——>  A5

      SDA  ——>  A4

Note : SGP30 and OLED can share the I2C bus because they have different addresses.

SGP30 Code

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SGP30 sgp;

void setup() {
  Serial.begin(9600);
  
  // Initialize OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println("OLED initialization failed!");
    while (1);
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  display.println("Initializing...");
  display.display();
  
  // Initialize SGP30 sensor
  if (!sgp.begin()) {
    Serial.println("SGP30 sensor not found!");
    display.println("SGP30 Error!");
    display.display();
    while (1);
  }
  
  // Try to restore baseline calibration
  uint16_t eco2_base, tvoc_base;
  if (sgp.getIAQBaseline(&eco2_base, &tvoc_base)) {
    sgp.setIAQBaseline(eco2_base, tvoc_base);
    Serial.println("Baseline calibration restored!");
  } else {
    Serial.println("No baseline found - sensor needs 12h calibration.");
  }
  
  Serial.println("SGP30 ready!");
  display.clearDisplay();
  display.println("SGP30 Ready");
  display.display();
  delay(2000); // Additional 2-second delay
}

void loop() {
  // Read sensor data
  if (!sgp.IAQmeasure()) {
    Serial.println("Failed to read SGP30 data!");
    display.clearDisplay();
    display.println("Sensor Error!");
    display.display();
    delay(1000);
    return;
  }
  
  // Print data to serial monitor
  Serial.print("TVOC: "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
  Serial.print("eCO2: "); Serial.print(sgp.eCO2); Serial.println(" ppm");
  
  // Display data on OLED
  display.clearDisplay();
  display.setCursor(0, 0);
  display.println("Air Quality");
  display.println("------------");
  display.print("TVOC: "); display.print(sgp.TVOC); display.println(" ppb");
  display.print("eCO2: "); display.print(sgp.eCO2); display.println(" ppm");
  display.display();
  
  delay(1000); // Update every 1 second
}
				
			

SGP30 Effect Demonstration

SGP30 Effect Demonstration

SGP30 Application Scenario

  1. Air quality detector
  2. Formaldehyde detector
  3. Portable gas detector
  4. Various DIY designs

Relative Information

SGP30 Purchase Link

FAQ

1、How accurate is the SGP30?

The SGP30 is a medium-accuracy gas sensor with ±15% accuracy for TVOC and ±15% or ±50ppm for eCO₂. It’s suitable for indoor air quality monitoring but requires 15s warm-up and 12h calibration. Not ideal for high-precision industrial use.

2、How do I know if my gas sensor is bad?

To determine if a gas sensor is damaged, look for these signs: After powering it on in clean air, does the reading fail to stabilize and remain stuck at an extremely high value or show no response at all? When tested with a known gas (such as the gas from a lighter), does the output signal show no change at all? Check if it has exceeded its service life (usually 2-10 years) or if there are any physical damages. For common MQ-type sensors, you can also measure the resistance of the heater pin with a multimeter after powering off. If it is infinity or zero ohms, it indicates internal damage.

3、How long do gas sensors last?

The lifespan of gas sensors typically ranges from 2 to 10 years, depending on the type: electrochemical types (such as those for detecting carbon monoxide) have a lifespan of approximately 2-3 years, while metal oxide types (such as the MQ series) have a lifespan of about 5-10 years. The actual lifespan may be shortened due to the usage environment (such as exposure to high concentrations of gases or chemical pollutants), and regular calibration and timely replacement according to the product instructions are necessary.

4、How often do gas monitors need to be calibrated?

Gas detectors are usually recommended to be calibrated at least once a year. However, the specific frequency depends on the type of sensor (such as electrochemical sensors require more frequent calibration), the usage environment (they should be calibrated immediately after exposure to high concentrations of gas or extreme conditions), and the manufacturer’s requirements. Regular calibration is crucial for ensuring the accuracy and safety of the measurements.

Leave a Reply

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