The value stored for the on-chip humidity compensation will remain static until a new value is sent or the SGP30 is
reset. We have included an option to send the letter "H" (upper or lower case) through your serial monitor to adjust
the humidity compensation value to a new reading from the SHTC3 to avoid having to reset the circuit.
To update the compensation value, open the Serial Monitor at any time after initialization and set the baud to 9600.
Type in "H", hit enter and the code will reset the humidity compensation value using an updated reading from the
SHTC3. The code will also print out the new value in g/m and then resume taking CO and TVOC readings from
the SGP30. The code below shows that if statement and how the humidity value is calculated from the SHTC3's
temperature and humidity data:
if (Serial.available())
{
char ch = Serial.read();
if (ch == 'H' || ch == 'h')
{
SHTC3_Status_TypeDef result = hSensor.update();
delay(190);
// Measure Relative Humidity from the Si7021
float humidity = hSensor.toPercent();
//Measure temperature (in C) from the Si7021
float temperature = hSensor.toDegC();
//Convert relative humidity to absolute humidity
double absHumidity = RHtoAbsolute(humidity, temperature);
//Convert the double type humidity to a fixed point 8.8bit number
uint16_t sensHumidity = doubleToFixedPoint(absHumidity);
//Set the humidity compensation on the SGP30 to the measured value
//If no humidity sensor attached, sensHumidity should be 0 and sensor will use default
mySensor.setHumidity(sensHumidity);
Serial.print("Absolute Humidity compensation value set to: ");
Serial.print(absHumidity);
Serial.println("g/m^3 ");
delay(100);
Resources and Going Further
That's all for this guide. Hopefully after reading this and following along with the Arduino examples you are ready
to integrate your SparkFun Air Quality Sensor -SGP30 (Qwiic) into your next air quality monitoring project!
For more information, take a look at the resources below:
Schematic (PDF)
Eagle Files (ZIP)
Board Dimensions (PNG)
Arduino Library GitHub Repository
Hardware GitHub Repository
SGP30 Datasheet
Looking to add more sensors to your indoor air quality project or simply want more weather and environmental-
related tutorials? Check these out:
3
2
Need help?
Do you have a question about the SGP30 and is the answer not in the manual?