Welcome to my open-source Air Quality Sensor IoT Project! This project monitors your home's indoor air quality in real-time using IoT technology and feeds you data in JSON over a web server.
This project includes:
- A data sampling and upload script, written in MicroPython, running on a Raspberry Pi Pico W.
- An ENS160 Digital Metal Oxide Multi-Gas Sensor, used for monitoring Carbon Dioxide (CO2), Total Volatile Organic Compounds (TOVC), and the Air Quality Index (AQI) of your home via the I2C protocol.
- An AHT21 Integrated Temperature and Humidity Sensor, used for monitoring ambient temperature and humidity of your home via the I2C protocol.
- A 3D-printed housing box for the Raspberry Pi Pico W and sensors (optional).
I am using a single breakout board that contains both an ENS160 and AHT21 on one board, found here.
The Raspberry Pi Pico, along with the ENS160 + AHT20 sensor breakout board live neatly in a small 3D-printed enclosure:
You can easily move this source code to a Raspberry Pi Pico W, hook that Pico W up to an ENS160 & AHT21 sensor, and deploy. The source code will:
- Validate and set up the ENS160 and AHT21 sensors.
- Connect to your wifi network (using credentials you specify in the settings.py file)
- Take air quality and condition measurements from the ENS160 and AHT21 sensors.
- If the air quality measurements were unsuccessful, restart these sensors and troubleshoot until they are operational.
- Upload these readings via HTTP POST request to an endpoint you define in the settings.py file.
- Wait for a predefined amount of time, specified in the settings.py file (default is one minute).
- Repeat steps 3-6 in an infinite loop, sampling and uploading data at a regular interval!
There is a watchdog timer implemented to ensure long-term functionality is preserved.
I modeled a simple housing tray for the microcontroller and sensors required for this project. You can download the 3D Model (STL file) here directly from this GitHub repo.
In May 2024, I changed the core functionality of how the Raspberry Pi Pico W performs: instead of being a server, responding to HTTP requests, it now instead samples data at a regular interval and uploads this via POST request to a defined endpoint.
All of the code and literature behind this old version can still be found by reverting to commit 3d04d5e89972443a98873347cb8421cb2e6d45a3
.