Using the SGP40 with Arduino is a simple matter of wiring up the sensor to your Arduino-compatible microcontroller, installing the Adafruit SGP40 library we've written, and running the provided example code.

I2C Wiring

Use this wiring if you want to connect via I2C interface. The default I2C address for the SGP40 is 0x59

Here is how to wire up the sensor using one of the STEMMA QT connectors. The examples show a Metro but wiring will work the same for an Arduino or other compatible board.

  • Connect board VIN (red wire) to Arduino 5V if you are running a 5V Arduino (Uno, etc.). If your Arduino is 3V, connect to that instead.
  • Connect board GND (black wire) to Arduino GND
  • Connect board SCL (yellow wire) to Arduino SCL
  • Connect board SDA (blue wire) to Arduino SDA

Here is how to wire the sensor to a board using a solderless breadboard:

  • Connect board VIN (red wire) to Arduino 5V if you are running a 5V Arduino (Uno, etc.). If your Arduino is 3V, connect to that instead.
  • Connect board GND (black wire) to Arduino GND
  • Connect board SCL (yellow wire) to Arduino SCL
  • Connect board SDA (blue wire) to Arduino SDA

Library Installation

You can install the Adafruit SGP40 library for Arduino using the Library Manager in the Arduino IDE.

Click the Manage Libraries ... menu item, search for Adafruit SGP40 , and select the Adafruit SGP40 library:

Follow the same process for the Adafruit BusIO library.

Finally follow the same process for the Adafruit SHT31 Library:

Load Basic Example

Open up File -> Examples -> Adafruit SGP40 -> sgp40test

After opening the demo file, upload to your Arduino wired up to the sensor. Once you upload the code, you will see the Raw measurement values being printed when you open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, similar to this:

These measurements rare the raw values from the VOC-sensitive resistor. They aren't quite 'resistance' but they're related. The number is affected by VOC as well as humidity.

VOC Index Example Code

Next we'll use the SGP40 along with a SHT31 humidity sensor to calculate the VOC Index, with the SHT31 providing humidity measurements to allow the SGP40 to correct for it

For this example, you'll need to add a SHT31 humidity sensor to the I2C bus, connected along with the SGP40 to the Metro/Arduino. 

Simply add connections for VIN, GND, SCL, and SDA between the SGP40 and SHT31 as seen above. Alternately the SHT31 can be wired directly to the Metro's I2C connections.

With the wiring done, open up File -> Examples -> Adafruit SGP40 -> sgp40_voc

After opening the demo file, upload to your Arduino wired up to the sensor. Once you upload the code, you will see the raw measurement and VOC Index values being printed when you open the Serial Monitor (Tools->Serial Monitor) at 115200 baud, similar to this:

It may take several minutes for the Voc index to start changing as it calibrates the baseline readings. We use the Sensirion SGP40 algorithm found here

This guide was first published on Dec 30, 2020. It was last updated on Dec 30, 2020.

This page (Arduino) was last updated on Oct 15, 2021.

Text editor powered by tinymce.