Labs / Electronic modules

GraftSense - An Open Version Air Quality Monitoring Module Based on SGP40

Author: Li Zisheng · Source: FreakStudio open documentation, v1.1 · License: CC BY 4.0 · Driver code (sensors/sgp40_driver): MIT License

Contents
SGP40
SGP40 LED1 R1/R2/R6 C1/C2/C3/C4/C5/C6/C7 U1 U3 SGP40-Based V1.0.0

I. Module Introduction

Air quality monitoring module based on SGP40, which adopts the SGP40 gas sensor solution, outputs air quality signals via the I2C interface. It can detect volatile organic compounds (VOC) and output equivalent CO₂(eCO₂) and VOC index. Equipped with an LDO voltage regulator circuit, power filtering and indicator circuit, this module operates on 3.3V power supply, supports low-power operation, and is applicable to scenarios such as indoor air quality monitoring, smart homes, and fresh air purification equipment.

II. Introduction to Main Chips

SGP40 is a low-power digital VOC sensor launched by Sensirion. Based on CMOSens® technology, it features an I²C interface for output, with built-in VOC algorithm and temperature & humidity compensation. It can output a VOC index ranging from 0 to 500, and is applied for indoor air quality monitoring.

2.1 Chip Overview

SGP40 2.6mA 2.44 0.85mm

SGP40 is an indoor air quality sensor based on MOx launched by Sensirion. Adopting CMOSens® technology, it features an I²C digital interface and temperature & humidity compensation. With low power consumption and an ultra-compact package of 2.44×2.44×0.85mm³, it delivers long-term stable VOC index output, which is suitable for scenarios such as air purifiers and intelligent ventilation systems.

2.2 Pin Definition

SGP40 6

SGP40 adopts a 6-pin DFN package, in which VDD and VDDH are power supply pins that shall be connected to the same power source with a decoupling capacitor;VSS is the ground pin;SDA / SCL are I²C communication pins requiring external pull-up resistors. Pin 4 has no electrical function and is recommended to be grounded, and the central pad also needs to be soldered to enhance mechanical stability.

2.3 Functional Block Diagram

SGP40

SGP40 uses the internal MEMS unit, where a heating controller regulates the temperature of the hot plate to drive the reaction between MOx material and VOC gases. The generated signal is processed by the analog front end, then sent to the humidity-compensated Digital Signal Processing unit, and finally the processed air quality data is output via the I²C interface.

2.4 Performance Parameters

SGP40 25 50 3.3V

SGP40 defines the key parameters of the sensor under the conditions of 25°C, 50% RH, and 3.3V power supply with ethanol as the test gas: the output signals include a VOC index ranging from 0 to 500 and a raw value ranging from 0 to 65535; the measurement range for ethanol is up to 0-1000ppm, with the specified range being 0.3-30ppm; the VOC index deviations for inter-device consistency and repeatability are both ≤±15, and the detection limit is < 0.05ppm;Response time T60 < 30s, power-on stabilization time < 60s; in terms of sensitivity, the original signal drops by approximately 870 ticks when the ethanol concentration doubles. Regarding the sampling interval, VOC index is 1s, and the original value ranges from 0.5 to 10s.

SGP40 25 50 3.3V 2 53.47

SGP40 under the conditions of 25°C, 50% RH, and 3.3V power supply, the typical response curves to ethanol, toluene, and ISO standard mixed gas show that the original sensor signal decreases approximately linearly with increasing VOC concentration, and there are differences in response sensitivity to different VOC species.

SGP40 1.7 3.6V 34 0.4ms

SGP40 has a supply voltage range of 1.7–3.6V (typical: 3.3V), a typical operating current of 2.6mA at 3.3V, a typical standby current of 34μA at 3.3V, and supports standard/fast mode I²C communication; its timing parameters specify a typical power-on/soft reset time of 0.4ms, and the maximum supported I²C clock frequency is 400kHz.

SGP40 0 90 10 50 1.5 30 80 5 3

SGP40 operates within a temperature range of -10 to 50°C and a humidity range of 0 to 90% RH (the green zone indicates the optimized humidity compensation area), with storage requirements of 5 to 30°C temperature and 0 to 80% RH humidity; operation or storage outside these ranges may impair performance or even cause damage.

SGP40 0.3 3.6V 40 70

