Parts

ENS160 air quality sensor

The ScioSense ENS160 gives an air quality index from 1 to 5, TVOC and eCO2 over I2C at 0x53 or 0x52.

Aliases: ENS160 breakout, ENS160+AHT21, SparkFun ENS160, Adafruit ENS160, ENS161, AQI sensor. A metal-oxide gas sensor with four tiny heated plates and its own processor. It works out three numbers each second in its standard mode: the air quality index of Germany's environment agency (UBA), 1 for excellent air to 5 for unhealthy; TVOC, the total volatile organic compounds in parts per billion; and eCO2, the carbon dioxide level in parts per million that would come with them. It does not measure CO2 itself: for that you need an NDIR sensor such as the SCD40.

Pins

Pin What it does
VIN Supply, 3.3 or 5 V on the board (the chip's core runs from 1.8 V; the board's regulator and level shifters feed it).
GND Ground.
SCL, SDA I2C. The board carries the pull-ups.
ADDR The address bit, read at power-up. The board pulls it up: 0x53. To GND it is 0x52.
INT INTn, which the sketch can set to go active when new data is ready.

Properties

aqi (1 to 5), tvoc (ppb, 0 to 65,000) and eco2 (ppm, 400 to 65,000) are the air, the chip's output range. The three sliders cover indoor air (eCO2 to 5000 ppm, TVOC to 3000 ppb) and change the readings while the circuit runs; the next sample reports them.

Reading it on an Arduino

With ScioSense's library, ScioSense_ENS160.h: the Library Manager's "ENS160 - Adafruit Fork", the one most tutorials use, and the one Mokxi ships. (SparkFun's SparkFun_ENS160.h and DFRobot's DFRobot_ENS160.h are not shipped.)

#include <Wire.h>
#include "ScioSense_ENS160.h"

ScioSense_ENS160 ens160(ENS160_I2CADDR_1);   // 0x53; ENS160_I2CADDR_0 is 0x52

void setup() {
  Serial.begin(9600);
  if (!ens160.begin()) {
    Serial.println("No ENS160");
    while (1) {}
  }
  ens160.setMode(ENS160_OPMODE_STD);
}

void loop() {
  if (ens160.measure(true)) {     // waits for the next sample
    Serial.print("AQI ");
    Serial.print(ens160.getAQI());
    Serial.print(", TVOC ");
    Serial.print(ens160.getTVOC());
    Serial.print(" ppb, eCO2 ");
    Serial.print(ens160.geteCO2());
    Serial.println(" ppm");
  }
  delay(1000);
}

Mind the address: the library's default constructor is 0x52, and most boards are 0x53. The gallery's ENS160 air quality example prints all three every second. With a temperature and humidity sensor beside it (the AHT21 on the ENS160+AHT21 boards), ens160.set_envdata(celsius, humidity) passes the room's climate in.

How it talks

  • PART_ID (0x00, two bytes, low byte first) reads 0x0160. Registers step on as a burst reads or writes them.
  • OPMODE (0x10): 0x00 deep sleep, 0x01 idle (after power-up), 0x02 standard gas sensing, 0xF0 reset. Any other value sets STATER in the status register.
  • DEVICE_STATUS (0x20): bit 7 says a mode is running, bit 6 an error, bits 3 and 2 the validity (1 during the 3 minute warm-up after power-on, then 0), bit 1 NEWDAT and bit 0 NEWGPR. Reading the data clears NEWDAT.
  • DATA_AQI (0x21), DATA_TVOC (0x22) and DATA_ECO2 (0x24): five bytes in one burst, the two words low byte first.
  • COMMAND (0x12) in idle mode: 0x0E puts the firmware version in GPR_READ 4 to 6 (0x4C), and 0xCC clears them.
  • TEMP_IN (0x13) takes Kelvin times 64 and RH_IN (0x15) %RH times 512; DATA_T and DATA_RH (0x30, 0x32) report what the calculations use.
  • CONFIG (0x11) sets up INTn: 0x23 is active low, push-pull, on new data, cleared when the data are read.

What it does not model

The gas chemistry: the three readings are the three sliders, set apart from each other, so the UBA table that ties the index to TVOC is not applied. The one hour initial start-up of a brand new sensor (the part is taken as run in), the temperature and humidity compensation, the raw hot plate resistances (GPR_READ in standard mode reads zero, so the library's measureRaw() finds no new data), DATA_MISR, the custom heater sequences, SPI and the ENS161's low power mode are not simulated. The datasheet gives no start-up time, so the chip answers at once.

Common mistakes

The wrong address: ScioSense_ENS160 ens160; looks at 0x52, but a board with ADDR pulled up is at 0x53. Forgetting setMode(ENS160_OPMODE_STD): in idle mode it never measures. Trusting the first readings on a real sensor: it warms up for 3 minutes after every power-on, and a new one needs an hour the first time.