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
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 |
The sensor provides the change of air quality trend, and the algorithm will continuously adjust the baseline of typical air according to historical data. The longer the sensor is used, the better the sensitivity and accuracy of trend and change.
In the normal air environment, the sensor can obtain the accurate VOC index immediately after use; in the heavily-polluted environment, the sensor can obtain the accurate VOC index after use for about 1 hour. It is recommended to integrate it into the long-term indoor projects.
For more information about VOC index, please refer to: SGP40 VOC Index for Experts.pdf
Features
- Ultra-low Power Consumption(2.6mA)
- Built-in Temperature and Humidity Compensation, no need to calibrate
- VOC Index for direct Air Quality Indication
Application
- Indoor Air Quality Monitoring
- Air Purifiers
- Kitchen Hoods
- Demand-controlled Ventilation
- Thermostats
Specification
- Power Supply: 3.3V~5V
- Operating Current: 2.6mA
- Preheat Time: 10S
- Response Time: 2S
- Communication: I2C
- I2C Address: 0x59
- Operating Temperature Range: -10℃~50℃
- Storage Temperature Range: 5℃~30℃
- Operating Humidity Range: 0%RH~90%RH
- VOC Index: 0-500
- Measuring Range: 0-1000ppm of Ethanol Equivalent
- Dimension: 20×22mm/ 0.79×0.87”
Board Overview
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
- Hardware
- DFRduino UNO R3 (or similar) x 1
- Gravity: SGP40 Air Quality Sensor x1
- Jumper wires
- Software
- Arduino IDE
- Download and install the SGP40 Library and Sample Code (About how to install the library?)
- Main API Function List
/**
* @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 (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);
}
Tutorial for Raspberry Pi
- Hardware
- Raspberry Pi B4(or similar) x 1
- Gravity: SGP40 Air Quality Sensor x1
- Jumper wires
Connection Diagram
Driver Installation
- 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.
- 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
- 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
Connect the sensor with your Raspberry Pi board as the diagram shown above. I2C default address: 0x59.
Input the following commands into the terminal and run the codes:
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.
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.