SGP40 Operating limit conditions: The supply voltage VDD / VDDH ranges from -0.3 V to + 3.6 V; the operating temperature ranges from -20 ℃ to + 55 ℃, with humidity of 0~90%(non-condensing); the short-term storage temperature ranges from -40 ℃ to + 70 ℃, with humidity of 0~80%. It also specifies the ESD protection level (HBM 2 kV, CDM 500 V) and latch-up current of 100 mA. Exceeding these limits may cause permanent damage.

2.5 Reference Circuit

SGP40 4.7 1 10k

SGP40 reference circuit connection is as shown in the above figure: the power supply terminal forms an RC decoupling network with a 4.7Ω resistor and a 1μF capacitor, which provides stable power for both the VDD and VDDH pins; the I²C communication pins SDA / SCL are externally connected with a pull-up resistor Rp (typically 10kΩ) to achieve standard communication level; the central pad and no-connect pins (n/a) are grounded to ensure stable operation and mechanical reliability of the sensor.

2.6 Chip Configuration

None.

SGP40 0x59 0x26

SGP40 I²C device address is 0x59, supporting both standard (100kHz) and fast (400kHz) modes. Commands during communication do not include CRC, while data transmission and reception both follow the format of "2-byte data + 1-byte CRC ". During measurement, the sensor will NACK the host's request, and the host can only read the result after the measurement is completed.

SGP40 8 2 4.7

SGP40 I²C communication CRC check and instruction set adopt an 8-bit CRC algorithm with polynomial 0x31 and initial value 0xFF, which only calculates the checksum for 2-byte data and provides a C language implementation example; meanwhile, it lists the core instructions, including raw signal measurement (0x26 0x0F), self-test (0x28 0x0E), heater off (0x36 0x15) and read serial number (0x36 0x82), and marks the parameter/response length and execution duration of each instruction.

2 1 50 65535ticks 25 175ticks sgp40_execute_self_test SGP40

SGP40 Core Measurement and Self-Test Commands: sgp40_measure_raw_signal command supports VOC raw signal measurement with/without humidity compensation; temperature and humidity values can be converted into parameters in the corresponding format (including CRC) and sent, and the command returns a 2-byte raw signal value plus a 1-byte CRC;sgp40_execute_self_test command triggers the built-in self-test to detect the status of the hot plate and MOX material, and also returns a 2-byte result plus a 1-byte CRC.

0x36 0x15 0x82 0x00 0x06 SGP40

SGP40 other I²C commands: The self-test command returns 0xD4 0xXX for pass, 0x4B 0xXX for fail; the sgp4x_turn_heater_off command turns off the heater to enter the low-power idle mode.

sgp4x_get_serial_number command reads the serial number and returns 3 sets of "2-byte data + 1-byte CRC ";

soft_reset instruction resets the device via a general call, returning it to the idle state.

2.8 PCB Routing Precautions

None.

III. Circuit Engineering

3.1 Circuit Source Engineering

To obtain the circuit source project, please follow the official account [Freak Embedded]

3.2 Module Usage Instructions

The schematic diagram of this module is shown below:

SCH_Schematic1_Air Quality Monitoring Module Based on SGP40_v1.0.0_2026-05-09.pdf 2.4 MB

SGP40 LED1 R6 C4 U3 C5 C1 C2 R2 R1

This module provides a IIC communication interface: it supports standard I2C communication rates, is compatible with 3.3V logic level, and can stably transmit the digital air quality signals collected by SGP40 including VOC, equivalent CO₂ and other parameters. It is applicable to scenarios such as indoor air quality monitoring, smart homes, and fresh air purification equipment, providing reliable environmental gas sensing data interaction capabilities for the system.

3.3 Application Experiment

Here, we use the GraftPort-RP2040 development board for testing, and the SGP40-based air quality monitoring module uses the I2C interface to communicate with the main controller.

Here, we first use the HY2.0-4P cable to connect the module to the GraftPort-RP2040 development board's I2C0 interface:

development board pins

Module Pins

Description

Pin 4

SDA

I2C data transmission line, corresponding to I2C0 's SDA

Pin 5

SCL

I2C clock signal line, corresponding to the I2C0 SCL

Here, we need to search for the relevant driver packages on uPyPI: https://upypi.net/zh/

106 sgp40_driver

