Difference between revisions of "SGP40 VOC Sensor"

From Waveshare Wiki
Jump to: navigation, search
Line 25: Line 25:
 
==Codes==
 
==Codes==
 
*[https://www.waveshare.com/w/upload/6/62/SGP40_Voc_Sensor_code.7z Demo codes]
 
*[https://www.waveshare.com/w/upload/6/62/SGP40_Voc_Sensor_code.7z Demo codes]
 +
=FAQ=
 +
{{FAQ|Why does the serial port stop outputting any data or output 0 data after the power-on operation as described in the tutorial?
 +
|Please check whether the hardware connection is OK, especially since the cable sequence of SDA and SCL should not be reversed, and reconnect the sensor after powering off and re-run the program.
 +
||}}
 +
{{FAQ|What are the units of output?
 +
|The raw data output is the sensor ADC value, which can be converted to a VOC class index using the Sensirionu library, and cannot be converted to PPM units or PPB.
 +
||}}
 
{{Service00}}
 
{{Service00}}
 
</div>
 
</div>
 
</div>
 
</div>

Revision as of 01:57, 19 May 2023

SGP40 VOC Sensor
MQ-2-Gas-Sensor

SGP40 VOC Sensor
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

Introduction

The SGP40 VOC Sensor is a digital VOC (Volatile Organic Compounds) sensor module that incorporates SGP40, designed for air quality monitoring. It can be used to measure fire coal, natural gas emissions, cigarette/cooking smoke, and emissions from construction activity, decoration material, furniture, and home appliances, then generate digital signals for triggering air treatment devices. The SGP40 VOC Sensor is small in size for easy integration into air treatment devices and air quality monitors, definitely an ideal choice for learning air quality monitoring.

Feature

  • Incorporates SGP40, for measuring 0 ~ 1000 ppm of ethanol equivalents.
  • Features humidity-compensation and low heat dissipation, providing outstanding performance in all sorts of environments.
  • Digital I2C output, less interference.
  • Onboard voltage translator, compatible with 3.3V/5V operating voltage.

Specification

  • Sensor: SGP40
  • Measurement range: 0~1000 ppm of ethanol equivalents
  • Communication bus: I2C (constant address: 0x59)
  • Operating voltage: 3.3V/5V
  • Response time: <10s (tau 63%)
  • Switch-on time: <60s
  • Dimensions: 27 x 20mm
  • Mounting hole size: 2.0mm

Pinout

  • Pins
PIN SYMBOL Description
1 VCC 3.3V/5V Power on
2 GND Ground
3 SDA I2C data pin
4 SCL I2C clock pin

Hardware

Controller

This product uses Sensirion's SGP40 gas sensor and is designed for easy integration into air purifiers or demand-controlled ventilation systems. Sensirion's CMOSens® technology provides a complete, easy-to-use sensor system on a single chip with a digital I2C interface and temperature-controlled micro-heating plates that provide VOC-based humidity-compensated indoor air quality signals. Sensirion's powerful VOC algorithm processes the output signal directly, converting the original signal into a VOC index that can be used as a reliable measure of indoor air quality. The VOC algorithm automatically ADAPTS to the environment in which the sensor is located. Both the sensing element and the VOC algorithm are unmatched in robustness against the polluting gases present in real-world applications, resulting in unique long-term stability and low drift and device-to-device differences.

Communication protocol

SGP40 uses I2C communication, I2C communication, one data line, and one clock line. Normal I2C bus has three types of signals in the data transmission process: start signal, end signal, and response signal, as shown in the figure below:
TSL2591.png
Start signal: When SCL is high, SDA jumps from high level to low level, and data transmission begins。
End signal: When SCL is high, SDA jumps from low level to high level, and data transmission ends。
Reply signal: After receiving 8bit data, the receiving IC sends a specific low-level pulse to the sending IC to indicate that the data has been received..

  • I2C data read and write operations for SGP40

SGP40 VOC Sensor wiki hard0.png
As can be seen from the figure above, the data of SGP40 is sent with 16-bit addresses, and the 16-bit data sent needs a CRC-8/MAXIM verification code.

CRC

Cyclic Redundancy Check (CRC) is one of the most commonly used error Check codes in the field of data communication. Its characteristic is that the length of information fields and verification fields can be arbitrarily selected. Cyclic redundancy check (CRC) is a data transmission error detection function that performs polynomial calculations on the data and attaches the results to the back of the frame. The receiving device also performs a similar algorithm to ensure the correctness and integrity of the data transmission. SGP40 uses THE CRC-8/MAXIM check code calculation, that is, the calculation result of polynomial x^8 + x^5 + x^4 + 1.
The procedure has been simplified, using the lookup table method.

Arduino

Hardware connection

SGP40 VOC Sensor wiki arduino1.png

Install Arduino IDE

Please download the IDE from the Arduino website and install it.

Test the codes

Download the demo codes from the Resources part and unzip them.
This demo is written based on the Arduino library version, so you need to copy the demo to the Arduino library directory. Copy the Waveshare_SGP40 folder in the Arduino directory from the next week's files to the Libraries folder in the Arduino installation directory (C:\Users\XXX\Documents\Arduino\libraries or C:\Program Files (x86)\Arduino\libraries).
Open the Arduino IDE: Choose file -> example -> Waveshare_SGP40 and open it.
SGP40 VOC Sensor wiki arduino2.png
The Development board selects the appropriate model, selects the appropriate COM port, compiles the demo, downloads it to UNO, and opens the serial port monitor.
SGP40 VOC Sensor wiki arduino3.png
It is important to note that this value uses a converted value, where VOC is 0 under normal conditions. Unless the environment is harsh, alcohol can be used instead of volatile gas, and a greater sensitive beat can be obtained.

STM32

Hardware connection

Connection with XNUCLEO-F103RB:

AS7341 Spectral Color Sensor XNUCLEO-F103RB
VCC 3.3V/5V
GND GND
SDA SDA/D14/PB9
SCL SCL/D15/PB8

Raspberry Pi

Hardware connection

SGP40 VOC Sensor wiki RPI1.png

AS7341 Spectral Color Sensor Raspberry Pi(BCM)
VCC 3.3V/5V
GND GND
SDA SDA(2)
SCL SCL(3)

Working with Raspberry Pi

Enable I2C interface

  • Open a terminal and run the following commands:
sudo raspi-config 
#Choose Interfacing Options -> I2C -> yes to enable the I2C interface

RaspberryPi-I2C-Enable.png

  • Restart Raspberry Pi
sudo reboot

Install libraries

  • Install BCM2835, open the terminal, and run the following command.
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.60.tar.gz
tar zxvf bcm2835-1.60.tar.gz 
cd bcm2835-1.60/
sudo ./configure
sudo make
sudo make check
sudo make install
  • Install wiringpi
sudo apt-get install wiringpi
cd /tmp
wget https://project-downloads.drogon.net/wiringpi-latest.deb
sudo dpkg -i wiringpi-latest.deb
gpio -v

Download and test the demo codes

sudo apt-get install p7zip-full
wget https://files.waveshare.com/upload/6/62/SGP40_Voc_Sensor_code.7z
7z x SGP40_Voc_Sensor_code.7z -r -o./SGP40_Voc_Sensor_code
sudo chmod 777 -R  SGP40_Voc_Sensor_code

C codes

cd
cd SGP40_Voc_Sensor_code/RPI/c
sudo make clean
sudo make
sudo ./main

python codes

cd
cd SGP40_Voc_Sensor_code/RPI/python
sudo python SGP40.py
  • Note: This sensor is extremely sensitive to ethanol.
  • Note: The sensor starts with a heating process, during which the raw data slowly increases until it stabilizes.

Resource

Documents

Codes

FAQ

 Answer:
Please check whether the hardware connection is OK, especially since the cable sequence of SDA and SCL should not be reversed, and reconnect the sensor after powering off and re-run the program.

{{{5}}}


 Answer:
The raw data output is the sensor ADC value, which can be converted to a VOC class index using the Sensirionu library, and cannot be converted to PPM units or PPB.

{{{5}}}


Support

If you require technical support, please go to the Support page and open a ticket.