Designing and building an air quality monitor

Around a year ago the headmistress of the school asked if it would be possible to build a device capable of monitoring the air quality around the school in real time. The computer science teacher directed her to me and I was asked to do some research and put together a shopping list of the parts that would be needed.

I decided to use LoRa and the Things Network for communication because the school already had a receiver we had bought using some of the money from the DVLA coding competition. Additionally, LoRa is a low power protocol and I already had some experience using it.

It also made sense for the monitor to be solar powered so that it wouldn’t have to be connected to the mains and would have a smaller carbon footprint.

My final design for the system was an Arduino Pro Mini with an RFM95 LoRa chip for communication and a solar panel with a charger and an 18650 Li-ion battery for power. It had three sensors: the CCS811 for measuring total volatile organic compounds and estimated CO2, the PMS5003 for measuring particulate matter and the grove multichannel gas sensor for measuring nitrogen dioxide and carbon monoxide:

A Fritzing schematic I created while documenting the system

It took a while for the parts to arrive and another while for me to build the system. The most problematic part was the solar power – I struggled to find resources on how to calibrate and use the CN3791 Li-ion charger I was using. You had to unsolder an SMD resistor in a voltage divider to calibrate it, and as I had no SMD resistors I had to solder the PCB to a matrix board and use through-hole resistors instead. While testing it I accidentally short circuited and broke the Li-ion battery on a metal table edge and it had to be replaced with a new one.

I created the enclosure using 2D design and the DT teacher laser cut it. The two sides are triangular, with the hypotenuse at the optimum angle for the solar panel to generate power in the winter. In the centre is a watertight box where all of the electronics are housed. We only just managed to get it printed, glued and sealed before the lockdown started.

The data recorded by the system is stored on a Raspberry Pi server running an Nginx reverse proxy to handle HTTPS along with a Node-RED dashboard and a Node.js API. A SQLite database is currently used, but I might upgrade to MariaDB or MySQL in the future. I also want to transition from a Raspberry Pi to a virtual Debian machine on the school’s servers.

I finished the system and it was put up on a wall overlooking the school car park in June:

The cable you can see at the bottom is the power cable going from the solar panel to the circuitry inside.

It took me until now to finish documenting the system because I couldn’t access the enclosure design files which were on the school computers.

The server has a FreeDNS subdomain and self-signed HTTPS certificates, so the only running cost of the system is the electricity for the server. The dashboard shows you live data which is transmitted every 15 minutes as well as a calculated air quality index score:

Live data
Calculated air quality index

I’ve also created a comparison dashboard with Chart.js that uses the API to let you compare averages from two time periods. For example, here is a comparison of the particulate matter levels on weekends in September and October (taken in multiple screenshots because the page is quite long):

Additionally, I made a GitHub repository for Jupyter notebooks analysing the data.

I’ve learned about a lot by doing this project, such as:

  • Different air pollutants
  • Designing parts for laser cutting
  • Reducing the power consumption of Arduino projects
  • MPPT, solar charging and lithium-ion batteries
  • Documenting APIs using Swagger
  • Using Nginx and Node-RED
  • Firewalls
  • Linux services

If I did it again I would design a PCB to connect all of the components together instead of using wires and matrix boards to make it more compact and organised.

Leave a comment

Design a site like this with WordPress.com
Get started