An outdoor air quality station with Enviro+ and Luftdaten

Let's contribute to citizen science! We're going to build an air quality monitoring station that can be mounted outside your house (or office, or wherever) that sends data to Luftdaten, an open data project that maps air quality using low-cost air quality monitoring devices.

We built Enviro+ specifically for this purpose (as well as lots of other uses) as, traditionally, air quality monitoring devices have been out of reach for most people, costing tens of thousands of pounds. This project costs less than a hundred pounds, and can be built and deployed in just a couple of hours.

This tutorial will guide you through attaching Enviro+ and the particulate matter sensor to your Raspberry Pi Zero W, installing the necessary software, signing up to Luftdaten, and then fitting your Enviro+ in a weatherproof housing that can be attached to the outside of your building.

Note: make sure that you have permission to attach your Enviro+ air quality monitor to wherever you're attaching it!

This article was written in 2019 and may now contain out of date information. Luftdaten has since been renamed Sensor.Community and can be found at https://sensor.community/ You can find updated installation instructions for the Enviro+ library here.

What you'll need

Here's a list of what you'll need for this project:

It should take a couple of hours to put everything together.

Attaching Enviro+ to your Raspberry Pi Zero W

Although Enviro+ works with any 40-pin version of the Raspberry Pi, for this one you'll need to use a Raspberry Pi Zero W, due to its small size and built-in wireless networking. We'd recommend the Pi Zero WH, as it comes with a pre-soldered header.

First, let's attach the metal standoffs to your Enviro+. Hold the standoffs underneath the mounting holes at the four corners of Enviro+ and use four of the metal M2.5 screws to secure them. If you're using just two standoffs, then attach them to the two mounting holes on the front edge of Enviro+ (the long edge furthest from the header).

Push the Enviro+ female header down onto the male header of the Pi Zero W, making sure that all the pins are lined up correctly, and secure with the remaining M2.5 metal screws.

Attaching the PMS5003 particulate matter sensor

Note: do this part BEFORE powering on your Pi, as hot-plugging the sensor will cause you Pi to reboot!

Plug one end of the cable (supplied with the PMS5003) into the connector on the PMS5003 particulate matter sensor.

Note: it'll only fit easily one way round, so if you're having to force it then stop what you're doing and try it the other way round!

Plug the other end of the cable into the connector on the underside of Enviro+ (below the PM label on the top side), again making sure that the cable is going in the right way round!

You can peel the blue plastic protective film off the particulate sensor if you wish, but leaving it on won't cause any problems.

Setting up your micro-SD card

You can find really good instructions on how to set up your micro-SD card with the Raspbian operating system in this guide from Raspberry Pi. If you're a beginner, it's best to use the full "Raspbian Buster with desktop and recommended software", as it's a little easier to set up and use, but you can also use Raspbian Lite, if you want. This tutorial will only cover how to set things up with full Raspbian Buster with desktop and recommended software.

Booting up and connecting to Wi-Fi

Before we put everything into its weatherproof housing, we'll need to boot the Pi up, connect it to Wi-Fi, set all of the software up, and test to make sure it's working properly.

Note: this is a good opportunity to test your USB cable and power supply to make sure that they can supply enough power to run your Pi Zero W, etc, so use the same cable and power supply here as you'll be using for the final build.

You'll need a display, keyboard, and mouse connected for this part, as it'll involve some typing and such. If you don't want to fiddle around with USB hubs (which you'll need to connect the keyboard and mouse to the Pi Zero W at the same time) and such, then you can do this next setup part on a Raspberry Pi 3 B+, if you have one, and then switch the micro-SD into the Pi Zero W once it's done.

Pop the micro-SD card into your Pi and boot it up now. Because it's the first time you're booting the Raspbian OS, it'll guide you through connecting to your Wi-Fi network. Connecting to Wi-Fi is essential for the rest of this tutorial.

Installing the Enviro+ software

Now that we've booted up our Pi and connected to Wi-Fi we can install and set up the Enviro+ software!

Open a terminal (press control-alt-t or find it in the Raspberry Pi menu) and then type the following:

git clone https://github.com/pimoroni/enviroplus-python
cd enviroplus-python
sudo ./install.sh

There's just one other requirement that's needed by the Luftdaten script we'll be running that's not installed either by default in "Raspbian Stretch with desktop and recommended software" or by our installer.

