Example Code for Arduino-Polling for Data
Last revision 2026/01/21
Burn the program to DFRuino UNO through Arduino IDE, open the serial monitor to see the printed sensor status, AQI level, and TVOC and eCO2 concentration in sequence.
Hardware Preparation
- DFRduino UNO R3 (or similar) x 1
- ENS160 Air Quality Sensor (I2C) x 1
- Wires
Software Preparation
- Arduino IDE
- Download and install the ENS160 Library & Examples. (About how to install the library?)
Wiring Diagram

- For other motherboards, connect to the corresponding SCL and SDA interface
Other Preparation Work
Preheat the sensor 3 minutes before use to obtain accurate data more quickly.
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.
Sensor Operating Status
| Status | Description |
|---|---|
| 0 | Operate normally |
| 1 | Preheat for 3 minutes when powered on (until 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 status after 24 hours of continuous operation, if there is a power failure during this period, the sensor will still enter the initial startup status after power-on again) |
For more details, please refer to Chapter 10 in the Chip Manual.
Sample Code
/*!
* @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 measurement 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]([email protected])
* @version V1.0
* @date 2021-10-26
* @url https://github.com/DFRobot/DFRobot_ENS160
*/
#include <DFRobot_ENS160.h>
DFRobot_ENS160_I2C ENS160(&Wire, /*iicAddr*/ 0x53);
void setup(void)
{
Serial.begin(115200);
// Initialize the sensor
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 by the sensor)
* ENS160_STANDARD_MODE: STANDARD Gas Sensing Modes
*/
ENS160.setPWRMode(ENS160_STANDARD_MODE);
/**
* Set ambient temperature and humidity for calibration and compensation of the measured data.
* temperature the current ambient temperature, float type, unit: C
* humidity the current ambient humidity, 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, 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);
/**
* 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 data
* 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 eCO2 data
* Return value range: 400–65000, unit: ppm
*/
uint16_t ECO2 = ENS160.getECO2();
Serial.print("Carbon dioxide equivalent concentration : ");
Serial.print(ECO2);
Serial.println(" ppm");
Serial.println();
delay(1000);
}
Result
Serial printed eCO2, TVOC concentration, AQI level, and sensor operating status in real time.

Additional Information
For more details, please refer to Chapter 10 in the Chip Manual.
Was this article helpful?
