Skip to content

Build an Air Quality sensor

Mitra Ardron edited this page Dec 5, 2025 · 5 revisions

Frugal IoT - building an Air Quality sensor.

These instructions are fresh - if they are not clear, feel free to open an issue and ask questions, this will help me refine the instructions. Or re-open issue#101.

Note: these instructions are based on the very similar Temperature Sensor

Contents

This is a, hopefully, simple guide to building, configuring, and using, a simple air quality sensor.

With practice it takes me around 5 or 10 minutes to make AND flash each sensor.

Parts needed (details below)

Part Typical cost
Dev board €1.76-4.07
ENS160-AHT21 sensor €3.28
Enclosure €0.31
USB cable €0.80
USB Power supply €0.50
================== ==========
Total. €6.65-8.96

Tools needed

  • Soldering iron - to solder the sensor cables to the dev board
  • Drill if want a hole for an antenna
  • Sharp knife to cut notch in enclosure

Dev board

I’ve built these with a variety of boards.

My current favorite is the D1 mini Pro v4, there are a number of boards calling themselves D1 mini Pro other than the one from Lolin, and I like this clone for €4.07 because of the external antenna (note the newer Lolin D1 mini Pro V4 €3.35 does not have external antenna).

See the full list in Supported Hardware, which also has suggestions on which board to choose for which use. I have built almost identical sensors using the D1 mini V0 and V4 boards; and the C3 pico and S2 mini and the D1 pro V2 (which needs a larger box).

ENS160/AHT21 sensor

The ENS160 / AHT21 is a combination sensor, the AHT21 provides temperature and humidity readings, which are passed to the ENS160 which adds Total Volatile Organic Compound (TVOC) and equivalent CO2 (eCO2).

There is an Air Quality indicator as well, but this rarely goes above "1" so I am not sure if its working properly, or its designed for some seriously worse air. See issue #101.

The sensor can be sourced from a number of suppliers, these appear to be clones rather than a single manufacturer with resellers, and the reviews suggest some arrive with AHT20 (silver) and some with AHT21(black), the main difference is that the AHT21 detects -40°C-120°C while the AHT20 is only -40°C-85°C, for air quality this doesn't really matter.

The ENS160 is set to I2C address 0x53 and the AHT2x to 0x38 and there do not appear to be jumpers to change it.

I obtained mine for €6.37 but they are currently on sale for €3.28 including shipping.

Enclosure

Any box should work - depending on the physical situation of the sensor. I’ve been using Vange Moulding’s ABS boxes because ABS has some (though not perfect) UV resistance. For this project I use either 61x36x22mm at €0.31 which has a mounting hole; or the same size box without the mounting.

If you want to mount the sensor inside the box, you'll need to experiment adding holes to get decent air flow, if you get good results, I would appreciate pictures.

USB cable

I leave a USB cable plugged into the device. You’ll want one that is data+power for programming, but a simpler power-only one is sufficient once it has been flashed.

USB power supply

For the simplest project plug into a wall-mounted USB charger, any you have handy should work fine

Construction

Enclosure preparation

The box needs three cutouts.

  • A notch for the USB cable to exit through, I cut a small notch in the box, and then cut back the lip of the lid. I use a box-cutter heated over a gas burner, but it can also be done cold.
  • A tiny notch in the opposite end for the Sensor cable, again cut back the lip of the lid.
  • A hole for the antenna - select a drill just slightly larger than the screw shaft.

IMG_1910 IMG_1913

Wiring

The Sensor has to be connected by 4 wires to the dev board as in the following table. The actual pins on the Sensor are labeled.

Sensor D1 Mini Pro
3V3. 3.3V
GND GND
SCL D1
SDA D2

IMG_1912

It may not be necessary but notice how I use adjacent holes for strain relief.

ens160

The USB cord is just plugged in, it’s half in place by the walls of the box. Use blob from hot glue gun to seal the hole if you like, but I haven’t found it necessary.

Mount parts

The parts fit together as in the photo.

  • The sensor needs to be mounted externally - unless you want to experiment with air flow. This can be affixed however convenient, I find that tying a knot in the wiring just inside the enclosure can be sufficient, but I haven’t done this in a location exposed to moisture..

IMG_1914

Sorry this picture is of an SHT! But, looks the same with the ENS160+AHT21

Programming.

Follow the instructions at Programming and Configuring a Device on PlatformIO or Arduino IDE to set it up.

The example to clone for this sensor is examples/ensaht

Getting help

If you get stuck - please open an issue on Github. you will need an account, but its free.

Clone this wiki locally