Air Quality Sensor - SGP40 (Qwiic) Hookup Guide

Contributors: El Duderino, MAKIN-STUFF
Favorited Favorite 0

Arduino Example

The SGP40 Arduino Library includes a single example demonstrating how to get the processed VOC Index data from the sensor. Let's take a closer look at this example.

Example 1 - Get VOC Index

Open this example by navigating to File > Examples > SparkFun SGP40 Arduino Library > Example1_GetVOCIndex. Next, open the Tools menu and select the Board (in our case, SparkFun RedBoard) and the Port the board enumerated on.

Upload the code and open the Arduino Serial Monitor with the baud set to 115200. The code starts both the Wire and Serial ports and initializes the SGP40 on the I2C bus. If the SGP40 is not detected at the default address, the code will print out SGP40 not detected. Check connections. Freezing... and will stop. If this error prints, double check the connections between the breakout and development board and reset it.

After initalizing, the code calls the getVOCIndex(); function and prints out the value every second. The SGP40 takes about 30 to 60 seconds to warm up and return valid VOC readings. The printed data starts at "0" and increases for about a minute as it acclimates to the room and stabilizes around 100 VOC index. Also, the SGP40 refers to VOC Index readings from the history of the room over the past 24 hours so the longer the sensor remains running in the room, the more accurate the data becomes.

Try creating VOC events by putting something like isopropyl alcohol or a permanent marker near the sensor and then pull it away after a few seconds. The VOC Index should rise significantly depending on the intensity of the event and after a couple of minutes the output should drop back towards 100 as the gases dissipate.