A basic example to get you started reading TVOC and CO readings from the SGP30. To open this example,
2
navigate to File > Examples > SparkFun SGP30 Arduino Library > Example1_BasicReadings. Next, open the
Tools menu and select your board (in our case, Arduino Uno) and the correct Port your board enumerated on.
Upload the code, open the Arduino Serial Monitor and set your baud rate to 9600. If the sensor initialization returns
false, the code will print out "No SGP30 Detected. Check connections." via serial. That error will almost certainly
be the result of a bad connection to the SGP30. After successful initialization, it will start to print out TVOC and
CO readings. Take note that for the first 15 seconds after sensor power up or reset, the readings will be: CO :
2
2
400 ppm and TVOC : 0 ppb so if you are logging the data using, say, the OpenLog Artemis, you will want to
ignore these first 15 readings.
After the first 15 readings have passed, try breathing lightly near the sensor and you should see the CO readings
2
jump significantly from the 400 ppm baseline. These basic readings are good to get started and making sure your
sensor is connected and functioning, but for more accurate readings, you'll probably want to include a
compensation value from a humidity sensor like we demonstrate in Example 3 - Humidity.
Example 2 - Raw Signals
This example includes both the TVOC and CO readings from the SGP30 along with raw readings for ethanol and
2
H . The Ethanol and H values are primarily for internal processing on the SGP30 but you can use them for rough
2
2
measurements of both gases.
Open the example from the Examples menu as we did above and select Example2_RawSignals. Select your
Board and Port and upload the code. Open the Arduino Serial Monitor again and set your baud to 9600. You
should see readings for CO , TVOC, Raw H and Raw Ethanol every second.
2
2
Example 3 - Humidity
This example demonstrates how to pass humidity data from an external sensor (in this case, the SparkFun
Humidity Sensor Breakout - SHTC3 (Qwiic)) to modify the SGP30's humidity compensation with an actual absolute
humidity value. Passing an actual humidity value to the SGP30's humidity compensation will help increase the
accuracy and reliability of the sensor.
In order to use this example as is you will need to also have the SparkFun SHTC3 Arduino Library installed. With
both libraries installed, simply connect an SHTC3 Breakout to your Qwiic chain and upload the example to add a
humidity compensation value to your SGP30's readings!
This example initializes both sensors and, in the setup, takes a temperature and humidity reading from the
SHTC3. The code then converts those readings to absolute humidity, parses that into a fixed 8.8 bit value the
SGP30 can accept for humidity compensation and then sends that data to the SGP30 using the
setHumidity
function. After this value is set, the code runs through the primary routine of reading CO and TVOC values and
2
printing them over serial.
Need help?
Do you have a question about the SGP30 and is the answer not in the manual?