Arduino Code

Install Adafruit_SGP30 library

To begin reading sensor data, you will need to install the Adafruit_SGP30 library (code on our github repository). It is available from the Arduino library manager so we recommend using that.

From the IDE open up the library manager...

And type in adafruit sgp30 to locate the library. Click Install

Load Demo

Open up File->Examples->Adafruit_SGP30->sgp30test and upload to your microcontroller wired up to the sensor

Then open up the serial console at 9600 baud, you'll see the serial number printed out - this is a unique 48-bit number burned into each chip. Since you may want to do per-chip calibration, this can help keep your calibration detail separate

The first 10-20 readings will always be TVOC 0 ppb eCO2 400 ppm. That's because the sensor is warming up, so it will have 'null' readings.

After a few seconds, you will see the TVOC and eCO2 readings fluctuate:

Every minute or so you'll also get a Baseline value printed out. More about that later!

You can take a bit of alcohol on a swap and swipe it nearby to get the readings to spike

That's it! The sensor pretty much only does that - all the calculations for the TVOC and eCO2 are done within the sensor itself, no other data is exposed beyond the 'baseline' values

Baseline Set & Get

All VOC/gas sensors use the same underlying technology: a tin oxide element that, when exposed to organic compounds, changes resistance. The 'problem' with these sensors is that the baseline changes, often with humidity, temperature, and other non-gas-related-events. To keep the values coming out reasonable, you'll need to calibrate the sensor. To make that easy, SGP lets you query the 'baseline calibration readings' from the sensor with code like this:

uint16_t TVOC_base, eCO2_base;
sgp.getIAQBaseline(&eCO2_base, &TVOC_base);

This will grab the two 16-bit sensor calibration words and place them in the variables so-named.

You should store these in EEPROM, FLASH or hard-coded. Then, next time you start up the sensor, you can pre-fill the calibration words with sgp.setIAQBaseline(eCO2_baseline, TVOC_baseline);

Last updated on 2018-01-12 at 01.45.10 PM Published on 2018-01-17 at 05.30.16 PM