CircuitPython library for the Adafruit SGP40 Air Quality Sensor / VOC Index Sensor Breakouts

  • Author(s): Bryan Siepert

    Keith Murray

Implementation Notes


Software and Dependencies:

class adafruit_sgp40.SGP40(i2c, address=89)

Class to use the SGP40 Air Quality Sensor Breakout


address (int) – The I2C address of the device. Defaults to 0x59

Quickstart: Importing and using the SGP40 temperature sensor

Here is one way of importing the SGP40 class so you can use it with the name sgp. First you will need to import the libraries to use the sensor

import board
import adafruit_sgp40
# If you have a temperature sensor, like the bme280, import that here as well
# import adafruit_bme280

Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA
sgp = adafruit_sgp40.SGP40(i2c)
# And if you have a temp/humidity sensor, define the sensor here as well
# bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

Now you have access to the raw gas value using the raw attribute. And with a temperature and humidity value, you can access the class function measure_raw() for a humidity compensated raw reading

raw_gas_value = sgp.raw
# Lets quickly grab the humidity and temperature
# temperature = bme280.temperature
# humidity = bme280.relative_humidity
# compensated_raw_gas = sgp.measure_raw(temperature=temperature,
# relative_humidity=humidity)
# temperature = temperature, relative_humidity = humidity)


The operational range of temperatures for the SGP40 is -10 to 50 degrees Celsius and the operational range of relative humidity for the SGP40 is 0 to 90 % (assuming that humidity is non-condensing).

Humidity compensation is further optimized for a subset of the temperature and relative humidity readings. See Figure 3 of the Sensirion datasheet for the SGP40. At 25 degrees Celsius, the optimal range for relative humidity is 8% to 90%. At 50% relative humidity, the optimal range for temperature is -7 to 42 degrees Celsius.

Prolonged exposures outside of these ranges may reduce sensor performance, and the sensor must not be exposed towards condensing conditions at any time.

For more information see: and


Reset the sensor to it’s initial unconfigured state and configure it with sensible defaults so it can be used

measure_raw(temperature=25, relative_humidity=50)

A humidity and temperature compensated raw gas value which helps address fluctuations in readings due to changing humidity.

  • temperature (float) – The temperature in degrees Celsius, defaults to 25

  • relative_humidity (float) – The relative humidity in percentage, defaults to 50

The raw gas value adjusted for the current temperature (c) and humidity (%)

property raw

The raw gas value