Type the following in the terminal:

sudo pip install smbus2

Once that's all done, type sudo reboot to reboot your Pi and apply the changes to the Pi's interfaces.

The install script enables I2C, SPI, and serial, disables the serial console, and enables the miniuart interface that the Pi uses to talk to the PMS5003 particulate sensor.

If you ever need to revert these changes to the UART and serial configuration, then you can run the uninstall script by typing sudo ./uninstall.sh within the enviroplus-python folder in the terminal, and then sudo reboot to reboot and apply the changes.

Testing the Luftdaten script

Our Luftdaten script reads the temperature, pressure, humidity, PM2.5, and PM10 (both measures of the concentration of particulates in the air, 2.5 microns and less and 10 microns and less in ug/l of air) and sends those data to the Luftdaten server.

For Luftdaten to receive data from your Enviro+, you'll have to register with them and add the serial number and details of your device (we'll do that in the next section), but the script will still run without that being set up.

Let's run the script now. Type the following in the terminal:

cd enviroplus-python/examples
python luftdaten.py

The script will print the readings from the sensors to the terminal. It'll also display the serial number of the Pi that you'll have to enter on the Luftdaten site on the LCD on Enviro+. Take a note of the serial number now.

If possible, it's good to leave the script running until we've registered with Luftdaten and set up our device, as we should be able to see the data starting to come through once it's set up. If not, you can press control-c to stop it and then start it again after we've registered with Luftdaten.

Registering with Luftdaten and setting up your device

On a separate computer, head to: https://meine.luftdaten.info/register

Type your email address that you want associated with the account and a password and then click "Register". Complete the registration process by following the URL sent by email.

Click on the "My sensors" page and then "Register new sensor".

In the box that says "Sensor ID", type in the serial number that you made a note of earlier from the Enviro+ LCD, making sure that you type it carefully and correctly.

Under "Sensor Board", select "raspi".

Give your sensor a name in the box that says "Personal sensor name", something like "Eric's Enviro+", and then fill in your address details. If you don't want to reveal your exact location, then you can leave the "Publish exact location" box empty.

In "Additional information", fill in the details of where your sensor is located.

Under "Hardware configuration", select "PMS5003" from the first dropdown, and "BME280" from the second dropdown. Do not change the numbers in the PIN boxes! They should be "1" for the PMS5003 and "11" for the BME280.

Click the "Lookup entered address" button and then pinpoint your location on the map, or enter your latitude and longitude manually.

Scroll to the very bottom and click "Save settings" to save the entered sensor settings. On the "My sensors" page, you should now see your sensor listed.

If you still have your sensor running, then you should see that the responses are now successful, as the Luftdaten server knows now to accept your data. If you don't still have it running, then run the example again now, following the instructions above in "Testing the Luftdaten script".

After a few minutes, you should see the "Last Update" time and date change to indicate that data has been received. If you click on "Data", then you'll see the most recent data, and if you click on the links "show on map", then you'll see your data on the map.

This means that your Enviro+ is working and sending data successfully to Luftdaten!

If you click on the tab at the bottom left corner then you can change the variable being displayed. You can also download your data as a CSV from: https://archive.luftdaten.info/.

If no data is being sent (i.e. it says "Response: failed" in the terminal), or if your data is not appearing on the "My sensors" page after more than 10 or 15 minutes, then double-check that you entered the serial number correctly from the LCD and that no other errors are appearing in the terminal.

Running the script automatically

We want the luftdaten.py script to run automatically when your Pi boots up, so that we can put it into the housing, plug it into the power, and then have it just work.

An easy way of running a script automatically on boot is to use crontab, a job scheduler, which has an @reboot command that will run a script or command when the Pi first boots up.

In the terminal, type crontab -e and then select nano as the editor.

Scroll down to the very bottom of the file with the arrow keys and type the following line:

@reboot sudo python /home/pi/enviroplus-python/examples/luftdaten.py &

Double- and triple-check this command to make sure that it's exactly correct, as any error will cause it not to run on boot.

Press control-x, then y, then enter to exit and save the new crontab.

You should now shutdown your Raspberry Pi Zero W, either through the Raspberry Pi menu, or by typing sudo shutdown -h now in the terminal.

