ENS160 air quality on an Arduino Uno
An ENS160 board on the Uno’s I2C pins, read with ScioSense_ENS160.h: the serial monitor prints the air quality index, TVOC and eCO2 every second. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner About 10 minutes to build and run. Runs in your browser. Free, and no account needed.
The parts retail for about $36. On Mokxi they're free.
What you'll learn
- Sensors
- School
- Using the Air quality
- Difficulty: Beginner
- Time: About 10 minutes
- Board: Arduino Uno R3
- Parts: 2
How it works
An ENS160 board on the Uno’s I2C pins, read with ScioSense_ENS160.h: the serial monitor prints the air quality index, TVOC and eCO2 every second.
Arduino Uno R3 runs the sketch below. The circuit around it: Air quality, ENS160. delay waits 1000 milliseconds. Serial.begin opens the serial port at 9600 baud.
Parts list
2 parts, plus the jumper wires. They retail for about $36; on Mokxi they're free.
Wiring table
Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.
| Part and pin | Connects to |
|---|---|
| Air quality, ENS160 pin VIN | Arduino Uno R3 pin 5V |
| Air quality, ENS160 pin GND | Arduino Uno R3 pin GND |
| Air quality, ENS160 pin SDA | Arduino Uno R3 pin A4 |
| Air quality, ENS160 pin SCL | Arduino Uno R3 pin A5 |
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// An ENS160 air quality sensor.
//
// The ENS160 answers at 0x53 (0x52 with ADDR to GND). begin() resets it and
// checks its part number; standard mode then heats its four tiny hot plates
// and gives three readings every second: the air quality index (1 excellent
// to 5 unhealthy, from Germany's UBA guideline), TVOC in ppb and eCO2 in
// ppm.
//
// ENS160 VIN -> 5V, GND -> GND, SCL -> A5, SDA -> A4
//
// The board has its own regulator and pull-ups, so 5 V on VIN is fine.
// Move the three sliders while it runs.
//
// THINGS TO TRY. Print the warm-up flag: bits 2 and 3 of the status
// register (0x20) read 1 for the first three minutes. Then turn on an LED
// when the AQI reaches 4.
#include <Wire.h>
#include "ScioSense_ENS160.h"
ScioSense_ENS160 ens160(ENS160_I2CADDR_1);
void setup() {
Serial.begin(9600);
if (!ens160.begin()) {
Serial.println("No ENS160 at 0x53: check SDA, SCL and power.");
while (1) {}
}
Serial.println("ENS160 found at 0x53");
ens160.setMode(ENS160_OPMODE_STD);
}
void loop() {
if (ens160.measure(true)) {
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);
}
Code walkthrough
The key functions of the sketch, and what each one does.
setup sketch.ino
Runs once when the board starts. It gets the pins and libraries ready.
void setup() {
Serial.begin(9600);
if (!ens160.begin()) {
Serial.println("No ENS160 at 0x53: check SDA, SCL and power.");
while (1) {}
}
Serial.println("ENS160 found at 0x53");
ens160.setMode(ENS160_OPMODE_STD);
}loop sketch.ino
Runs over and over for as long as the board has power. This is where the project does its work.
void loop() {
if (ens160.measure(true)) {
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);
}Troubleshooting
The usual mistakes with this circuit, and the fix for each.
- Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected. - Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.