SMOG = Raspberry Pi B z SDS011

[UPDATED 03-02-2018] SMOG sensor – 2,5 and 10 micro meter particles

[Last changes]:
07-11-2017: Additional data from richer stations, Open-Smog Integration
20-12-2017: USB power control on Raspberry Pi 3, thanks to reader
02-03-2018: New API from GIOŚ Poland

SMOG is common nowadays in big cities. Let’s put together a working, precise own SMOG sensor, first for the 2,5 and 10 μm size particles. There is one issue – the choices are many, but only few are reliable, precise and have affordable price. Finally – after a log searching, I’ve chosen Nova Fitness SDS011:

  • precision is OK
  • fan included
  • ability to mount a small tube to access external air
  • very realiable
  • UART with USB converter included
  • Low Total cost: around $40 (with Orange Pi Zero) up to $60 (with Raspberry Pi)

What will you need?

Hardware:

  • Raspberry Pi or clone (Orange Pi) with one USB port free
  • Nova Fitness SDS011 sensor with USB-UART included in package, it’s currently 15% off at Nettigo if you use the DIY_SMOG_15 code.  Luckily the SMOG is mainly attributed to low emissions, so fast delivery is the key.

Software:

  • favourite distibution – Raspbian or Armbian for clones
  • basic software included or optional in those distributions

Setup, configuration and graphs


The SDS011 should be connected to outside air via the duct and possibly very short tube (few cm). The picture above with the tube length of 100cm – is not advised the results are much lower than in real life.

Nova Fitness SDS011 on RPi B+ (tube too long)
Nova Fitness SDS011 on RPi B+ (tube too long)

Don’t forget that the sensor works constantly, so we will try to turn it on – only for the time of actual measurement. This version has a very simple solution – using Orange Pi with A20 CPU, I can selectively power the USB port pairs.

Sensor right under the roof
Sensor right under the roof

Another important caveat – sensor works only up to 70% of humidity, don’t forget that!
First – let’s install bc – needed for caluclations:

This is of first version of the sensor – meaning we will modify it for the extra humidity.
The communication with SDS011 is very simple – after inserting the delivered dongle in USB port we get the /dev/ttyUSB0 serial port – that we can use to read the data:

The data needs to be parsed to find “aac0” (SDS011 talks in hex, big endian), and the final value needs to be calculated. The whole code with updating the IndluxDB so Grafana can present nice graphs is here. Added comments to explain, used bash for simplicity:

Raspberry Pi 3 USB power control

Thanks to reader of the blog – Piotrek Pilek (cheers man!), we have also an option to control power on Raspberry Pi USB ports! (Piotr works at Lantech in Szczecin – check out this gem – https://lantech.com.pl/internet_szczecin_oferta/transmisje-live/)

Now, the control of power to USB port can be achieved by using Vadim’s Mikhailov, who created software for multiple powered USB hubs, Raspberry Pi included. Install the software:

Then, modify the lines in the example above (in the first lines):

to

And the same at the end of the file:

to

Caution – this command shuts down all USB ports, but not eth0 nor wlan0

Now, lets draw…

…the results just like last time in Grafana, the definitions are as follows:

Nova Fitness SDS011 - Grafana graph
Nova Fitness SDS011 Grafana graph

And that is it!

Sharing the data, external systems. Do you run your own project?

Our SMOG data are available and easy to share. If you run a system that gathers such data – write in comments – I’ll setup connection to your project and update this entry.
Current measurements, updated every 15 minutes are available at http://pogoda.jokielowie.com/

OpenSmog integration

Open-Smog is a new project, based on Artur’s Kurasiński idea. For details – check out Slacka: https://open-smog.slack.com/
Integration is simple – just add at the end of script:

I promised easy, right ?

Getting the data from regional smog sensors – Polish voivodeship – WIOŚ

OF course you’re curios how precise is our sensor. To verify – we can add official data from WIOŚ sensor: the map is here: http://powietrze.gios.gov.pl/pjp/current. Choose the sensor near you – here it’s the one at Koszyka Streen in Opol, that has this particular address (mind the ID): http://powietrze.gios.gov.pl/pjp/current/station_details/chart/10374. As pointed by Krzysztof Styc on Domoticz group – the WIOŚ share the current measurment in JSON format. Then around the end of 2017, they chnged it to new API at the address: http://powietrze.gios.gov.pl/pjp/content/api

This allows us to quickly get this data and put it to InfluxDB too – adding just couple of lines to our script:

Of course the script will vary from sensor – some give out much more data – the line needs to be modified (it’s usually about another print $7, print $8 etc.), i.e. for this Warsaw station, we can get more data:

After modification, we can get new variables i.e. PM10 or NO2
Our Grafana graph should now get new data (you can choose which to add in similar manner) – that we can put up against our own sensor data.

The actual visualized data, updated every 60 minutes, are available under http://weather.jokielowie.com/

Gauges – current SMOG data via WWW

The up-to-date information about particles in cubic meter can be also presented as gauges. Popular library with easy examples JavaScript that work in most browsers is present at: http://justgage.com/:

Zegary smogowe i pogodowe
SMOG Gagues

Downdload the ZIP called “justgauge”, unpack. Now lets prepare RAW version of our webpage. We will update it via InfluxDB – using stored temperature and humidity to find out if our measurements are correct.
Here’s the RAW version:

Save it as raw-index.html

The main script already has the values for 2,5 and 10 (ppm). Let’s incorporate them by adding lines to the script dodają te line also with temperature and humidity. In my InfluxDB example – they are named as “temperatura_out” and “wilgotnosc_out” – change them to your measured values as well as IP and database – and then – add those lines at the end of the script:

Ready! Let’s process our RAW index file and swap the values for real ones:

The index.html file could be now sent to external hosting after using “ssh keygen” and “ssh-copy-id”

If you got those line in order – in the main script – each launch will update the file on the remote server!