Build an Air Quality Sensor with Raspberry Pi and Enviro+
Are you curious how you can contribute to a citizen science initiative? Does the idea of building your own electronics to analyse the environment around you sound exciting? Then I have a project for you!
I will show you how easy it is to build a device to monitor air quality and contribute the data collected to Sensor Community (formerly Luftdaten), a global network of DIY environmental sensors.
So we can have some fun and learn together, I’ve chosen a path that is on the more accessible end but still requires some DIY electronics, building, and coding. This project will use the incredible Raspberry Pi platform and an Enviro+ Air Quality monitor HAT as a sensor package. You’ll need some basic skills in electronics, programming, and configuring Internet of Things (IoT) devices.

What we will be building together is just one option for those looking to collect and contribute air quality data. If you think this project looks too easy or too hard, know there are many other options, from building and programming everything yourself to buying an off-the-shelf solution that needs power and the internet. So, I encourage you to search for modifications that work for you.
Before we dive in, let me give you some background on why I’m passionate about this project. If nothing else, I would love to convince you that understanding the air quality around you is so important.
Today we welcome guest author Ganesh Shankar, tinkerer and engineer. Stick around until the end for ways to connect and engage with him.
Why Air Quality is Important
Most of us know inherently how vital a balanced diet is. Similarly, clean air is essential to our health and well-being. According to the WHO, air pollution kills an estimated 7 million people yearly. Human-driven industrial activity (e.g., factories, transportation, agricultural burning) and climate change (e.g., larger, more frequent fires) further exacerbate the problem.
When I was two years old, I was diagnosed with Asthma, a chronic condition I’ve lived with all my life. Being an asthmatic makes you very aware of the air quality around you, as irritants like pollution, smoke, pollen, and dust can quickly leave you out of breath and possibly even in a life-threatening situation.
I’ve lived in Singapore, Australia, and Germany, three countries with very different air quality characteristics, and three different experiences for me as an asthmatic.
Singapore’s Air Quality
Singapore is a highly developed city with better air quality than most Asian cities. However, I remember distinctly from my childhood an annual phenomenon called “The Smog” when asthmatics and those with respiratory issues were told to stay indoors. The Smog was a human-created issue caused by farmers in nearby Indonesia doing mass burnoffs during the dry season to clear land for palm oil and paper plantations.

Australia’s Air Quality
Being sparsely populated and with lower industrial activity than other countries, Australia enjoys relatively low pollution from human-made sources. In general, air quality in the southern hemisphere is better because it is less populated than the northern hemisphere.
However, that doesn’t mean that air quality isn’t a concern in Australia; substantial pollen blooms during springtime and extreme weather create risky scenarios such as thunderstorm-triggered asthma attacks. Also, hotter and drier weather driven by climate change leads to more frequent and more significant bushfires in summer, another primary air pollution source in Australia.

Germany’s Air Quality
For the last six years, I’ve lived in Munich, Germany, where my sensitivity to pollen and smoke has been at its lowest. However, mainland Europe has had to keep a close eye on pollution created by industrial activity and diesel vehicles, which are notoriously bad for making the particulate matter that most of us think of as air pollution. During lockdown in Germany, I noticed that my apartment’s air quality was declining, likely because my partner and I were home more often.

