Overview
The sgp30 node reads air quality data from the Sensirion SGP30 multi-pixel gas sensor
via I2C. It provides equivalent CO2, Total VOC, raw hydrogen, and raw ethanol measurements. The SGP30 features
on-chip humidity compensation and baseline management for long-term stability in smart ventilation and air quality systems.
Wiring (I2C)
Connection
VCC → 3.3V
GND → GND
SDA → GPIO 2 (Pin 3)
SCL → GPIO 3 (Pin 5)
Calibration
Initial 15-second initialization period
Save baseline every hour for best accuracy
Restore baseline on power cycle
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| bus | number | 1 | I2C bus number |
| address | number | 0x58 | I2C address (fixed at 0x58) |
| baseline | object | — | Saved baseline (eCO2 and TVOC values) |
| humidityCompensation | boolean | true | Enable humidity compensation from external sensor |
| interval | number | 1000 | Reading interval in milliseconds |
Output
{
"payload": {
"eCO2": 520,
"TVOC": 18,
"H2": 13243,
"ethanol": 18745
},
"eCO2": 520,
"TVOC": 18,
"rawH2": 13243,
"rawEthanol": 18745,
"timestamp": 1640000000000
} Example: Smart Ventilation Control
Automatically control exhaust fans and fresh air intake based on real-time air quality readings.
// Function node: Ventilation speed controller
var eCO2 = msg.eCO2;
var tvoc = msg.TVOC;
// Fan speed zones (PWM 0-100%)
var fanSpeed = 0;
if (eCO2 > 2000 || tvoc > 500) {
fanSpeed = 100; // Maximum ventilation
} else if (eCO2 > 1200 || tvoc > 200) {
fanSpeed = 75; // High
} else if (eCO2 > 800 || tvoc > 100) {
fanSpeed = 50; // Medium
} else if (eCO2 > 600) {
fanSpeed = 25; // Low
}
// Gradual transitions to avoid sudden changes
var current = flow.get('fanSpeed') || 0;
var step = 5;
if (fanSpeed > current) {
current = Math.min(fanSpeed, current + step);
} else if (fanSpeed < current) {
current = Math.max(fanSpeed, current - step);
}
flow.set('fanSpeed', current);
msg.payload = {
eCO2: eCO2,
tvoc: tvoc,
fanSpeed: current,
mode: current === 0 ? "off" : "running"
};
return msg; Example: Baseline Persistence
Save and restore the sensor baseline to maintain calibration accuracy across reboots.
// Function node: Save baseline every hour
var baseline = msg.baseline;
var lastSave = flow.get('lastBaselineSave') || 0;
var now = Date.now();
// Save baseline every hour after 12h initial period
var uptime = flow.get('sensorUptime') || now;
var runHours = (now - uptime) / 3600000;
if (runHours > 12 && (now - lastSave) > 3600000) {
flow.set('lastBaselineSave', now);
// Store to persistent context
global.set('sgp30_baseline', {
eCO2: baseline.eCO2,
TVOC: baseline.TVOC,
savedAt: now
});
msg.payload = "Baseline saved: " + JSON.stringify(baseline);
return msg;
}
return null; Use Cases
Demand-Controlled Ventilation
Adjust airflow based on actual occupancy and VOC levels
Air Purifier Control
Trigger air purifiers when TVOC levels spike
Smart Home AQI
Display air quality index on home dashboards
Industrial Monitoring
Detect solvent or chemical vapors in workshops