Now, let's go ahead and build it into the weatherproof housing!

Mounting your Enviro+ in the weatherproof housing

For this part of the tutorial, you'll need a few things:

  • 2x pieces of square 112-degree gutter downpipe offset bend (65mm dia)
  • 3M Command Strips (we got the medium-sized ones)
  • Some duct tape
  • Long cable ties

You should be able to get all of these bits at your local DIY/hardware store. We got our bits from B&Q in the UK, but you should also be able to find them all at Amazon, They'll cost around £10 or less in total.

Let's start to build it!

First, we'll attach the Command Strips to the bottom of the particulate sensor. They're great because they let you remove your Pi and particulate sensor from inside the housing if you need to, but otherwise hold it really securely.

Peel the backing off from one Command Strip and stick it onto one side of the particulate sensor. Take another Command Strip, line it up with the one you stuck on the sensor and then push them firmly together.

Take one of the narrower (male) ends of the downpipe bend, peel the backing paper off the exposed Command Strip and stick it just inside the top of the pipe, so that the cable sticks outward and the fan side of the sensor faces down inside the pipe.

Now, take the Pi Zero W and stick another two Command Strips onto the underside, in a similar fashion to the sensor. In our testing, we haven't had any issues with the Command Strip or its adhesive shorting any of the test pads on the underside of the Pi Zero W, but if you're concerned about it then you can stick some electrical tape onto the underside first.

Plug in the particulate sensor cable if it isn't already still plugged in.

This next part if slightly tricky and might involve some trial and error to get things positioned just right. The basic idea is to mount the Pi Zero W at an almost 45-degree angle so that the USB power cable can fit.

Thread the USB cable up through the second piece of downpipe bend, and plug it into your Pi Zero W before doing this part, so that you can tell whether it's fitting.

Stick the Pi Zero W just below where you mounted the particulate sensor at an angle, so that the USB cable connector will fit once the other piece of downpipe bend is pushed on.

Test the fit of the other piece of downpipe now, making sure that it's pushed all the way in, and don't force it if the USB power cable is preventing it going together. Instead, take it apart again and reposition things to make them fit correctly.

Before we tape the two pieces of downpipe together, it's a good point at which to test that the script is running on boot correctly and still sending data to Luftdaten. Plug the USB power in, leave it for 5 or so minutes, and then check the "My sensors" page at Luftdaten to ensure that data is being sent.

Finally, use some duct tape to carefully seal along the join between the two pieces of downpipe bend to ensure that no water gets in. An alternative is to seal the join with some silicone sealant and then use duct tape on top to hold everything secure, if you want it to be especially watertight.

Mounting your housing outside

We mounted our housing to a downpipe from the guttering using some long, heavy duty cable ties, as in the photo below, but we'd encourage you to get creative with where and how you mount your housing.

Again, make sure that you have the appropriate permission to mount your Enviro+ housing wherever you're mounting it, and take the necessary precautions if you're using a ladder and/or working at height.

Power alternatives

We used a long USB (A to micro-B) cable and USB power brick, but you could also use some good-quality heavy-gauge wire or Cat5e cable, a 5V supply, and solder straight to the 5V and ground pins on the Enviro+ (on the GPIO breakout pins).

Another option, which limits the potential for voltage drop across your cable, would be to use one of our Wide Input SHIMs and a 12V power supply with a long barrel jack cable, similar to those used for CCTV systems. The advantage of Wide Input SHIM is that it will provide a regulated 5V at 2A, plenty to power your Enviro+.

Upgrade ideas

A couple of pieces of fairly course plastic meshing cable-tied around the ends of the housing can help to prevent insects or birds from taking up residence in your housing. Make sure that it isn't too fine though, or it will prevent air (and particulate) flow to the sensor.

You could adapt your code and add an LED that sticks through a hole in the housing to show whether the script is successfully sending data to Luftdaten, again using the GPIO breakout pins on Enviro+ (the pin marked #4 AKA pin BCM 4 is ideal).

Make sure that you share your Enviro+ hacks and modifications with us on Twitter or Facebook!

That's all folks!

Search above to find more great tutorials and guides.

Plasma 2040

Swathe everything in rainbows with this all-in-one, USB-C powered controller for WS2812/Neopixel and APA102/Dotstar addressable LED strip.