Fermion: ENS160 Air Quality Multi-Gas Sensor Wiki - DFRobot

Introduction

This Fermion: ENS160 Air Quality Sensor, based on ScioSense's new ENS160 sensor chip, is specifically designed for indoor air quality monitoring and offers detection of multiple IAQ data(TVOC, eCO2, AQI).
The innovative TrueVOC™ technology combines the metal oxide(MOX) technology to bring this sensor superior accuracy, fast response, anti-interference, etc. With intelligent on-chip algorithms, the ENS160 can directly output rich and easy-to-understand environmental data. Preheat the sensor 3 minutes before use then you can obtain accurate data more quickly. What's more, the built-in automatic baseline correction algorithm ensures the long-term stability of the sensor.

Air Quality Index

AQI Reference

Level Description Suggestion Recommended Stay Time
5 Extremely bad In unavoidable circumstances, please strengthen ventilation Not recommended to stay
4 Bad Strengthen ventilation, find sources of pollution Less than one month
3 Generally Strengthen ventilation, close to the water source Less than 12 months
2 Good Maintain adequate ventilation Suitable for long-term living
1 Excellent No suggestion Suitable for long-term living

eCO2/CO2 Concentration Reference

eCO2/CO2 Level Suggestion
21500 Terrible Indoor air pollution is serious and requires ventilation
1000-1500 Bad Indoor air is polluted, ventilation is recommended
800-1000 Generally Can be ventilated
600-800 Good Keep it normal
400-600 Eexcellent No suggestion

TVOC Concentration Reference

TOVC(ppb) Effects on Human Health
>6000 Headaches and nerve problem
750-6000 Restless and headache
50-750 Restless and uncomfortable
<50 No effect

Features

Applications

Specification

Board Overview

Board Overview

Num Label Description
1 3V3 Power +
2 GND GND
3 SCL I2C clock line
4 SDA I2C data line
5 SCK Serial clock
6 SDI Serial data input
7 SDO Serial data ouput
8 CS Chip-select
9 INT Interrupt Pin

Tutorial for Arduino

Connect the sensor to FireBeelt Board ESP32-E(or other 3.3V board) as shown below.

Requirements

Connection Diagram

Connection

Sample Code 1 - Data Pooling

Burn the program to FireBeetle Board ESP32-E through Arduino IDE, open the serial port, we can see the printed sensor status, AQI level, TVOC and eCO2 concentration on the serial monitor.

Sensor operating status

Status Description
0 Operate normally
1 Preheat, the first 3 minutes when powered on(No more inital startup status for the sensor)
2 Initial startup, the first 1 hours when powered on(the sensor will no longer be in this state after 24 hours of continuous operation, if there is a power failure during this period, the sensor will still enter the initial startup state after power-on again)

For more details, please refer to Chapter 10 in the Chip Manual.

Note: The ambient temperature and humidity will affect the accuracy of the data, please fill in the current ambient temperature and humidity in the setTempAndHum(/*temperature=*/temp, /*humidity=*/hum); function.

/*!
 * @file  getMeasureData.ino
 * @brief  Get the sensor data by polling (use 3.3V main controller for Fermion version)
 * @details  Configure the sensor power mode and parameters (for compensating the calibrated temperature and relative humidity in gas measurement)
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license  The MIT License (MIT)
 * @author  [qsjhyy](yihuan.huang@dfrobot.com)
 * @version  V1.0
 * @date  2021-10-26
 * @url  https://github.com/DFRobot/DFRobot_ENS160
 */
#include <DFRobot_ENS160.h>

#define I2C_COMMUNICATION  //I2C communication. Comment out this line of code if you want to use SPI communication.

#ifdef  I2C_COMMUNICATION
  /**
   *   For Fermion version, the default I2C address is 0x53, connect SDO pin to GND and I2C address will be 0x52
   */
  DFRobot_ENS160_I2C ENS160(&Wire, /*I2CAddr*/ 0x53);