As you can see, many factors influence the air quality in your region. As with all good science, we need data and a lot of it to understand the world around us. Collecting an accurate picture of air quality trends in your area can help researchers look for a robust dataset and use this data to advocate for improvements with your local representatives.
At a very pragmatic level, you can use the sensor we built today to help you understand when to open your windows to improve the air quality inside your home and when to shut them down to avoid dangerous conditions. Here in Germany, some rental contracts require you to open your windows for 10 minutes daily to get ‘Frische luft’ for good health.
In other cases, pollution might be so harmful outside with heavy smog you want to keep your windows closed and run an air filter fan in your house.
Did you know that new furniture and textiles can pollute your apartment or house over several years and airing out your place is essential to keeping you in good health?
I hope I’ve convinced you to at least become more interested in the air quality around you. For those who want to dive deeper to contribute to citizen science and improve air quality, let’s get tinkering.
Technology’s Contribution to Citizen Science
Before we dive into the project, I want to share a bit of background on the technology we’re working with and why we live in such an exciting time for citizen science and technology projects.
I’ve always been a giant nerd, fascinated with taking technology apart and building computers from a young age. When I started my career as an electrical engineer, it used to be extremely difficult and expensive to mess around with electronics – which meant only the most dedicated hobbyists dabbled in making circuits. Scientific instruments were considered specialised, and sharing data with the world was a significant challenge.
Thankfully, a few innovations over the past 10 years have lowered the barrier to entry, meaning that it’s relatively easy to create basic electronics projects and have a lot of fun along the way. If you’ve ever wanted to automate some of the lights in your home, set up a wildlife camera, or create a weather station, we live in a time when technology has made these projects easy for almost anyone.
Open-source hardware, like the Raspberry Pi, makes getting started a breeze.
Introduction to Raspberry Pi
Why Use Raspberry Pi?
For our project, I’ve selected the Raspberry Pi as the platform to build on.
The Raspberry Pi is a low-cost computing device designed by an open-source foundation looking to promote basic computer science teaching in developing countries. By creating straightforward and hardy miniaturised computers that fit on a single circuit board (about the size of the palm of your hand), the device became popular with makers who wanted an easy way to experiment with sensors and robotics.
Since its early years, the Raspberry Pi has undergone four design iterations, resulting in a larger format B model and a compact Zero model. The beauty of the Raspberry Pi is that it is cheap and has a low barrier to entry; if you can use a computer, you can use a Raspberry Pi.
The Raspberry Pi runs a Linux operating system with built-in networking, video, audio, and USB so you can plug it into power, a screen, monitor, and keyboard and write programs for it from the device itself!
HATs for everyone
The other attraction of the Raspberry Pi is the community of independent hardware vendors who make add-ons called HATs. If you look at the Raspberry Pi board, you’ll see a double row of pins sticking out from one side.

These pins allow access to power and input/output control signals from the device, making attaching custom hardware to the computer trivial. These easy connections encouraged manufacturers to create modules that could slot into the header and add superpowers to the Raspberry Pi.

These modules are called HATs, which stands for Hardware Attached on Top. Welcome to the wonderful world of Engineering humor :-) The HATs allow for easy customization and the magical ability to turn a Raspberry Pi for all citizen projects.
HATs have a row of slots to place on top of the Raspberry Pi.
Materials You’ll Need
We will use the compact Raspberry Pi Zero W for our project. Being compact means it is less powerful, saving energy and space (but still more than powerful enough for our needs). The W in the name means that this model has built-in networking, which is important for connecting to Wi-Fi and sending data to the Sensor Community.
I recommend purchasing this model, which comes with the header (the rows of pins) pre-installed, so you don’t need to do any soldering unless you want to. I discuss both options below.

The next piece of hardware we will use is the Enviro + Air Quality HAT sensor HAT, created by Pimoroni. All the sensors we need for this project are conveniently packaged into a small circuit board ready to slot on top of the Raspberry Pi Zero W – convenient, right?
Finally, we will need the PMS5003 Particulate Matter Sensor to plug and play with our Enviro + board. Without it, you could still make a pretty fun sensor package. However, it helps record outdoor air quality and send data on the particulate matter to Sensor Community, allowing us to measure PM 2.5 and PM10 data.

Some additional bits and bobs you’ll need:
- A computer to set up and configure the Raspberry Pi
- Micro USB Power supply for your Raspberry Pi (an old phone USB charger should do, but you can also get an official Raspberry Pi one)
- Micro SD Card (8Gb is plenty) to hold the operating system of your Raspberry Pi.
- A way to read/write to your SD card from your computer.
- PVC drainpipe, zip ties, velcro command straps, and duct tape to mount your air quality monitor outside. Most of this can be found at a DIY store, so pick what works for you, but I’ll show you what I did later on.
- [Optional] An anti-static work mat.
- [Optional] A case for your Raspberry Pi like the Pibow Zero W, which protects it but leaves the header exposed so we can add the HAT
- If you don’t want a case, I recommend getting four standoff screws to help mount the Hat securely.
Step 1 – Preparing Your Operating System
For the Raspberry Pi to work, you need to load an operating system to the micro SD card. Think of it as the same way a computer has a hard drive. The Raspberry Pi Foundation makes this super easy.
1.1 Visit https://www.raspberrypi.org/software/
1.2 Install the Raspberry Pi Imager onto your computer
1.3 Insert your micro SD card into your computer via an SD Card reader

