TVOC Sensor

From Waveshare Wiki
Jump to: navigation, search
TVOC Sensor
TVOC-Sensor

UART
{{{name2}}}

{{{name3}}}

{{{name4}}}

{{{name5}}}

{{{name6}}}

Overview

Introduction

The TVOC gas sensor module is specifically designed to accurately measure the concentration of TVOC (Total Volatile Organic Compounds) gas in the environment, providing an efficient tool for air quality assessment. Its core advantage lies in its outstanding adaptability and scalability, allowing for customization according to the specific needs of users. This sensor module is known for its excellent performance characteristics, including high sensitivity, stability, miniaturized design, simple measurement circuitry, and long lifespan.

Usage Scenarios

  • Smart home
  • Ambient air quality monitoring
  • Car air purifier
  • Handheld air quality monitor
  • Factory workshop fresh air system

Operating Principle

Based on the chemical adsorption reaction between gas molecules and the surface of semiconductor materials, when volatile organic compounds (VOCs) come into contact with heated sensitive materials, the reaction between gas molecules and surface oxygen ions will change the resistance value of the material. By measuring the change in resistance, the concentration of surrounding TVOC can be indirectly calculated. The resistance of the gas-sensitive material in the gas sensor varies with the concentration of the gas in the environment, and the greater the concentration of the TVOC gas, the smaller the sensor resistance. The measurement adopts a circuit that divides the voltage in series with a reference resistor, as shown in the circuit diagram in Figure 1-2. The calculation formula for the sensor response magnitude S and the reference circuit are as follows:

TVOC Sensor 04.png

Specifications

TVOC Sensor
Supply voltage 5V Logic voltage 3.3V
Communication interface UART (TTL signal line level 3.3V) Communication baud rate 115200
Response time <20S Startup time <120S
Detection concentration range 0.1~100 ppm Refresh rate 1Hz
Product dimensions 27×20×4.3mm Mounting hole diameter 2.0mm
Operating current ≤60mA Operating temperature -20℃~50℃
Operating humidity ≤96%RH Service life 5 years

  • The IO level of the sensor is 3.3V. If a 5V IO level is used, level conversion is required, otherwise the sensor will be damaged

Pinout Definition

Pin No. Identifier Pin Description
1 VCC 5V power positive
2 GND Ground
3 TXD UART output
4 RXD UART input
5 RST Reset pin, low active
6 ALM Alarm pin, if TVOC exceeds 2ppm, the pin will automatically pull down

Protocol Parsing

UART Communication Process

  • The default configuration of the serial port is: 8-bit data bit, 1-bit stop bit, no parity check, no flow control, and the default baud rate is 115200.
  • The protocol consists of Frame Header, Data, Sum Check and Frame Footer.
    • Frame Header and Frame Footer are fixed values. For details, please refer to the following table for details;

Note: The protocol packet follows the little-endian principle, i.e., the low byte comes first, and the high byte comes last.

Active Mode

  • The module defaults to active mode
  • Raw data
Frame header Air level Reserved High bit of CO₂ concentration Low bit of CO₂ concentration High bit of CH₂O concentration Low bit of CH₂O concentration High bit of TVOC concentration Low bit of TVOC concentration Checksum value Frame footer
Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8 Byte9 Byte10
FE 02 00 02 32 00 04 01 96 CF 16
  • Data decoding

Air quality levels are divided into excellent, good, medium, and poor, corresponding to levels 1-4 (0x1-0x4) respectively. For example, the above data shows that the air level is "good"

    • CO₂ concentration value = (High bit of concentration*256+Low bit of concentration) ppm
    • CH₂O concentration value = (High bit of concentration*256+Low bit of concentration) ppm
    • TVOC concentration value = ((High bit of concentration*256+Low bit of concentration) /1000) ppm
  • Parsing table
Data Type Length (Bytes) Hex Result
Frame header uint8 1 FE 0xFE
Air level uint8 1 02 0x02
Reserved uint8 1 00 *
CO₂ concentration uint16 2 02 32 562 ppm
CH₂O concentration uint16 2 00 04 4 ppb
TVOC concentration uint16 2 01 96 0.406 ppm
Checksum value uint8 1 CF 0xCF
Frame footer uint8 1 16 0x16


  • Restore Active Mode
    • When you need to switch to active mode, send the following command to the module:
Frame header Reserved Switch mode command Active upload mode Reserved Reserved Reserved Reserved Checksum value
Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
FE 00 78 40 00 00 00 00 B8

Query Mode

  • Switch to query mode
    • When you need to switch to query mode, you should first send the stop active upload mode command in the following format:
Frame header Reserved Switch mode command Active upload mode Reserved Reserved Reserved Reserved Checksum value
Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
FE 00 78 41 00 00 00 00 B9
  • Query current concentration
    • In query mode, the command format for reading the current concentration is as follows:
Frame header Reserved Q&A mode command Reserved Reserved Reserved Reserved Reserved Checksum value
Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8
FE 00 86 00 00 00 00 00 86
  • Query data decoding
    • After sending the query current concentration command, the module will return the following data:
Frame header Frame header Frame header Reserved Reserved High bit of TVOC concentration Low bit of TVOC concentration High bit of ADC value Low bit of ADC value Checksum value Frame footer
Byte0 Byte1 Byte2 Byte3 Byte4 Byte5 Byte6 Byte7 Byte8 Byte9 Byte10
FE FE 68 01 01 18 09 09 40 6C 16
  • Data decoding
    • TVOC concentration value = (High bit of concentration*256+Low bit of concentration) /1000
    • ADC value = (High bit of ADC value*256 + Low bit of ADC value)
  • Parsing table
Data Type Length (Bytes) Hex Result
Frame header uint24 3 FE FE 68 0xFE 0xFE 0x68
Reserved uint16 2 00 00 xx
TVOC concentration uint16 2 18 09 6.153 ppm
ADC value uint16 2 09 40 2368
Checksum value uint8 1 6C 0x6C
Frame footer uint8 1 16 0x16
  • ADC: The microcontroller collects the voltage value of VS through ADC sampling and outputs a 12 bit ADC value. For details on the circuit, please refer to the Operating Principle section.

Quick Test

  • The test software WS-TVOC is a debugging software that comes with TVOC Sensor, mainly used for rapid testing
  • Test preparation
    • Windows computer
    • USB TO TTL 1PCS
    • TVOC Sensor 1PCS
    • Matching cables
  • Hardware Connection
TVOC Sensor 05.png
  • Start testing
    • Connect the serial port to the USB port of the computer
    • Wait for 2 minutes until the sensor is fully heated up
    • Active mode:
      • Method 1: Use the Serial Port Debugging Assistant (SSCOM), select the corresponding port number, set the baud rate to 115200, and open the serial port to upload data once per second.
        TVOC Sensor 06.png
      • Method 2: Open the supporting host computer software
        ① Select the corresponding serial port number
        ② Click Save
        ③ Click Get directory
        ④ Click Start to visually view the real-time data and curves
        If you want to view all historical data, ⑤ click Save, and you can see the source file in the DataFile
        600px-TVOC Sensor 07.png
    • Query mode:
      • Use the Serial Debugging Assistant (SSCOM), select the corresponding port number, set the baud rate to 115200, and open the serial port
      • Send the stop active upload mode command in hexadecimal: FE 00 78 41 00 00 00 00 B9
      • Send the read data command in hexadecimal: FE 00 86 00 00 00 00 00 86, then the data can be read:
        ① Send the command to switch to query mode
        ② Send the query command to get the data
        600px-TVOC Sensor 08.png

Dimensions

  • TVOC-Sensor-size.jpg

Working with Raspberry Pi

  • For the installation and use of the Raspberry Pi system, you can refer to this link.
  • After successful boot, configure the Raspberry Pi environment

Download Demo

sudo apt install gpiod libgpiod-dev
wget https://files.waveshare.com/wiki/TVOC%20Sensor/TVOC_Sensor_Demo.zip
unzip TVOC_Sensor_Demo.zip
cd TVOC_Sensor_Demo/

UART Demo

Enable Raspberry Pi UART

  • Enter the command in the Raspberry Pi terminal: sudo raspi-config nonint do_serial 2
  • Select NO in the first pop-up window, YES in the second one, and OK for the final one.

Hardware Connection

  • Refer to the following diagram for connection:

TVOC-Sensor-details-5.jpg

Run C Demo

cd ~/TVOC_Sensor_Demo/Raspberrypi/c/
make
./main

Run Python Demo

cd ~/TOF_Laser_Range_Sensor_demo/Raspberrypi/python/example
python main.py