Enter sgp40_driver to search, and the following will be displayed:

sgp40_driver 1.0.8 SGP40/SGP41 2026 05 29 SGP40

Click to copy the local installation command:

sgp40_driver SGP40/SGP41 1.0.0 2026 05 29 upypi.net/pkgs/sgp40_driver/1.0.0

Import the module driver library code via the mip tool. Below are the usage commands for the mpremote tool:

mpremote mip install https://upypi.net/pkgs/sgp40_driver/1.0.0

Import the Air Quality Monitoring Module Based on SGP40 - MicroPython Driver Code, then copy the following main.py code into our project:

# Python env   : MicroPython v1.23.0
# -*- coding: utf-8 -*-
# @Time    : 2026/05/06 07:00
# @Author  : FreakStudio
# @File    : main.py
# @Description : SGP40/SGP41 air quality sensor driver test
# @License : MIT

# ======================================== Import Modules =========================================

import time
from machine import Pin, SoftI2C
from sensor_pack_2.bus_service import I2cAdapter
from sgp4Xmod import SGP4X

# ======================================== Global Variables ============================================

TARGET_SENSOR_ADDRS = [0x59]
I2C_SCL_PIN = 5
I2C_SDA_PIN = 4
I2C_FREQ = 100_000
SENSOR_ID = 0          # 0=SGP40, 1=SGP41

# ======================================== Functions ============================================

# ======================================== Custom Classes ============================================

# ======================================== Initialization ==========================================

time.sleep(3)
print("FreakStudio: SGP40/SGP41 air quality sensor test")

# ========================================  Main Program  ============================================

if __name__ == '__main__':
    i2c_bus = SoftI2C(sda=Pin(I2C_SDA_PIN), scl=Pin(I2C_SCL_PIN), freq=I2C_FREQ)

    devices_list = i2c_bus.scan()
    print("START I2C SCANNER")

    if not devices_list:
        raise SystemExit("I2C scan found no devices")
    print("i2c devices found:", len(devices_list))

    sensor = None
    for device in devices_list:
        if device in TARGET_SENSOR_ADDRS:
            print("I2C address:", hex(device))
            try:
                sensor = SGP4X(I2cAdapter(i2c_bus), address=device, sensor_id=SENSOR_ID)
                print("Sensor initialization successful")
                break
            except Exception as e:
                print("Sensor init failed:", e)

    if sensor is None:
        raise SystemExit("No target sensor found on I2C bus")

    try:
        sn = sensor.get_id()
        print("Serial number: 0x%04X 0x%04X 0x%04X" % (sn.word_0, sn.word_1, sn.word_2))

        result = sensor.execute_self_test()
        print("Self test: %s (0x%04X)" % ("PASS" if result == 0xD400 else "FAIL", result))

        if SENSOR_ID == 1:
            print("Conditioning SGP41 for 10s...")
            for _ in range(10):
                val = sensor.execute_conditioning(rel_hum=50, temperature=25)
                print("Conditioning VOC raw:", val.VOC)
                time.sleep_ms(1000)

        print("Starting measurement loop (Ctrl+C to stop)...")
        while True:
            val = sensor.measure_raw_signal(rel_hum=50, temperature=25)
            if SENSOR_ID == 1:
                print("VOC raw: %d  NOx raw: %d" % (val.VOC, val.NOx))
            else:
                print("VOC raw:", val.VOC)
            time.sleep_ms(1000)

    except KeyboardInterrupt:
        print("Program interrupted by user")
    finally:
        sensor.deinit()
        print("Sensor deinitialized")

Burn the code, open the terminal, and the output is as follows:

SGP40 I2C

The SGP40 VOC sensor features normal I2C communication and initialization, passes the self-test, and can stably output raw VOC data; the value rises from the initial value and then fluctuates stably, with fixed temperature and humidity compensation parameters and normal working response.

IV. Drivers

sgp40_driver-1.0.0.zip 23 KB

None.

VI. Revision History

Document Version

Date of Revision

Modifier

Modify Content

v1.0

2026-05-09

Zero High-Luck

Initialize the document

v1.1

2026-06-06

Xin Ruili

Create an open version of the document based on the internal document version v1.0.

VII. Relevant Materials

7.1 Chip Datasheet

SGP40.pdf 852 KB

7.2 Unique Icons for PCB Silk Screen

7.2