1.4 Open the Raspberry Pi Imager and click Choose OS
1.4.1 Click Raspberry Pi OS (other)

1.4.2 Select Raspberry Pi OS Lite
Why select the Raspberry Pi OS Lite? It’s a version of the operating system with no desktop environment, meaning we won’t be using applications like a browser, etc. The Lite version is better since we won’t be using our Raspberry Pi as a traditional computer. It’s faster to install, runs faster, and is easy to access remotely from our computer.

1.5 Select Choose SD Card and pick the micro SD card you inserted (you might need to format it)
1.6 Select Write and wait until the Raspberry Pi Imager says it’s done.
Now, because we installed Raspberry Pi OS Lite, there are a couple of additional configuration steps we want to do to preconfigure the device so we can remotely access it when we power it up.
1.7 To configure your device to connect to your Wifi and enable SSH (our way of connecting to the device remotely), follow these instructions.
1.8 Test the connection of your Raspberry Pi.
Insert the SD Card, power up the device, wait a few minutes, and then SSH into raspberrypi.local (or the IP address of the device you found earlier)
Step 2 – Hardware Assembly
The second phase of our project involves assembling the Raspberry Pi, Enviro + HAT, and case if you have one.

2.1 [If Required] Attach your header to the Raspberry Pi Zero W
I used a Pi Zero W Starter Kit for convenience, but note that this kit requires some basic soldering to attach the Pi Zero W board header. I have a soldering iron at home and was keen to dust off my skills. If you’re uncomfortable working with solder (it’s like a mix of hot glue and welding), I recommend buying the pre-assembled Pi Zero WH or the Starter Kit and a Hammer Header kit to make this step much more manageable.

2.2 [Optional] Assemble the Pibow Case
Make sure your SD Card is inserted (as you won’t be able to get to it again quickly once you build the case), I assembled the Pibow Zero W as per this guide.

2.3 Attach the Enviro + Air Quality HAT
Follow this excellent guide from Pimoroni on attaching your Enviro + Air Quality Hat and testing its functions.
** Make sure to use gentle force when you push the HAT down onto the header pins. You will need to push a little, but double-check to make sure it’s oriented the right way (the HAT should sit over the board) and with all pins aligned, and don’t force it!

2.4 Attach the Particulate Matter Sensor
If you didn’t do so in the previous step, ensure your Raspberry Pi is powered off and attach the Particulate Matter Sensor – the cable only goes into the socket in one orientation, so use that gentle force once more.

Step 3 – Software Configuration and Testing
Now that we have the board assembled, we are done with the hardware part. It’s easy, right? It’s time to fire up our device and see how it works.
Since I recommended installing the headless Lite version of Raspbian OS, you’ll need to SSH into your device for this next part (the last part of this tutorial we did earlier when setting up the Operating System)
Once you have the Command Prompt of the Raspberry Pi up on your terminal, resume the Pimoroni Getting Started guide at the step called Installing the Enviro+ Python library.

If you’re able to successfully run the examples at the end (my favourite is the one that powers the little screen with data), then you are almost done! Congratulations, you’ve (hopefully) successfully assembled the hardware and software—Pat yourself on the back.

Step 4 – Register to Contribute to Citizen Science
Now that we know our Raspberry Pi and air quality sensors are working, it’s time to contribute to the world of science!
For this part, we’re following this guide from Pimoroni, which takes the existing sensor package and adds a script that lets us talk to Sensor Community.
You can skip most of the guide as we configured almost everything in Part 3, but review Installing the Enviro+ software as there is an additional step at the end of it. When following the guide on registering your device, note that Luftdaten is now called Sensor Community and has a slightly updated site. That said, the flow was ~90% the same.
**Note: if you get an error when trying to run the command:
python luftdaten.py
You might be missing a required Python module Requests; run the following command:
sudo pip install requests
Once I ran the command, the error was resolved.
4.1 Register an account with Sensor Community
Go to devices.sensor.community and follow their prompts to get set up and contribute to citizen science. Make sure to do this before you place it outside.
4.2 Register your sensor on Sensor Community
Use the number on the LCD while running: python luftdaten.py

