

The SGP40, manufactured by DFRobot, is a digital gas sensor designed for indoor air quality monitoring. It is capable of detecting a wide range of volatile organic compounds (VOCs) and provides a digital signal output, making it easy to integrate into various applications. The sensor is ideal for use in air purifiers, HVAC systems, and other devices that monitor or improve indoor air quality. Its compact design and robust performance make it a popular choice for both hobbyists and professionals.








Below are the key technical details of the SGP40 sensor:
| Parameter | Value |
|---|---|
| Supply Voltage | 1.8V to 3.6V |
| Interface | I²C |
| Operating Temperature | -10°C to +50°C |
| Humidity Range | 0% to 90% RH (non-condensing) |
| Power Consumption | 2.6 mA (typical) |
| Measurement Range | 0 to 1,000 ppm (VOC Index) |
| Output | Digital (VOC Index) |
| Dimensions | 2.44 mm × 2.44 mm × 0.85 mm |
The SGP40 sensor has a simple pinout for easy integration. Below is the pin configuration:
| Pin Name | Description |
|---|---|
| VDD | Power supply (1.8V to 3.6V) |
| GND | Ground |
| SDA | I²C data line |
| SCL | I²C clock line |
| ADDR | I²C address selection (connect to GND or VDD) |
To use the SGP40, connect it to a microcontroller such as an Arduino UNO via the I²C interface. Below is a typical wiring setup:
Below is an example of how to interface the SGP40 with an Arduino UNO to read VOC data:
#include <Wire.h>
// I2C address of the SGP40 sensor
#define SGP40_ADDRESS 0x59
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Start serial communication for debugging
// Initialize the sensor
Serial.println("Initializing SGP40...");
if (!initializeSGP40()) {
Serial.println("Failed to initialize SGP40. Check connections.");
while (1); // Halt execution if initialization fails
}
Serial.println("SGP40 initialized successfully.");
}
void loop() {
uint16_t vocIndex = readVOCIndex(); // Read VOC index from the sensor
Serial.print("VOC Index: ");
Serial.println(vocIndex); // Print the VOC index to the serial monitor
delay(1000); // Wait 1 second before the next reading
}
// Function to initialize the SGP40 sensor
bool initializeSGP40() {
Wire.beginTransmission(SGP40_ADDRESS);
// Send a dummy command to check if the sensor responds
Wire.write(0x20); // Example command (refer to the datasheet for actual commands)
Wire.write(0x08);
return (Wire.endTransmission() == 0); // Return true if the sensor responds
}
// Function to read VOC index from the SGP40 sensor
uint16_t readVOCIndex() {
Wire.beginTransmission(SGP40_ADDRESS);
Wire.write(0x26); // Example command to read VOC index
Wire.write(0x0F);
Wire.endTransmission();
delay(10); // Wait for the sensor to process the command
Wire.requestFrom(SGP40_ADDRESS, 2); // Request 2 bytes of data
if (Wire.available() == 2) {
uint8_t msb = Wire.read(); // Most significant byte
uint8_t lsb = Wire.read(); // Least significant byte
return (msb << 8) | lsb; // Combine bytes into a 16-bit value
}
return 0; // Return 0 if no data is available
}
0x20, 0x08, 0x26, 0x0F) with the actual commands from the SGP40 datasheet.0x59) matches the sensor's default or configured address.No Response from the Sensor
Inaccurate Readings
I²C Communication Errors
Can the SGP40 detect specific gases?
What is the VOC Index?
Can I use the SGP40 with a 5V microcontroller?
By following this documentation, you can successfully integrate the SGP40 into your projects and monitor indoor air quality with ease.