Introduction

The SGP40 Air Quality sensor adopts the new SGP40 digital VOC sensor chip launched by the well-known Sensirion. Based on the Sensirion’s CMOSens® technology, the SGP40 offers a complete sensor system on a single chip, a temperature-controlled micro-hotplate and a humidity-compensated indoor air quality signal. In combination with Sensirion’s powerful VOC algorithm, the sensor signal can be directly used to evaluate indoor air quality. It features low power(2.6mA), fast response(2s) and small body. The data from the sensor can be directly used to evaluate air quality without calibration. Integrated with easy-to-connect Gravity interface, this Gravity 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.

Note: VOC index is obtained by converting the detected ethanol equivalent in air.

VOC Index

1

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

2

Features

Application

Specification

1

Board Overview

Pinout

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

Tutorial for Arduino

The sensor adopts easy-to-use standard Gravity I2C interface. Connect the sensor to your mainboard as the diagram. The product features short preheat time and 10s algorithms.

Note: The sensor will output more accurate and stable VOC data after using for 5 minutes.

Requirements

/**
   * @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

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 (http://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author [yangfeng]<feng.yang@dfrobot.com>
 * @version  V1.0
 * @date  2020-12-18
 * @get from https://www.dfrobot.com
 * @url  https://github.com/DFRobot/DFRobot_SGP40
 */
#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.begin(115200);
  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");
    delay(1000);
  }
  Serial.println("----------------------------------------------");
  Serial.println("sgp40 initialized successfully!");
  Serial.println("----------------------------------------------");
  /* 
   * 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 = ");
  Serial.println(index);
  delay(1000);
}

Result 1

Tutorial for Raspberry Pi

Connection Diagram

Connection

Driver Installation

  1. Enable 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 https://github.com/DFRobot/DFRobot_SGP40

Run Sample Code

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

Result

Print the VOC index once every 1 second.

Result 2

FAQ

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

More Documents

DFshopping_car1.png Get Gravity: SGP40 Air Quality Sensor from DFRobot Store or DFRobot Distributor.