With that, our air quality sensor is ready to go into the outside world! They grow up so fast.
Step 5 – Weatherise for Outdoors
While the Raspberry Pi is a hardy little computing device, there are some precautions to take when putting electronics outdoors.
We will need to ensure that we put our device into a weather-proof container while still allowing air sampling access. You may also want to take precautions to prevent birds/animals from building nests in there.
I followed the Mounting your Enviro+ in the weatherproof housing section of the same Pimoroni Guide as Step 4. Unlike the rest of our project, you can feel creative here. You’re unlikely to find the same type of piping in all parts of the world, so find some PVC drainpipe that you can assemble to hold the device. Ensure it’s waterproof and aimed downwards so air can still get in, but water can’t.

**Note: When assembling the case, it might be a little challenging to push the Raspberry Pi with its power cable into the pipe, especially if you used the same case and pipe.
I found that removing two screws from the right side of the Pibow case (don’t worry, it won’t open) and using a wire clipper to strip off some of the bend protection on my micro-USB cable (we do want it to bend here) helped me make it fit snugly.


Finally, find a great place to mount your sensor (usually, a drainpipe or balcony railing provides the right spot). We put ours on our balcony!


Step 6 – Analyse Your Sweet, Sweet Data
6.1 Go to devices.sensor.community and log in
6.2 Click on Data
6.3 Click “Show on Map” to see the air quality data for your local area centered on your device.
You can change the filter on the bottom right to see various data like PM 2.5, PM 10, and Air Quality Index. It’s pretty sweet, eh?

What is the official Air Quality (AQI) where you live? As you can see, they have excellent data coverage in Europe but could use additional sensors in other parts of the world. So, if you live on any other continent, It would be super cool to set up one of these and add your data.
Since I first wrote this article, we have moved to North Vancouver, Canada. You can see our little dot, adding to North America.
Discuss and Share
How awesome is it to be a citizen scientist contributing data to help alleviate global air pollution?
I was thrilled to find this project and share it with you. I hope you found the same joy from learning a little about electronics and citizen science data collection. The Raspberry Pi is a revolutionary device for the world of makers.
I hope that once you’ve experienced how simple creating an air quality sensor is, you’ll move on to other citizen science projects, too! For something to noodle on, here are some ideas for other Citizen Science initiatives that use Raspberry Pi – from a traffic monitor to a wildlife camera. make sure you read all the ways you can get engaged as a citizen scientist with no skills required!
- What was your favourite part of this project?
- Why is air quality important to you – what’s the quality like where you live?
- What factors contribute to air quality (good or bad) in your home region? Industry, cars, fire, pollen? Or, maybe you live near a forest that cleans the air.
- Do you have any questions – ask away!
Share your progress and answers to the questions in the comments; I look forward to reading them. Happy making, and stay curious!









Nice! The Envirohat looks pretty neat! I like the new format. Hope you are all well.
I know it was super easy to work with and a lot of fun to make. We’re doing great, hope you all are well too – Ganesh.
Sounds very interesting. I mightvtry that too
You should try it, it’s loads of fun and a great citizen science project. Let us know if you try it.
Thanks a lot for this!
Can you comment on how luftdaten.py should be modified when there’s no PM sensor present? The default script fails shortly after beginning, as it pings the PMS5003 and doesn’t find it. Even the LCD fails to start, showing only white noise.
I’ve tried removing a few mentions to PM sensor from the script, but even when it kinda worked eventually the log started showing errors related to the missing PM data.
hi! I don’t know if anyone will see this comment, but I want to make a change to this code so that while it is running the luftdaten script, it is also showing the data on the LCD like ti does in the all-in-one example. does anyone know how to do that?