KS0566 Keyestudio ENS160 Air Quality Sensor (TVOC, eCO2, AQI)

From Keyestudio Wiki
Revision as of 14:54, 24 August 2023 by Keyestudio (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Keyestudio ENS160 Air Quality Sensor


Description


Keyestudio ENS160 air quality sensor, originated from ScioSense, reveals indoor air quality by outputting IAQ data (TVOC, eCO2, AQI). Technically, It applies TrueVOC and Metal oxides Technology, featuring splendid accuracy, fast response and anti-interference.

Algorithms are built in the ENS160 air quality sensor to directly output TVOC, eCO2 and AQI values, hence the quality data is enriched and easy to understand. During using, its preheat time is less than 3 minutes, which makes the sensor quickly get accurate data. What’s more, the algorithm is automatically calibrated by an internal baseline to guarantee its long-term stability.

Features


  • Multiple IAQ outputs (TVOC, eCO2, AQI), enriching data


  • Preheat time is less than 3min, quickly acquiring data


  • Built-in algorithm, outputting accurate data


  • Automatic calibration baseline, ensuring long-term stability



Parameters


Power Voltage 3.3 V~5.5 V
Working Current 29 mA
Preheat Time <3min
Interface Mode I2C
I2C Address 0x52; 0x53
Working Temperature -10℃~65℃
Working Humidity 5 %RH~95 %RH
eCO2 Detection Range 400 ppm~65000 ppm
TVOC Detection Range 0 ppb~65000 ppb
Sensor Pin 5P 2.54mm right angled pin headers
Wire 5P 2.54mm DuPont Wire
Diameter of Hole 3.2mm
Dimensions 30mm*20mm*7.5mm
Weight 2.4g


Pin out


ENS160 sensor pin description:
ENS160 sensor pin description.png

ENS160 pin description:
ENS160 pin description.png

Pin 3 on ENS160 sensor is for I2C address selection (SPI master input slave output). When I2C ADDR pin is at high level, it selects 0x53; when it is at low, the address becomes 0x52. Herein, our I2C ADDR pin is designed at high, so the I2C address is 0x53 by default.

Besides, this sensor includes empty pads(pulled down by I2C ADDR pin) and ADDR pin, which are able to alter the I2C address. Here are procedures:

  • Method 1: Weld a 0Ω resistor packaged in 0603 at the empty pad(as below), and modify the address to 0x52 in example code “getMeasureData.ino”.


截图20230824142304.png

图4.4.png

  • Method 2: Connect ADDR pin to GND on mainboard(as below), and also modify the address to 0x52 in that example code.


截图20230824142614.png

For more, please refer to Specifications of ENS160.

Air Quality Reference


Air quality index (AQI) grade


Air quality index (AQI) grade.png

Carbon dioxide (eCO2/CO2) concentration


Carbon dioxide concentration.png

Total volatile organic compounds (TVOC) concentration


Total volatile organic compounds concentration.png

Shamanistic Diagram


Shamanistic Diagram.png

Dimensions


0566Dimensions.png

Arduino Tutorial


Hardware Requirement


  • Keyestudio Arduino UNO R3 main control board X1


  • ENS160 air quality sensor X1


  • M-F DuPont wire: many



Software Requirement


Arduino IDE 2.0.4

Download Arduino IDE. Please refer to Arduino official website: https://www.arduino.cc/

Wiring Diagram


Wire up according to the following diagram, and connect the mainboard to your computer via USB cable.
8.3 Wiring Diagram.png
Open Arduino IDE 2.0.4, and check whether the port is selected. If not, please the installation of the driver.

Select the port.
Select the port..png

Note: If you want to connect to other boards, please link with the corresponding SCL or SDA interface.

Example Code


8.4 Example Code.png

Open example code getMeasureData.ino. It is not recommended to copy and paste the following text to Arduino IDE and upload it, as errors may occur due to wrong format.
Thus, please find the library file to load the code on Arduino.

Complete code:

/******************************************************************************
#include <DFRobot_ENS160.h>
#define I2C_COMMUNICATION  //use I2C for communication. To use SPI to communicate, you need to invalidate this line code
#ifdef  I2C_COMMUNICATION
  /**
   *   Fermion version: I2C address is 0x53 by default. Connect SDO pin to GND, I2C address becomes 0x52
   */
  DFRobot_ENS160_I2C ENS160(&Wire, /*iicAddr*/ 0x53);#else
  uint8_t csPin = D3;
  DFRobot_ENS160_SPI ENS160(&SPI, csPin);#endif
void setup(void){
  Serial.begin(115200);

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

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

  /**
   * Set temperature and humidity parameter to measure the calibration compensation of data
   * temperature: current temperature value, float, °C
   * humidity: current ambient humidity, float, %rH
   */
  ENS160.setTempAndHum(/*temperature=*/25.0, /*humidity=*/50.0);
}
void loop(){
  /**
   * Acquire the sensor status
   * Output: 0-Normal operation, 
   *       1-Warm-Up phase, During first 3 minutes after power-on.
   *       2-Initial Start-Up phase, During first full hour of operation after initial power-on.Only once in the sensor’s lifetime.
   *           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);
  /**
   * Acquire air quality index
   * Output: 1-Excellent, 2-Good, 3-Moderate, 4-Poor, 5-Unhealthy
   */
  uint8_t AQI = ENS160.getAQI();
  Serial.print("Air quality index : ");
  Serial.println(AQI);

  /**
   * Acquire TVOC
   * Output:  0~65000, ppb
   */
  uint16_t TVOC = ENS160.getTVOC();
  Serial.print("Concentration of total volatile organic compounds : ");
  Serial.print(TVOC);
  Serial.println(" ppb");

  /**
   * Acquire eCO2
   * Output: 400~65000, ppm
   */
  uint16_t ECO2 = ENS160.getECO2();
  Serial.print("Carbon dioxide equivalent concentration : ");
  Serial.print(ECO2);
  Serial.println(" ppm");

  Serial.println();
  delay(1000);
*********************************************************************/



Note: Ambient temperature and humidity impact the accuracy of detection, please fill current values in the following function:

setTempAndHum(/*temperature=*/temp, /*humidity=*/hum);
图8.4.1.png

ENS160 sensor pulls up I2C ADDR pin so the address is 0x53. If you want to alter it to 0x52, please refer to Section 4. Pin out.
图8.4.2.png

Test Result


Upload code on UNO R3 board via Arduino IDE, and open the serial monitor to set the baud rate to 115200. We will see that sensor status, AQI Grade, TVOC and eCO2 concentration are printed on it:
RFG`F2-J3G SK2JLQ-FK8@X.png

Troubleshooting


(1) The port cannot be recognized
Please check whether the driver is installed or port is in poor conduct. Try to change a USB cable.

(2) Error occurs during compiling
Please select the correct development board. Please import library first as needed.

(3) Copy and paste the text code to Arduino IDE, format may be wrong when uploading. Please open and upload code in library file.