Projects / VOC and eCO2 desk sensor

VOC and eCO2 desk sensor

Beginner1 hGuided buildReviewed

Build it step by step

0 of 6 done
  1. ESP32AHT2024.4°C

    Wire the three I2C devices

    All share GPIO 21 and 22 with 3V3 and GND. Their addresses differ.

  2. ESP32AHT2024.4°C

    Scan the bus

    Run an I2C scanner to see 0x38, 0x3C and 0x53.

  3. ESP32ENS160AHT2024.4°CSSD1306

    Install the libraries

    ENS160, AHTX0, SSD1306 and GFX from Library Manager.

  4. ESP32AHT2024.4°C

    Upload and warm up

    Leave it on for an hour the first time so the readings settle.

  5. ESP32

    Test with a VOC source

    Hold a marker pen near it. TVOC rises sharply.

  6. ESP32AHT2024.4°C

    Place it

    Put it on your desk away from the window and heat sources.

In short

How do you build a VOC and eCO2 desk sensor?

An ENS160 metal-oxide sensor with an AHT21 gives a TVOC and estimated CO2 reading for a study desk and nudges you to open the window. You need ESP32 DevKit V1, ENS160 air quality sensor, AHT20 temperature and humidity sensor, SSD1306 OLED Display, USB A to micro-USB cable (data) and Jumper wires male to male (40 pcs, 20 cm). It takes 6 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
ENS160 VIN and GNDESP32 3V3 and GNDSupply
ENS160 SDA and SCLESP32 GPIO 21 and 22I2C, address 0x53
AHT20 VIN and GNDESP32 3V3 and GNDSupply
AHT20 SDA and SCLESP32 GPIO 21 and 22I2C, address 0x38
OLED VCC and GNDESP32 3V3 and GNDSupply
OLED SDA and SCLESP32 GPIO 21 and 22I2C, address 0x3C

Code

Arduino IDE with the ESP32 board package. Install "ScioSense ENS160" (or the library your ENS160 breakout vendor recommends), "Adafruit AHTX0", "Adafruit SSD1306" and "Adafruit GFX Library". The eCO2 value is an estimate from VOCs and not a true CO2 measurement, and the ENS160 needs about an hour of warm-up on first use. Library function names can differ between versions, so check the example sketch of the one you install.

Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_AHTX0.h>
#include <ScioSense_ENS160.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_AHTX0 aht;
ScioSense_ENS160 ens160(ENS160_I2CADDR_1);     // address 0x53
Adafruit_SSD1306 oled(128, 64, &Wire, -1);

void face(byte aqi) {                          // 1 happy to 5 sad
  oled.drawCircle(100, 20, 14, SSD1306_WHITE);
  oled.fillCircle(95, 16, 2, SSD1306_WHITE); oled.fillCircle(105, 16, 2, SSD1306_WHITE);
  if (aqi <= 2) oled.drawLine(92, 26, 108, 26, SSD1306_WHITE);        // flat mouth simplified for a small display
  if (aqi <= 1) { oled.drawLine(92, 24, 96, 28, SSD1306_WHITE); oled.drawLine(96, 28, 104, 28, SSD1306_WHITE); oled.drawLine(104, 28, 108, 24, SSD1306_WHITE); }
  if (aqi >= 4) { oled.drawLine(92, 28, 96, 24, SSD1306_WHITE); oled.drawLine(96, 24, 104, 24, SSD1306_WHITE); oled.drawLine(104, 24, 108, 28, SSD1306_WHITE); }
}

void setup() {
  Serial.begin(115200);
  Wire.begin();
  aht.begin();
  ens160.begin();
  ens160.setMode(ENS160_OPMODE_STD);
  oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  oled.setTextColor(SSD1306_WHITE);
}

void loop() {
  sensors_event_t hum, temp;
  aht.getEvent(&hum, &temp);
  ens160.set_envdata(temp.temperature, hum.relative_humidity);   // compensation
  ens160.measure(true);
  byte aqi = ens160.getAQI();
  uint16_t tvoc = ens160.getTVOC();
  uint16_t eco2 = ens160.geteCO2();

  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setCursor(0, 0);  oled.print("AQI "); oled.print(aqi);
  oled.setCursor(0, 14); oled.print("TVOC "); oled.print(tvoc); oled.print(" ppb");
  oled.setCursor(0, 28); oled.print("eCO2 "); oled.print(eco2); oled.print(" ppm");
  oled.setCursor(0, 42); oled.print(temp.temperature, 1); oled.print(" C  "); oled.print(hum.relative_humidity, 0); oled.print(" %");
  if (eco2 > 1000) { oled.setCursor(0, 54); oled.print("Open a window"); }
  face(aqi);
  oled.display();
  delay(2000);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Fresh airAQI 1 or 2, eCO2 near 400 to 600 ppm
Hand sanitiser or marker nearbyTVOC and AQI rise
Closed room after an hour of studyeCO2 climbs above 1000 and the message appears
Open windowReadings fall within minutes

If it does not work

ENS160 not found

Check the address (0x52 or 0x53 depending on the breakout) and wiring.

Readings stuck at the first values

Still in the first warm-up. Wait.

eCO2 drifts at night

This is normal for an estimate. Treat the trend, not the number.

Compile errors on ens160 functions

The library version differs. Match the code to its bundled example.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the VOC and eCO2 desk sensor?

ESP32 DevKit V1, ENS160 air quality sensor, AHT20 temperature and humidity sensor, SSD1306 OLED Display, USB A to micro-USB cable (data) and Jumper wires male to male (40 pcs, 20 cm).

How long does the VOC and eCO2 desk sensor take to build?

About 60 minutes for a beginner maker, in 6 steps.

How do I know the VOC and eCO2 desk sensor works?

Fresh air: AQI 1 or 2, eCO2 near 400 to 600 ppm. Hand sanitiser or marker nearby: TVOC and AQI rise. Closed room after an hour of study: eCO2 climbs above 1000 and the message appears.

ENS160 not found: what should I check?

Check the address (0x52 or 0x53 depending on the breakout) and wiring.

Readings stuck at the first values: what should I check?

Still in the first warm-up. Wait.

eCO2 drifts at night: what should I check?

This is normal for an estimate. Treat the trend, not the number.

Compile errors on ens160 functions: what should I check?

The library version differs. Match the code to its bundled example.