Skip to main content

tVOC Sensor(Built-in)

The built-in SGP40 sensor in the SenseCAP Indicator is a high-quality, reliable TVOC sensor that can be used in a wide range of applications to monitor indoor and outdoor air quality. It with a measurement range of 1-500 VOC Index Points.

TVOCs are a group of organic chemicals that are emitted as gases from a variety of sources, including building materials, cleaning products, and personal care products.

Example Code:

This example reads the value of the built-in SGP40 TVOC sensor through the IIC interface, and print it to the serial monitor.

Based on the following library:

Sensirion Arduino Core library

SGP40 TVOC sensor library

Transfer index library: Sensirion Gas Index Algorithm

Note: When using the built-in sensor, the sensor power must be enabled.

#include <Arduino.h>
#include <SensirionI2CSgp40.h>
#include <VOCGasIndexAlgorithm.h>
#include <Wire.h>

SensirionI2CSgp40 sgp40;
VOCGasIndexAlgorithm voc_algorithm;


//The built-in sensor needs to be powered on
void sensor_power_on(void) {
pinMode(18, OUTPUT);
digitalWrite(18, HIGH);
}

/************************ sgp40 tvoc ****************************/

void sensor_sgp40_init(void) {
uint16_t error;
char errorMessage[256];

sgp40.begin(Wire);

uint16_t serialNumber[3];
uint8_t serialNumberSize = 3;

error = sgp40.getSerialNumber(serialNumber, serialNumberSize);

if (error) {
Serial.print("Error trying to execute getSerialNumber(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
} else {
Serial.print("SerialNumber:");
Serial.print("0x");
for (size_t i = 0; i < serialNumberSize; i++) {
uint16_t value = serialNumber[i];
Serial.print(value < 4096 ? "0" : "");
Serial.print(value < 256 ? "0" : "");
Serial.print(value < 16 ? "0" : "");
Serial.print(value, HEX);
}
Serial.println();
}

uint16_t testResult;
error = sgp40.executeSelfTest(testResult);
if (error) {
Serial.print("Error trying to execute executeSelfTest(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
} else if (testResult != 0xD400) {
Serial.print("executeSelfTest failed with error: ");
Serial.println(testResult);
}
}

void sensor_sgp40_get(void) {
uint16_t error;
char errorMessage[256];
uint16_t defaultRh = 0x8000;
uint16_t defaultT = 0x6666;
uint16_t srawVoc = 0;

Serial.print("sensor sgp40: ");

error = sgp40.measureRawSignal(defaultRh, defaultT, srawVoc);
if (error) {
Serial.print("Error trying to execute measureRawSignal(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
} else {
Serial.print("SRAW_VOC:");
Serial.print(srawVoc);

int32_t voc_index = voc_algorithm.process(srawVoc);
Serial.print(", VOC Index: ");
Serial.println(voc_index);
}
}

/************************ setup & loop ****************************/

void setup() {
Serial.begin(115200);

sensor_power_on();

Wire.setSDA(20);
Wire.setSCL(21);
Wire.begin();

sensor_sgp40_init();
}

void loop() {
sensor_sgp40_get();
delay(5000);
}

"SRAW_VOC" refers to the sensor's raw signal output for VOCs, which is usually a voltage or resistance measurement that is proportional to the concentration of VOCs in the air.

"VOC Index" is a calculated value that is used as a way to represent the concentration of VOCs in the air in a more user-friendly format. The VOC index is a numerical value that ranges from 0 to 500, with higher values indicating higher concentrations of VOCs.

Tech Support

Don't worry, we've got you covered! Please visit our Seeed Official Discord Channel to ask your questions!

If you have large order or customization requirement, please contact [email protected]

Loading Comments...