Stufin
Home Quick Cart Profile

M5Stack TVOC/eCO2 Gas Unit (SGP30)

Buy Now on Stufin

Pin Configuration

  • M5Stack TVOC/eCO2 Gas Unit (SGP30) Pinout Documentation
  • The M5Stack TVOC/eCO2 Gas Unit (SGP30) is a compact sensor module designed to detect Total Volatile Organic Compounds (TVOC) and equivalent Carbon Dioxide (eCO2) levels in the air. The module features the popular SGP30 gas sensor from Sensirion, which provides highly accurate and reliable gas concentration measurements. Here's a detailed explanation of the pins on the M5Stack TVOC/eCO2 Gas Unit (SGP30) and how to connect them:
  • Pinout Structure:
  • The module has a total of 6 pins, arranged in a single row.
  • The pins are spaced 2.54mm apart, making it compatible with standard breadboards and PCBs.
  • The pin numbering starts from the top-left corner, moving clockwise.
  • Pin-by-Pin Explanation:
  • 1. VIN (Pin 1)
  • Function: Power Supply Input
  • Description: This pin is connected to the positive terminal of the power supply (typically 3.3V or 5V).
  • Connection: Connect to a suitable power source (e.g., a battery or a voltage regulator output).
  • 2. GND (Pin 2)
  • Function: Ground
  • Description: This pin is connected to the negative terminal of the power supply (ground).
  • Connection: Connect to the ground pin of the power source or a common ground point on the PCB.
  • 3. SCL (Pin 3)
  • Function: I2C Clock Line
  • Description: This pin is used as the clock line for I2C communication.
  • Connection: Connect to the SCL pin of the microcontroller or other I2C devices.
  • 4. SDA (Pin 4)
  • Function: I2C Data Line
  • Description: This pin is used as the data line for I2C communication.
  • Connection: Connect to the SDA pin of the microcontroller or other I2C devices.
  • 5. RST (Pin 5)
  • Function: Reset Pin
  • Description: This pin is used to reset the SGP30 sensor.
  • Connection: Connect to a digital output pin on the microcontroller or a pull-up resistor to the power supply.
  • 6. INT (Pin 6)
  • Function: Interrupt Pin
  • Description: This pin is used to indicate when new measurement data is available.
  • Connection: Connect to a digital input pin on the microcontroller to detect interrupts.
  • Connection Tips and Precautions:
  • Ensure the power supply voltage is within the recommended range (3.3V to 5V) to avoid damaging the sensor.
  • Use a suitable pull-up resistor (e.g., 4.7k) on the RST pin if it's not connected to a digital output pin on the microcontroller.
  • The I2C bus should be properly terminated with pull-up resistors to prevent data corruption.
  • Avoid exposing the sensor to extreme temperatures, humidity, or gas concentrations, as this may affect its accuracy and lifespan.
  • By following these guidelines, you can successfully connect and interface the M5Stack TVOC/eCO2 Gas Unit (SGP30) with your microcontroller or other devices to enable accurate gas concentration measurements in your IoT projects.

Code Examples

M5Stack TVOC/eCO2 Gas Unit (SGP30) Documentation
Overview
The M5Stack TVOC/eCO2 Gas Unit (SGP30) is a high-performance gas sensor module designed for detecting Total Volatile Organic Compounds (TVOC) and equivalent Carbon Dioxide (eCO2) levels. The module is based on the SGP30 gas sensor chip from Sensirion, which offers high accuracy and reliability in measuring indoor air quality.
Features
Measures TVOC (ppb) and eCO2 (ppm) levels
 High accuracy and reliability
 Low power consumption
 I2C interface for easy communication
 Operating voltage: 3.3V - 5V
 Compatible with M5Stack development boards
Pinout
VCC: Power supply (3.3V - 5V)
 GND: Ground
 SCL: I2C clock signal
 SDA: I2C data signal