#else
  /**
   * Set up digital pin according to the on-board pin connected with SPI chip-select pin
   * csPin Available Pins. For example: ESP32&ESP8266(D3), m0(6)
   */
  uint8_t csPin = D3;
  DFRobot_ENS160_SPI ENS160(&SPI, csPin);
#endif


void setup(void)
{
  Serial.begin(115200);

  // Init the sensor
  while( NO_ERR != ENS160.begin() ){
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }
  Serial.println("Begin ok!");

  /**
   * Set power mode
   * mode Configurable power mode:
   *   ENS160_SLEEP_MODE: DEEP SLEEP mode (low power standby)
   *   ENS160_IDLE_MODE: IDLE mode (low-power)
   *   ENS160_STANDARD_MODE: STANDARD Gas Sensing Modes
   */
  ENS160.setPWRMode(ENS160_STANDARD_MODE);

  /**
   * Users write ambient temperature and relative humidity into ENS160 for calibration and compensation of the measured gas data.
   * ambientTemp Compensate the current ambient temperature, float type, unit: C
   * relativeHumidity Compensate the current ambient temperature, float type, unit: %rH
   */
  ENS160.setTempAndHum(/*temperature=*/25.0, /*humidity=*/50.0);

}

void loop()
{
  /**
   * Get the sensor operating status
   * Return value: 0-Normal operation, 
   *         1-Warm-Up phase, first 3 minutes after power-on.
   *         2-Initial Start-Up phase, first full hour of operation after initial power-on. Only once in the sensor’s lifetime.
   * note: Note that the status will only be stored in the non-volatile memory after an initial 24h of continuous
   *       operation. If unpowered before conclusion of said period, the ENS160 will resume "Initial Start-up" mode
   *       after re-powering.
   */
  uint8_t Status = ENS160.getENS160Status();
  Serial.print("Sensor operating status : ");
  Serial.println(Status);

  /**
   * Get the air quality index
   * Return value: 1-Excellent, 2-Good, 3-Moderate, 4-Poor, 5-Unhealthy
   */
  uint8_t AQI = ENS160.getAQI();
  Serial.print("Air quality index : ");
  Serial.println(AQI);

  /**
   * Get TVOC concentration
   * Return value range: 0–65000, unit: ppb
   */
  uint16_t TVOC = ENS160.getTVOC();
  Serial.print("Concentration of total volatile organic compounds : ");
  Serial.print(TVOC);
  Serial.println(" ppb");

  /**
   * Get CO2 equivalent concentration calculated according to the detected data of VOCs and hydrogen (eCO2 – Equivalent CO2)
   * Return value range: 400–65000, unit: ppm
   * Five levels: Excellent(400 - 600), Good(600 - 800), Moderate(800 - 1000), 
   *               Poor(1000 - 1500), Unhealthy(> 1500)
   */
  uint16_t ECO2 = ENS160.getECO2();
  Serial.print("Carbon dioxide equivalent concentration : ");
  Serial.print(ECO2);
  Serial.println(" ppm");

  Serial.println();
  delay(1000);
}

Expected Results

Serial print eCO2, TVOC concentration, AQI level, and sensor operating status in real time.

Result

Sample Code 2 - Get Data by Intterupt

Burn the program to FireBeetle Board ESP32-E through Arduino IDE. When an interrupt is triggered, the information about TOVC, eCO2 concentration and AQI level will be printed on the serial monitor.

/*!
 * @file  interruptDataDrdy.ino
 * @brief  Get the sensor data through interrupt (Use 3.3V main controller for Fermion version; this example is only applicable to Fermion version)
 * @details  Configure the sensor interrupt mode, interrupt occurs when a new data is uploaded into the sensor
 * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
 * @license  The MIT License (MIT)
 * @author  [qsjhyy](yihuan.huang@dfrobot.com)
 * @version  V1.0
 * @date  2021-10-27
 * @url  https://github.com/DFRobot/DFRobot_ENS160
 */
