This project aims to implement a smart air quality sensor capable of making predictions regarding air quality for the day. The purpose of it is to give recommendations on outdoor activities based off air quality, as well as display real-time sensor data to the user. This device is of use to those wary of their health and well-being who may wish to do various outdoor activities, such as running or going for a walk around the block.
The device actively polls for air quality data from its sensors and displays it on its LCD screen. It stores hourly sensor data for up to 24 hours and makes a prediction of air quality for the following day on request. The predictive analysis is accessible to the user via an HTTP server.
The device consists of the following hardware components:
| Component | Details | Interface | Source |
|---|---|---|---|
| ESP32 | module with integrated Wi-Fi | - | emag |
| PMS5003 | particulate matter (PM1, PM2.5, PM10) sensor | USART | emag |
| BME280 | temperature, atmospheric pressure and humidity sensor | I2C | emag |
| LCD2004 | 4×20 character display | GPIO | emag |
This choice of components was a result of various considerations pertaining to the project's specifications. The ESP32 is a powerful, dual core chip better fit for predictive analytics in contrast with its counterparts. It features on-board Wi-Fi, crucial for remotely sharing predictive data. The BME280 and PMS5003 sensors were picked for availability reasons. A large 4×20 character display was chosen over its more common 2×16 alternative to better fit all the sensor data.
The BME280 module interfaces with the ESP32 board using its default I2C SCL and SDA pins, which need not be set in software. Its power is supplied by the board using the 3V3 pin, according to specification.
The PMS5003 sensor communicates with the ESP32 module via the serial interface. The RX and TX pins of the sensor are connected to the TX2 and RX2 pins of the module, respectively. The RX2 and TX2 pins were chosen over the RX0 and TX0 for spacial convenience. As per the specification, it is powered via the VIN pin of the ESP32 module which, while powered via USB, outputs 5V. This voltage is necessary for the sensor to function properly.
The LCD2004 display communicates with the ESP32 module via GPIO. The display can function under normal conditions while only using four data pins (D4:7). These four pins are connected to GPIO33, GPIO25, GPIO26, GPIO27, respectively for spacial convenience. The E (enable) and RS (cursor) pins of the LCD are connected to the GPIO14 and GPIO32 pins of the ESP32 module, respectively. The VO pin, which pertains to contrast control is also connected to a GPIO pin (GPIO4) which is capable of PWM. This enables contrast control from software, without the use of a potentiometer. The RW pin is pulled low via a connection to GND, which allows writing to the display. The display is powered via the VIN port of the ESP32 module, which outputs 5V while the board is powered using USB. The backlight, however, is undervolted to 3V3 (as opposed to its specified upper limit of 5V). This decision was made in consideration of power usage, despite the dimness.
LCD output and data readings from PMS5003 and BME280 respectively:
The program running on the microcontroller was developed and uploaded using ESP-IDF - Espressif’s official IoT Development Framework for the ESP32. The framework provides wrappers and abstractions for various features supported by the ESP32 family of microcontrollers. These streamline development and translate focus onto actual functionality. The following abstractions were used during development:
Aside from the libraries available inside ESP-IDF, the following third-party libraries were used for peripheral communication:
Predictions of AQI are made using a highly accurate regression model trained and deployed using the Edge Impulse platform. Edge Impulse provides tools and APIs for training and deploying machine learning models specifically on edge devices, including embedded systems. The model was trained on two years' worth of hourly readings of PM2.5 and PM10, starting from 2023 and ending in 2024. The readings were translated into an AQI following this US Environmental Protection Agency paper. The dataset was split into samples covering 24 hours, each labled as the AQI reading of hour 25. The readings are publicly available on www.calitateaer.ro.
All the previous components interact as follows:
A demonstration of the device is available at https://youtu.be/Bxe3qhWADMU.
The software implementation is available at https://github.com/Cosminovici22/pm_project.