SGP40 Air Quality VOC Sensor Breakout Arduino Wiki - DFRobot


As the next generation of SGP30, the SGP40 VOC sensor from Sensirion features long-term and stable supply available (Sensirion 10 years plan), extremely low power consumption(average as low as 2.6mA/3.3V), fast start(<60s), and no need to calibrate. Most importantly, the raw signal from the SGP40 is processed using their algorithm to give an overall "air quality" value from 0 to 500.
Similar to human nose, SGP40 reflects the change of indoor VOC within a period of time. With compact and small body, this Breakout SGP40 Air Quality sensor is very suitable for indoor projects that will be used for a long time, such as refitting air purifiers, kitchen hoods, etc. Besides, we provide you with C and Python libraries for using with different main-controllers.

VOC Index


VOC Index Air Quality Suggested Action
0-100 Excellent No measures needed
100-200 Good No measures needed
200-300 Lightly Polluted Ventilation suggested
300-400 Moderately Polluted Increase ventilation with clean air
400-500 Heavily Polluted Optimize ventilation





Board Overview

Num Label Description
1 VCC +
2 GND -
3 SCL I2C Clock line
4 SDA I2C Data line

Tutorial for Arduino

The product uses standard I2C wiring, which very easy to use. Connect the sensor with a main-board(UNO or others).

warning_yellow.png NOTE: the sensor will output more accurate and stable VOC index data after using for 5 minutes.


   * @brief  Initialization function
   * @param duration Warm-up time
   * @return return true succeed ;return false failed.
  bool begin(uint32_t duration = 10000);

   * @brief  Set the temperature and humidity
   * @param  relativeHumidityRH  Current environmental relative humidity value, range 0-90, unit: %RH
   * @param  temperatureC  Current ambient temperature, range -10~50, unit: °C
  void setRhT(float relativeHumidity = 50,float temperatureC=25);

   * @brief  Measure VOC index after humidity compensation
   * @note   VOC index can indicate the quality of the air directly. The larger the value, the worse the air quality.
   * @note       0-100,no need to ventilate, purify
   * @note       100-200,no need to ventilate, purify
   * @note       200-400,ventilate, purify
   * @note       400-500,ventilate, purify intensely
   * @return The VOC index measured, ranged from 0 to 500
  uint16_t getVoclndex(void);

Connection Diagram


Sample Code - Read VOC Index

Serial print the currect VOC index after the sensor is powered on for 10s. The chip has on-chip compensation, so users can use it without calibration. If you need to get a more accurate value, you can open the setrht() function and fill in the RH% of the ambient relative humidity value obtained by the external humidity detection sensor and the ° C of the ambient temperature detected by the temperature sensor.

 * @file getVocIndex.ino
 * @brief Read the environmental VOC index.  Range: 0-500;
 * @n Experimental phenomena: read environmental VOC index once per second and print the value in serial port
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (
 * @licence     The MIT License (MIT)
 * @author [yangfeng]<>
 * @version  V1.0
 * @date  2020-12-18
 * @get from
 * @url
#include <DFRobot_SGP40.h>

 * Method 1: pass in the specified I2C object address 
 * #include <Wire.h>
 * DFRobot_SGP40    mySgp40(&Wire);

 * Method 2: use the default I2C object&Wire
 * I2C Default Address:0x59

//#include <Wire.h>
//DFRobot_SGP40    mySgp40(&Wire);
DFRobot_SGP40    mySgp40;

void setup() {
  Serial.println("sgp40 is starting, the reading can be taken after 10 seconds...");
   * Sensor preheat time: 10s
   * duration: init wait time. Unit: ms. It is suggested: duration>=10000ms
  while(mySgp40.begin(/*duration = */10000) !=true){
    Serial.println("failed to init chip, please check if the chip connection is fine");
  Serial.println("sgp40 initialized successfully!");
   * Set the relative humidity and temperature of current environment 
   * The sensor has internal temerpature & humidity calibration. For more accurate VOC index, please open the function setRhT().
   * relativeHumidity:ambient relative humidity, refer to the moisture content in air. Range:0-90, unit: %RH,e.g. 50%
   * temperatureC:ambient temperature. Range: -10~50, unit: °C, e.g. 20°C
  //mySgp40.setRhT(/*relativeHumidity = */ 50, /*temperatureC = */ 20);


void loop() {
   * Get VOC index 
   * VOC index can directly indicate the condition of air quality. The larger the value, the worse the air quality
   *    0-100,no need to ventilate,purify
   *    100-200,no need to ventilate,purify
   *    200-400,ventilate,purify
   *    400-500,ventilate,purify intensely
   * Return VOC index, range: 0-500
  uint16_t index = mySgp40.getVoclndex();

  Serial.print("vocIndex = ");



Tutorial for Raspberry Pi



Connection Raspberry Pi

Driver Installation

  1. Eable Raspberry Pi I2C. Skip this step if it is already enabled. Open the terminal, input the following commands:
pi@raspberrypi:~ $ sudo raspi-config

Select "5 Interfacing Options" with the up/down arrows, press "enter", then select "P5 I2C", click "YES". Restart the Raspberry Pi board.

  1. Install Python Dependent Library and git(Your Raspberry Pi board needs to access to the Internet). Skip this step if they have been installed already. Input the following commands into the terminal:
pi@raspberrypi:~ $ sudo apt-get update
pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git
  1. Download SGP40 Driver library. Input the following commands into the terminal:
pi@raspberrypi:~ $ cd Desktop/ pi@raspberrypi:~/Desktop $ git clone

Run Sample Code

pi@raspberrypi:~/Desktop $ cd /home/pi/Desktop/DFRobot_SGP40/Python/raspberrypi/examples/
pi@raspberrypi:~/Desktop/DFRobot_SGP40/Python/raspberrypi/examples $ python


Print the VOC index once every 1 second.

Result 2


For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents