Skip to main content

How to make a Raspberry Pi Home Air Quality Monitor

Raspberry Pi Air Quality Monitor
(Image credit: Tom's Hardware)

I’ve been more concerned about the quality of air in my house recently. I’ll soon be paying for a service to clean the furnace and duct work, and I wanted a way to determine if there’s been any measurable impact or change. Fortunately, using a SDS011 sensor, a Raspberry Pi and a bit of software, I can create a simple home air quality monitor. Here’s how to do it. 

What You’ll Need For This Project 

How to Make a Raspberry Pi Home Air Quality Monitor 

Before you get started, make sure that you have your Raspberry Pi OS set up. If you haven’t done this before, see our article on how to set up a Raspberry Pi for the first time or how to do a headless Raspberry Pi install (without the keyboard and screen).

1. Install git, which will allow us to clone the code from github.com

sudo apt-get update && sudo apt-get install -y git

2. Clone the repository with example code. This code takes care of communication with the sensor, and sets up a simple server for monitoring on your home network. 

cd ~/
git clone https://github.com/rydercalmdown/pi_air_quality_monitor.git

3. Run the installation command after descending into the repository. This will take care of installing all base dependencies, like Docker and Docker Compose to make this project run. 

cd pi_air_quality_monitor
make install

4. Run the build command to build the docker images. This may take a bit of time depending on your Raspberry Pi. 

make build

5. Connect the SDS011 sensor to the USB adapter it comes with using the provided jumper cable. 

(Image credit: Tom's Hardware)

6. Connect the SDS011 USB adapter to your Raspberry Pi. You may see a flashing red light, but if not, don’t worry. 

Image 1 of 2

Raspberry Pi Air Quality Monitor

(Image credit: Tom's Hardware)
Image 2 of 2

Raspberry Pi Air Quality Monitor

(Image credit: Tom's Hardware)

7. Mount the SDS011 sensor and your Raspberry Pi to a small block of wood. This step is optional, you can also use a case, but I like the open air look of the system. If mounting the sensor inside a component, make sure the air inlet port is connected to the outside of the case. 

(Image credit: Tom's Hardware)

8. Run the server to start taking measurements. 

make run

9. Navigate to your Pi’s IP address on port 8000 to view the web server, and a small graph of recent measurements of air quality. You’ll see a graph. 

(Image credit: Tom's Hardware)

The sensor in this Raspberry Pi Project measures two metrics: PM2.5 and PM10. PM stands for particulate matter and the number after is the amount of micrometers, 2.5 or 10. Particles of PM2.5 are particularly bad for your health if they contain toxic substances.

This server shows running measurements for the last 30 minutes, but could be easily adapted to do more. I’ll be comparing my values from now until after my HVAC system is cleaned, and hopefully I’ll see a measurable difference. After that, I’ll be putting this in a water proof box to measure air quality outside, to give me an idea of how it varies over time.

  • Psyrick
    Hi!

    Thanks so much for this guide! I am a complete newbie and found this very easy to follow.

    I have followed the instructions as posted but can't make it run well.

    When opening the browser to view the page, this is what appears:

    This site can’t be reached192.168.10.165 refused to connect.

    then I get this from the Windows command prompt:

    web_1 | Traceback (most recent call last):
    web_1 | File "app.py", line 15, in <module>
    web_1 | aqm = AirQualityMonitor()
    web_1 | File "/code/AirQualityMonitor.py", line 13, in initweb_1 | self.sds = SDS011(port='/dev/ttyUSB0')
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 132, in initweb_1 | self.probe()
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 139, in probe
    web_1 | firmware_version_data = self.get_firmware_version()
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 226, in get_firmware_version
    web_1 | return self.request(cmd)
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 234, in request
    web_1 | resp = self.rx_cmd_resp_queue.get(timeout=10)
    web_1 | File "/usr/local/lib/python3.8/queue.py", line 178, in get
    web_1 | raise Empty
    web_1 | _queue.Empty

    I am using an old Raspberry Pi (2011.12) and have installed the latest Raspbian OS.

    I am hoping that you can help me out.
    Reply
  • NJAir
    I'm having the same issue - currently running Raspberry Pi 3 (B+) - not headless. Can't navigate to IP address as per the last instruction in the tutorial. Sorry, I'm a noob! Any help would be appreciated. Would love to see the air quality readings!

    Psyrick said:
    Hi!

    Thanks so much for this guide! I am a complete newbie and found this very easy to follow.

    I have followed the instructions as posted but can't make it run well.

    When opening the browser to view the page, this is what appears:

    This site can’t be reached192.168.10.165 refused to connect.

    then I get this from the Windows command prompt:

    web_1 | Traceback (most recent call last):
    web_1 | File "app.py", line 15, in <module>
    web_1 | aqm = AirQualityMonitor()
    web_1 | File "/code/AirQualityMonitor.py", line 13, in initweb_1 | self.sds = SDS011(port='/dev/ttyUSB0')
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 132, in initweb_1 | self.probe()
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 139, in probe
    web_1 | firmware_version_data = self.get_firmware_version()
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 226, in get_firmware_version
    web_1 | return self.request(cmd)
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 234, in request
    web_1 | resp = self.rx_cmd_resp_queue.get(timeout=10)
    web_1 | File "/usr/local/lib/python3.8/queue.py", line 178, in get
    web_1 | raise Empty
    web_1 | _queue.Empty

    I am using an old Raspberry Pi (2011.12) and have installed the latest Raspbian OS.

    I am hoping that you can help me out.
    Reply
  • NJAir
    Psyrick said:
    Hi!

    Thanks so much for this guide! I am a complete newbie and found this very easy to follow.

    I have followed the instructions as posted but can't make it run well.

    When opening the browser to view the page, this is what appears:

    This site can’t be reached192.168.10.165 refused to connect.

    then I get this from the Windows command prompt:

    web_1 | Traceback (most recent call last):
    web_1 | File "app.py", line 15, in <module>
    web_1 | aqm = AirQualityMonitor()
    web_1 | File "/code/AirQualityMonitor.py", line 13, in initweb_1 | self.sds = SDS011(port='/dev/ttyUSB0')
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 132, in initweb_1 | self.probe()
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 139, in probe
    web_1 | firmware_version_data = self.get_firmware_version()
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 226, in get_firmware_version
    web_1 | return self.request(cmd)
    web_1 | File "/usr/local/lib/python3.8/site-packages/sds011/sds011.py", line 234, in request
    web_1 | resp = self.rx_cmd_resp_queue.get(timeout=10)
    web_1 | File "/usr/local/lib/python3.8/queue.py", line 178, in get
    web_1 | raise Empty
    web_1 | _queue.Empty

    I am using an old Raspberry Pi (2011.12) and have installed the latest Raspbian OS.

    I am hoping that you can help me out.


    I figured it out - this is an issue that was discussed on Github: https://github.com/rydercalmdown/pi_air_quality_monitor/issues
    You have to change the code in a file called "index" to point to your pi's IP address (or removed the IP address entirely and use /api/ instead - that worked for me).

    Also, you have to close and restart the script ("make run") a couple of times before it runs correctly.

    Eventually this will all work, and you'll be able to navigate to your pi's IP address (port 8000) to see the data.
    Reply
  • Psyrick
    NJAir said:
    I figured it out - this is an issue that was discussed on Github: https://github.com/rydercalmdown/pi_air_quality_monitor/issues
    You have to change the code in a file called "index" to point to your pi's IP address (or removed the IP address entirely and use /api/ instead - that worked for me).

    Also, you have to close and restart the script ("make run") a couple of times before it runs correctly.

    Eventually this will all work, and you'll be able to navigate to your pi's IP address (port 8000) to see the data.

    Glad that worked out for you. I have done those indicated at the link but I am still having the same errors as before... Decided to just try running different code instead - apparently plenty available in other sites.

    I hope that the people who decided to post this tried to run the code first though 🤷‍♂️
    Reply