März 9, 2020

Airquality Sensor

There are many reasons why one might want to measure the quality of air at a specific location, e.g. to see the impact of nearby environment like streets or factories, to improve factors of health, to regulate for conservation or sustaining a certain status or just to have even more data and connected IoT devices :)

The quality of air is a subjective perception but various aspects of air can be measured and together with recommended values be computed into some sort of quality level. Besides the common aspects of temperature and humidity, "total volatile organic compounds (TVOC)", CO2 (carbon-dioxide) and eCO2/CO2-eq (calculated equivalent carbon-dioxide), barometic pressure or fine dust are used to determine air quality.

There are products available like from Netatmo (*) and similar but they start at 100 Eur and one then has to use their eco-system and is bound to the good will of the manufacturer to provide updates, information on how the system works and ways to integrate/hack with other systems.

Therefor an opensource/self-built option is way more appealing.

There are basically three contestants for most of the air aspects mentioned above:

After some research which of them performs best, i went with the SGP30 because it was the cheapest, ready for shipping, easily connectable (i2c) and the one with the most resources available (libraries, howtos, example code).

Together with an SHT31-D temperature and moisture sensor (improves the calculation of the SGP30) and an NodeMCU (ESP8266-12E) board everything is hooked up like described here.

The firmware does the following:

  • Save calibration data (baseline) for SGP30 every hour
  • Load SGP30 baseline during boot
  • Perform some warm-up measurements during boot (sensor needs to really warm up)
  • Post measured values of temperature, relative humidity, TVOC and eCO2 to remote webserver each minute

This leaves some room for improvement:

  • Power saving/deepsleep modes (the SGP30 sensor must stay on though)
  • Local buffering of values to avoid constant WiFi connection

The webserver then writes the values into a textfile and provides a simple API and a graph based on CanvasJS which looks like this:
airquality_canvasjs

Room for improvement:

  • Security/Authentication
  • Grafana/Prometheus
  • Some sort of database (sqlite)

Code (firmware and server endpoint) will be uploaded soon.

It is important to note that the SGP30 sensor needs 12 hours to adjust to its location and values, then the baseline is set correctly (see this question).

(*) Affiliate Link