Using the ENS160 gas sensor with Arduino involves wiring up the sensor to your Arduino-compatible microcontroller, installing the ENS160 library and running the provided example code.
Wiring
Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the ENS160 VIN.
Here is an Adafruit Metro wired up to the ENS160 using the STEMMA QT connector:
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Here is an Adafruit Metro wired up using a solderless breadboard:
-
Board 5V to sensor VIN (red wire)
-
Board GND to sensor GND (black wire)
-
Board SCL to sensor SCL (yellow wire)
- Board SDA to sensor SDA (blue wire)
Library Installation
You can install the ENS160 - Adafruit Fork library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit ENS160, and select the ENS160 - Adafruit Fork library:
No additional libraries are required.
/*************************************************************************** ENS160 - Digital Air Quality Sensor This is an example for ENS160 basic reading in custom mode Updated by Sciosense / 25-Nov-2021 ***************************************************************************/ #include <Wire.h> int ArduinoLED = 13; //------------------------------------------------------------- //ENS160 related items //------------------------------------------------------------- #include "ScioSense_ENS160.h" // ENS160 library ScioSense_ENS160 ens160(ENS160_I2CADDR_0); //ScioSense_ENS160 ens160(ENS160_I2CADDR_1); /*-------------------------------------------------------------------------- SETUP function initiate sensor --------------------------------------------------------------------------*/ void setup() { Serial.begin(115200); while (!Serial) {} //Switch on LED for init pinMode(ArduinoLED, OUTPUT); digitalWrite(ArduinoLED, LOW); Serial.println("------------------------------------------------------------"); Serial.println("ENS160 - Digital air quality sensor"); Serial.println(); Serial.println("Sensor readout in custom mode"); Serial.println(); Serial.println("------------------------------------------------------------"); delay(1000); Serial.print("ENS160..."); bool ok = ens160.begin(); Serial.println(ens160.available() ? "done." : "failed!"); if (ens160.available()) { // Print ENS160 versions Serial.print("\tRev: "); Serial.print(ens160.getMajorRev()); Serial.print("."); Serial.print(ens160.getMinorRev()); Serial.print("."); Serial.println(ens160.getBuild()); Serial.print("\tCustom mode "); ens160.initCustomMode(3); // example has 3 steps, max. 20 steps possible // Step time is a multiple of 24ms and must not be smaller than 48ms ens160.addCustomStep(48, 0, 0, 0, 0, 80, 80, 80, 80); // Step 1: 48ms, no measurments, all hotplates at low temperatures ens160.addCustomStep(196, 0, 0, 0, 0, 160, 215, 215, 200); // Step 2: 196ms, no measurments, all hotplates at medium temperatures ens160.addCustomStep(600, 1, 1, 1, 1, 250, 350, 350, 325); // Step 3: 600ms, measurments done, all hotplates at high temperatures Serial.println(ens160.setMode(ENS160_OPMODE_CUSTOM) ? "done." : "failed!"); } } /*-------------------------------------------------------------------------- MAIN LOOP FUNCTION Cylce every 1000ms and perform measurement --------------------------------------------------------------------------*/ void loop() { if (ens160.available()) { ens160.measureRaw(true); Serial.print("R HP0: ");Serial.print(ens160.getHP0());Serial.print("Ohm\t"); Serial.print("R HP1: ");Serial.print(ens160.getHP1());Serial.print("Ohm\t"); Serial.print("R HP2: ");Serial.print(ens160.getHP2());Serial.print("Ohm\t"); Serial.print("R HP3: ");Serial.print(ens160.getHP3());Serial.println("Ohm"); } delay(1000); }
I2C Address
In the Arduino library, ENS160_I2CADDR_0
is I2C address 0x52
and ENS160_I2CADDR_1
is I2C address 0x53
.
The default I2C address for the breakout board is 0x53
. To run the example code for address 0x53
, edit the top of the example code by commenting out ENS160_I2CADDR_0
and uncommenting ENS160_I2CADDR_1
:
#include "ScioSense_ENS160.h" // ENS160 library //ScioSense_ENS160 ens160(ENS160_I2CADDR_0); ScioSense_ENS160 ens160(ENS160_I2CADDR_1);
To use the sensor with address 0x52
, leave the example code as-is with ENS160_I2CADDR_0
uncommented.
#include "ScioSense_ENS160.h" // ENS160 library ScioSense_ENS160 ens160(ENS160_I2CADDR_0); //ScioSense_ENS160 ens160(ENS160_I2CADDR_1);
Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 115200 baud. You should see that the sketch has found your connected I2C ENS160 gas sensor. Then, sensor readings for AQI, TVOC, eCO2 and the raw resistance values of the four hot plates in the sensor are printed to the Serial Monitor every second.
Page last edited January 22, 2025
Text editor powered by tinymce.