#include <DFRobot_ENS160.h>

#define I2C_COMMUNICATION  //I2C communication. Comment out this line of code if you want to use SPI communication.

#ifdef  I2C_COMMUNICATION
  /**
   *   For Fermion version, the default I2C address is 0x53, connect SDO pin to GND and I2C address will be 0x52
   */
  DFRobot_ENS160_I2C ENS160(&Wire, /*I2CAddr*/ 0x53);
#else
  /**
   * Set up digital pin according to the on-board pin connected with SPI chip-select pin
   * csPin Available Pins. For example: ESP32&ESP8266(D3), m0(6)
   */
  uint8_t csPin = D3;
  DFRobot_ENS160_SPI ENS160(&SPI, csPin);
#endif

/* Interrupt flag */
volatile uint8_t flag = 0;
/* External interrupt flag */
void interrupt()
{
  flag = 1;
}

void setup(void)
{
  Serial.begin(115200);

  // Init the sensor
  while( NO_ERR != ENS160.begin() ){
    Serial.println("Communication with device failed, please check connection");
    delay(3000);
  }
  Serial.println("Begin ok!");

  #if defined(ESP32) || defined(ESP8266)
    // D4 pin is used as interrupt pin by default, other non-conflicting pins can also be selected as external interrupt pins.
    attachInterrupt(digitalPinToInterrupt(D4)/* Query the interrupt number of the D4 pin */, interrupt, RISING);
  #elif defined(ARDUINO_SAM_ZERO)
    // Pin 5 is used as interrupt pin by default, other non-conflicting pins can also be selected as external interrupt pins
    attachInterrupt(digitalPinToInterrupt(5)/* Query the interrupt number of the 5 pin */, interrupt, RISING);
  #endif

  /**
   * Interrupt config (INT)
   * mode Interrupt mode to be set, perform OR operation on the following to get mode:
   *   Interrupt setting (the interrupt occur when a new data is uploaded): eINTModeDIS-Disable interrupt, eINTModeEN-Enable interrupt
   *   Interrupt pin output driving mode: eINTPinOD-Open drain output, eINTPinPP-Push pull output
   *   Interrupt pin active level: eINTPinActiveLow-Active low, eINTPinActiveHigh-Active high
   */
  ENS160.setINTMode(ENS160.eINTModeEN | 
                    ENS160.eINTPinPP | 
                    ENS160.eINTPinActiveHigh);

  Serial.println();
  delay(1000);
}

void loop()
{
  if(flag == 1){
    flag = 0;
    /**
     * Get the air quality index
     * Return value: 1-Excellent, 2-Good, 3-Moderate, 4-Poor, 5-Unhealthy
     */
    uint8_t AQI = ENS160.getAQI();
    Serial.print("Air quality index : ");
    Serial.println(AQI);

    /**
     * Get TVOC concentration
     * Return value range: 0–65000, unit: ppb
     */
    uint16_t TVOC = ENS160.getTVOC();
    Serial.print("Concentration of total volatile organic compounds : ");
    Serial.print(TVOC);
    Serial.println(" ppb");

    /**
     * Get CO2 equivalent concentration calculated according to the detected data of VOCs and hydrogen (eCO2 – Equivalent CO2)
     * Return value range: 400–65000, unit: ppm
     * Five levels: Excellent(400 - 600), Good(600 - 800), Moderate(800 - 1000), 
     *               Poor(1000 - 1500), Unhealthy(> 1500)
     */
    uint16_t ECO2 = ENS160.getECO2();
    Serial.print("Carbon dioxide equivalent concentration : ");
    Serial.print(ECO2);
    Serial.println(" ppm\n");
  }
}

Expected Result

Serial print the eCO2, TOVC concentration and AQI level in real time.

Result

