Lately, I moved buildings for my work towards a building which is very close by Eindhoven Airport. Only 430 meters to be precise.
The air-planes and kerosene smell triggered me about the health risks, and air quality inside the building as well as at home. The fact is that we have more and more cars/trucks within the residential areas (too bad still running on fossil fuel). Meaning our health is at risk, and apparently nobody cares. My idea was measuring is knowing, so lets start measuring!
Bills of Material
I want to measure the indoor air ‘quality’. But what is air quality? What to measure? And how..?
After some research, I came up with several indicators I think are important for the air we are all breathing and easy enough to measure via sensors. But besides air quality also comfort and energy efficiency could be taken along. The current list is as follows:
- Temperature, humidity and pressure;
- CO2 concentrations;
- Total Volatile Organic Compounds (TVOC) gas concentrations;
- Amount of fine dust / particulate matter.
We need to measure those physical data by some measurement device, often called sensors. I will use the following sensors for now:
- BME280 – Temperature, relative humidity and pressure sensor
- MH-Z19B – CO2 meter
- SGP30 – TVOC sensor
- PMSA003 – Fine dust sensor
Maybe in the future I can think about adding more sensors. The sensors we have now need to be attached to some board with the proper IO pins to read-out the data and to power the sensors as well.
I’ll use a single board computer: BeagleBone Black (I had this still laying around). Its quite similar to a Raspberry Pi or Arduino, but quite powerful and has tons of IO! See image below:
I ordered all required sensors (mainly from AliExpress) and tried to attach the sensors one by one to the BeagleBone Black. Two sensors are using I2C protocol to communicate while the other two sensors use serial TTL (UART) protocol. The BeagleBone black has plenty of IO to cope with request. Also some sensors require 5V to run, while others only need 3V3.
I took the Agile approach, and tried to implement one sensor at a time from begin to end, to have a working system all the time. And increase the amount of sensors + code + tests together. Meaning I started with the first device what came in, and gradually added to others as well.
Current state of the project is that I’m able to do read-outs from all the sensors mentioned above. I’m using the Linux device tree to mount the sensors as a device file in the
/dev folder. And using C++ to configure/init and read-out the data from the sensors. I’m using cmake cross-platform tool for pre-build and Ninja for the build system, which makes building and testing my code a breeze!
I took some time to get some special commands working, for example: the Fine dust sensor (PMSA003) has a stand-by mode and active/passive mode. The datasheet documentation was not always clear how long it took to get a device out of stand-by and in which state it started when you bring the sensor out of stand-by mode.
Luckily, I have a logic analyzer. A hardware device that can help you debug data lines (incl. protocols) between the sensor and the BeagleBone black. I used a Saleae logic analyser clone from China to debug my problems. You can attach this logic analyser to your computer, once you have firmware installed and I used a free open-source program called Sigrok to plot all the data visually (using PulseView). The screenshot below shows you the data on the line (zero’s and ones), the corresponding byte representation together with the protocol pieces (I2C in this case):
The logic analyser helped me in this case to debug the conflict between active mode (=sensor is pushing data on the line periodically) and passive mode (=the host need to request for data) during start-up of the PMSA003 sensor. Where it could take some time before the sensor acts on the requests.
The end goal is to create an easy to use device from the user perspective, properly with some kind of screen or webpage interaction/mobile app.
My personal goal is to also log the data into a database, and keep track of the air quality over a longer period of time. And plot those graphs by using Grafana.
AIR Quality meter is open-source for the public, you find AIR Quality project on my Gitlab server. If you like you can help developer the project further, add new sensors/add a screen interface or help with the code and/or testcases.
Will be continued 🙂Did you like the article? Please share!