Code Examples
Example 1: Basic TVOC and eCO2 Measurement
This example demonstrates how to use the M5Stack TVOC/eCO2 Gas Unit (SGP30) to measure TVOC and eCO2 levels using an M5Stack development board.
```c++
#include <M5Stack.h>
#include <Wire.h>
#define SGP30_ADDRESS 0x58
void setup() {
  M5.begin();
  Wire.begin();
  Serial.begin(115200);
// Initialize SGP30 sensor
  Wire.beginTransmission(SGP30_ADDRESS);
  Wire.write(0x00);
  Wire.write(0x03); // Init command
  Wire.endTransmission();
  delay(10);
}
void loop() {
  uint16_t tvoc, eco2;
// Read TVOC and eCO2 values
  Wire.beginTransmission(SGP30_ADDRESS);
  Wire.write(0x00);
  Wire.write(0x05); // Read TVOC command
  Wire.endTransmission();
  Wire.requestFrom(SGP30_ADDRESS, 2);
  tvoc = Wire.read() << 8 | Wire.read();
Wire.beginTransmission(SGP30_ADDRESS);
  Wire.write(0x00);
  Wire.write(0x06); // Read eCO2 command
  Wire.endTransmission();
  Wire.requestFrom(SGP30_ADDRESS, 2);
  eco2 = Wire.read() << 8 | Wire.read();
Serial.print("TVOC: ");
  Serial.print(tvoc);
  Serial.println(" ppb");
  Serial.print("eCO2: ");
  Serial.print(eco2);
  Serial.println(" ppm");
delay(1000);
}
```
Example 2: Air Quality Monitoring with Display
This example demonstrates how to use the M5Stack TVOC/eCO2 Gas Unit (SGP30) to display air quality data on an M5Stack development board with an LCD display.
```c++
#include <M5Stack.h>
#include <Wire.h>
#define SGP30_ADDRESS 0x58
void setup() {
  M5.begin();
  Wire.begin();
  Serial.begin(115200);
  M5.Lcd.begin();
// Initialize SGP30 sensor
  Wire.beginTransmission(SGP30_ADDRESS);
  Wire.write(0x00);
  Wire.write(0x03); // Init command
  Wire.endTransmission();
  delay(10);
}
void loop() {
  uint16_t tvoc, eco2;
  char airQuality[20];
// Read TVOC and eCO2 values
  Wire.beginTransmission(SGP30_ADDRESS);
  Wire.write(0x00);
  Wire.write(0x05); // Read TVOC command
  Wire.endTransmission();
  Wire.requestFrom(SGP30_ADDRESS, 2);
  tvoc = Wire.read() << 8 | Wire.read();
Wire.beginTransmission(SGP30_ADDRESS);
  Wire.write(0x00);
  Wire.write(0x06); // Read eCO2 command
  Wire.endTransmission();
  Wire.requestFrom(SGP30_ADDRESS, 2);
  eco2 = Wire.read() << 8 | Wire.read();
// Calculate air quality index
  if (tvoc < 100) {
    strcpy(airQuality, "Excellent");
  } else if (tvoc < 200) {
    strcpy(airQuality, "Good");
  } else if (tvoc < 400) {
    strcpy(airQuality, "Fair");
  } else {
    strcpy(airQuality, "Poor");
  }
// Display air quality data
  M5.Lcd.clear(BLACK);
  M5.Lcd.setTextSize(2);
  M5.Lcd.setCursor(10, 10);
  M5.Lcd.println("Air Quality:");
  M5.Lcd.println(airQuality);
  M5.Lcd.print("TVOC: ");
  M5.Lcd.print(tvoc);
  M5.Lcd.println(" ppb");
  M5.Lcd.print("eCO2: ");
  M5.Lcd.print(eco2);
  M5.Lcd.println(" ppm");
delay(1000);
}
```
These examples demonstrate the basic functionality of the M5Stack TVOC/eCO2 Gas Unit (SGP30) and its ability to measure TVOC and eCO2 levels. You can modify and expand these examples to suit your specific application requirements.