Working with ESP32S3

  • For ESP32S3 environment setup and basic usage, please refer to this link.
  • After setting up the environment, you can connect the sensor and download the Demo

Hardware Connection

  • Refer to the following diagram for connection:

TVOC Sensor 09.png

Arduino esp32 Demos

  • Go to TVOC_Sensor_Demo\ESP32S3\Arduino\TVOC_UART_Demo and double-click on the TVOC_UART_Demo.ino file
  • Select development board:

TOF Laser Range Sensor C 19.png

  • Select the port of the ESP32S3, and then compile and upload it
  • After the upload is completed, open the serial port monitor, and the relevant information will be output

Micropython Demos

  • Go to TVOC_Sensor_Demo\ESP32S3\Micropython and double-click on the TVOC_UART_Demo.py file
  • Select development board:

TOF Laser Range Sensor C 26.png

  • Select the port of the ESP32S3, and then run the demo
  • The shell will output the relevant information

Working with Raspberry Pi Pico

  • After setting up the environment, you can connect the sensor and download the Demo

Hardware Connection

  • Refer to the following diagram for connection:

TVOC Sensor 15.png

C Demo

  • Go to TVOC_Sensor_Demo\Raspberrypi pico\C and open the project via VS Code
  • Wait for automatic import and load of the compilation tool, and then compile and upload
  • After the upload is completed, open the serial port monitor, and the relevant information will be output

Micropython Demos

  • First flash MicroPython firmware to Raspberry Pi Pico
  • Go to TVOC_Sensor_Demo\Raspberrypi pico\Micropython and double-click on the TVOC_UART_Demo.py file
  • Select development board:

TVOC Sensor 16.png

  • Select the port of Raspberry Pi Pico, and then run the demo
  • The shell will output the relevant information

Working with Arduino

  • The IO level of the Arduino development board must be 3.3V. If a 5V IO level is used, level conversion is required, otherwise the sensor will be damaged
  • To use waveshare R3/R4, you need to set the following jumper cap to 3.3V before you can use it
  • For Arduino environment setup and basic usage, please refer to this R4 link, R3 is installed by default.
  • After setting up the environment, you can connect the sensor and download the Demo

Arduino Demos

Hardware Connection

  • Refer to the following diagram for connection:

Run Demo

  • Go to TVOC_Sensor_Demo\Arduino\TVOC_UART_Demo and double-click on the TVOC_UART_Demo.ino file
  • Select development board:
  • Select the port of the development board, and then compile and upload it
  • After the upload is completed, open the serial port monitor, and the relevant information will be output

Working with STM32

Hardware Connection

  • Refer to the following diagram for connection:

TVOC Sensor 17.png

STM32 Demo

  • Go to TVOC_Sensor_Demo\STM32, double-click on the .project file
  • Wait for automatic import and load, and then compile and flash
  • After uploading, connect the PA2 PA3 of the microcontroller to output relevant information

API Introduction

  • tvoc_init(): TVOC initialization
  • tvoc_set_device_active_mode(): Set the sensor to active mode
  • tvoc_set_device_query_mode(): Set the sensor to query mode
  • tvoc_get_active_device_data(): Get the data in active mode and decode it
  • tvoc_get_query_device_data(): Get the data in query mode and decode it
  • CRC_Check(uint8_t *Data, uint32_t Size): Calculate the checksum, and for the data output by the module, it only needs to verify the value of Byte 3+Byte4+...+Byte8, and the data sent by the host to the module is verified as Byte 1+Byte2+……+Byte7

Effect Demonstration

Active Mode

  • In active mode, it can output values of air level, CO₂, CH2O, and TVOC

TVOC Sensor 01.png

Query Mode

  • In query mode, it can output the TVOC value and the original ADC value

TVOC Sensor 02.png

ALM Alarm

  • ALM alarms can be implemented by IO reading, as shown below

TVOC Sensor 03.png

Resources

Datasheet

Demo

Software

FAQ

Q1. The host computer does not update the data, what's the issue?

  If the data is not updated, please restart the host computer and follow the steps to obtain it again

Q2. Is the baud rate fixed at 115200?

Yes, currently the default is 115200 baud rate 

Support




Technical Support

If you need technical support or have any feedback/review, please click the Submit Now button to submit a ticket, Our support team will check and reply to you within 1 to 2 working days. Please be patient as we make every effort to help you to resolve the issue.
Working Time: 9 AM - 6 PM GMT+8 (Monday to Friday)