API Function

  /**
   * @fn setPWRMode
   * @brief Set power supply mode
   * @param mode Configurable power mode:
   * @n       ENS160_SLEEP_MODE: DEEP SLEEP mode (low power standby)
   * @n       ENS160_IDLE_MODE: IDLE mode (low-power)
   * @n       ENS160_STANDARD_MODE: STANDARD Gas Sensing Modes
   * @return None
   */
  void setPWRMode(uint8_t mode);

    /**
   * @fn setTempAndHum
   * @brief Users write ambient temperature and relative humidity into ENS160 for calibration compensation of the measured gas data.
   * @param ambientTemp Compensate the current ambient temperature, float type, unit: C
   * @param relativeHumidity Compensate the current ambient temperature, float type, unit: %rH
   * @return None
   */
  void setTempAndHum(float ambientTemp, float relativeHumidity);

  /**
   * @fn getENS160Status
   * @brief This API is used to get the sensor operating status
   * @return Operating status:
   * @n        eNormalOperation: Normal operation; 
   * @n        eWarmUpPhase: Warm-Up phase; 
   * @n        eInitialStartUpPhase: Initial Start-Up phase; 
   * @n        eInvalidOutput: Invalid output
   */
  uint8_t getENS160Status(void);

  /**
   * @fn getAQI
   * @brief Get the air quality index calculated on the basis of UBA
   * @return Return value range: 1-5 (Corresponding to five levels of Excellent, Good, Moderate, Poor and Unhealthy respectively)
   */
  uint8_t getAQI(void);

  /**
   * @fn getTVOC
   * @brief Get TVOC concentration
   * @return Return value range: 0–65000, unit: ppb
   */
  uint16_t getTVOC(void);

  /**
   * @fn getECO2
   * @brief Get CO2 equivalent concentration calculated according to the detected data of VOCs and hydrogen (eCO2 – Equivalent CO2)
   * @return Return value range: 400–65000, unit: ppm
   * @note Five levels: Excellent(400 - 600), Good(600 - 800), Moderate(800 - 1000), 
   * @n                  Poor(1000 - 1500), Unhealthy(> 1500)
   */
  uint16_t getECO2(void);

Tutorial for Raspberry Pi

Note: Please let the sensor run for 1 hour first to ensure the accuracy of the data when using it for the first time, and then perheat for 3 minute each time it is used. You also need to set the current ambient temperature and humidity to assist in detecting result.

Requirements

Connection

Connect the module to the Raspberry Pi according to the wiring diagram(use I2C in the example).

Connection for Raspberry Pi

The left is connection for I2C, the right is for SPI.

Driver Installing

  1. Enable Raspberry Pi I2C.(Skip this step if it is already enabled) Open terminal and input the following commands and press "Enter":

pi@raspberrypi:~ $ sudo raspi-config

Then use the UP/Down keys to select "Interfacing Options", press Enter, select "P5 I2C" and press Enter to comfirm "Yes". Restart the Pi board.

  1. To install Python dependency library and git, the Raspberry Pi needs to be connected to the Internet. Skip this step if already installed. In the terminal, input the following commands and press Enter:

pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git

  1. Download the ENS160 driver library. In the terminal, type the following commands and press Enter:

pi@raspberrypi:~ $ cd Desktop/ pi@raspberrypi:~/Desktop $ git clone https://github.com/DFRobot/DFRobot_ENS160

Sample Code 1 - Data Pooling

pi@raspberrypi:~/Desktop $ cd DFRobot_ENS160/python/raspberrypi/examples/get_measure_data

pi@raspberrypi:~/Desktop/DFRobot_ENS160/python/raspberrypi/examples/get_measure_data $python get_measure_data.py

Result

Sample Code 2 - Get Data by Interrupt

pi@raspberrypi:~/Desktop $ cd DFRobot_ENS160/python/raspberrypi/examples/interrupt_data_drdy

pi@raspberrypi:~/Desktop/DFRobot_ENS160/python/raspberrypi/examples/interrupt_data_drdy $python interrupt_data_drdy.py

Result

FAQ

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

More Documents