Introduction: How to Measure Particulate Air Pollution and Share the Data Online

Picture of How to Measure Particulate Air Pollution and Share the Data Online

Ever since I moved from Portland, Oregon to the Middle East, I've been curious about particulate air pollution. It's one of the worst varieties of air pollution in terms of impact on health and mortality. East Asia seems to get all the press about awful air quality, but there's plentyofdata to suggest that things aren't great here in the Middle East, either.

Unfortunately, there are no air quality monitoring stations in the city where I live (Doha, Qatar), so I decided to build a rudimentary one myself. It's based on design and code from an engineer at GE named Chris Nafis. You can find more information about my project here.

This guide will show you how to do the following:

  • Connect an air particle sensor to an Arduino Ethernet
  • Connect an Arduino Ethernet to the internet
  • Create an account on Xively
  • Share sensor data from an air particle sensor and Arduino Ethernet on Xively

That's enough for the introduction. Let's get started!

Step 1: Buying Parts and Materials

Picture of Buying Parts and Materials

All of the parts necessary to build this project are available online and can be shipped anywhere in the world. You may already have some of them on hand from other projects.

Here's the parts list:

You'll also need a computer with a USB port, a router with an ethernet port, and an internet connection, but I'm going to assume you already have these things.

The total cost (less computer, router, and internet connection) comes to about $119, depending on what you already have laying around. If you can't find what you're looking for by following the links I've provided above, you can also try Seeed Studio and Sparkfun.

Step 2: Preparing the Particle Sensor

Picture of Preparing the Particle Sensor

Once you've got your hands on the particle sensor, you can get started. We're going to use tape and foil to cover up the large hole in the middle of the particle sensor.

Use a bit of foil and tape to cover up the middle opening (the one highlighted by the red box in the first image). When you're done, your particle sensor should look like the second photo I've included.

The issue that we're trying to correct here is that the particle sensor detects individual particles in the air by shining a light into a sensor. When an airborne particle obstructs the path of that light, the sensor registers the presence of a particle. If there's a lot of ambient light flooding the testing chamber, then the sensing won't work properly. This isn't documented by the manufacturer online, but they explained it to me in an email and included the photo with the blue and red boxes.

Step 3: Connecting the Grove Shield to the Arduino Ethernet

Picture of Connecting the Grove Shield to the Arduino Ethernet

Plug the shield stacking headers into the black connectors on top of your Arduino Ethernet. The header with ten pins goes in the connector with ten receptacles, the two headers with eight pins go in the connectors with eight receptacles, and so on. One header has six pins in a two by three configuration — that one goes on the end of the Arduino Ethernet with the pins facing up. If you get confused, just look at the pictures. It's pretty straightforward.

Now that the pins are installed in the Arduino Ethernet, plug the Grove shield into the top of the Arduino Ethernet. You'll know which way it should go because there's only one way the six pin header with the pins sticking up can go into the Grove Shield. Note that there will be few receptacles on either side of the Arduino Ethernet that will go unused.

Step 4: Connect the Shinyei Particle Sensor

Picture of Connect the Shinyei Particle Sensor

Now we'll connect the particle sensor to the Grove shield. Just take the cable that's coming out of the particle sensor and plug it into port D8 on the Grove shield. If you get confused, check out the picture.

Next, mount the particle sensor vertically as shown in the picture. I used a cardboard box with a pushpin, but I've also had a lot of luck just taping them to the wall.

Step 5: Connect the Arduino Ethernet to the Computer

Picture of Connect the Arduino Ethernet to the Computer

Start by connecting the non-USB end of the FTDI cable to the six pins sticking out of the side of the Arduino Ethernet. The FTDI cable has a rainbow assortment of cables, and we want the black cable to be on the right and the green cable on the left (with the Grove shield oriented on top and the ethernet port on the Arduino Ethernet facing away from you). If this is confusing, just check out the pictures.

Connect the other end of the cable to a USB port on your computer.

Step 6: Install the Arduino IDE and Set Board and Serial Port

Picture of Install the Arduino IDE and Set Board and Serial Port

Unless you already have it, start by downloading the Arduino IDE*, the program that lets us load programs (known as sketches) onto the Arduino (here are direct download links for OS X and Windows). If you have trouble with this, check out Arduino's guide.

Once it's installed and running, we'll need to change two settings. The first thing we'll set is the type of board we're using (an Arduino Ethernet). On a Mac, go to Tools > Board > Arduino Ethernet, as in the picture. I'm not sure what the steps are on Windows but I'll bet they're similar.

The second thing we'll set is the port that the computer uses to communicate with the Arduino Ethernet. This is probably already set automatically, but just in case, go to Tools > Serial Port > /dev/tty.usbserial..., as in the picture.

* IDE stands for integrated development environment.

Step 7: Load Test Sketch to Make Sure Everything's Working

Picture of Load Test Sketch to Make Sure Everything's Working

Start by copying the particleSensorTest.ino sketch (again, a sketch is just a name for an Arduino program) by clicking the file attached to this page (I've tried posting the text of the code directly onto this page, but the Instructables editor messes it up).

Now open a new window on the Arduino IDE and paste in the particleSensorTest.ino sketch to test and make sure the Arduino Ethernet, Grove shield, and particle sensor are working properly (obviously you'll need the particle sensor plugged into the Arduino and the Arduino plugged into your computer for this to work).

Once it's pasted in, click the arrow pointing to the right in the upper left-hand corner of the Arduino IDE window. This will compile (translate) the code and upload it to the Arduino Ethernet.

Next, open the Serial Monitor to check output from the particle sensor. It should update every thirty seconds with three values separated by commas. The final value, which shows number of particles per 0.01 cubic feet, is the one we're looking for. In my experience, this usually ranges from 50 to 500 while I'm inside, but as I said at the beginning of the guide, the air where I live is pretty dirty. Your air quality will vary.

If the Arduino Ethernet and the particle sensor are posting values every thirty seconds we're in good shape. You may see zero values (0,0.00,0.62) from time to time, but there's not much we can do about that beyond what we did with the foil.

Next we'll set up an account on Xively, which will allow us to share our data online.

Step 8: Set Up an Account and a Device on Xively

Picture of Set Up an Account and a Device on Xively

We'll need to take a brief break from the Arduino IDE to set up an account and a device on Xively, a website that allows posting and sharing of sensor data.

Start by setting up a new accounthere. Once you're done with that, click the "Develop" button, and then "+ Add Device."

Type in a name and brief description for your device, set it to "Public" (so that anyone can see the data you collect), and then click "Add Device." The "device" we're adding is our Arduino Ethernet and dust sensor.

On the next page (the homepage for the device, so to speak), we'll gather two pieces of information: a random string of numbers and letters called the API key, and a ten digit number called the Feed ID. Look at the pictures to see where on the page to find them. Copy them down into a text document and head to the next step.

Step 9: Expand Arduino IDE's Capability by Adding Two Libraries

In order to post your data to the internet, you'll need to install two Arduino libraries (which give the software extra functionality) to your computer: the HTTP Client library and the Xively library.

To install the HTTP Client library, download the zip file by clicking here. Then, in the Arduino IDE, go to Sketch > Import Library... > Add Library... Navigate to wherever your downloaded the zip file to, and then select it and click "Choose." You should see a message at the bottom of the Arduino IDE saying "Library added to your libraries. Check 'Import library' menu."

Next, download the Xively library by clicking here. Once it's downloaded, unzip it and rename the folder from "xively_arduino-master" to "Xively" (the Arduino IDE won't accept library names with special characters). Then, in the Arduino IDE, go to Sketch > Import Library... > Add Library... Navigate to wherever you renamed the folder, and then select it and click "Choose." You should see a message at the bottom of the Arduino IDE saying "Library added to your libraries. Check 'Import library' menu."

In the next step, we'll upload the final sketch to our Arduino Ethernet which will allow us to post data to Xively.

Step 10: Load Final Sketch Which Will Allow Sharing Data Online

Picture of Load Final Sketch Which Will Allow Sharing Data Online

The first thing you'll need to do in this step is look on the bottom of your Arduino Ethernet for its MAC address, which should look something like this: 5B-8G-C3-EB-38-AM. Write down this MAC address — we'll use it in a little bit.

Next, open the particleSensorXively.ino file (it's attached to this page) and paste its contents into a new Arduino IDE window. We'll need to edit three fields in this sketch. You'll find them in the configuration section toward the top of the sketch:

  1. MAC address: If your MAC address is printed on the sticker on the Arduino Ethernet as 5B-8G-C3-EB-38-AM, then you'll write the MAC address in the format of 0x5B, 0x8G, 0xC3, 0xEB, 0x38, 0xAM. Look at the annotated screen capture if this doesn't make sense.
  2. Xively API key: We copied this down in step eight. It's a long, random string of letters and numbers. Paste it between the quotes, as in the picture.
  3. Xively Feed ID: We copied this down in step eight. It should be about ten digits long. It goes after "feed(" and before the first comma, as in the picture.

Once you've put the necessary information into the sketch, click the arrow pointing to the right (just like we clicked for the test sketch) to load the sketch onto your Arduino Ethernet.

Now all we need to do is plug in some wires and the particle sensor will be up and running!

Step 11: Connect the Particle Sensor to Your Router and Start Posting Data

Picture of Connect the Particle Sensor to Your Router and Start Posting Data

For most of the previous steps in this guide you've had the Arduino Ethernet connected to your computer via USB cable. The first thing you'll do in this step is disconnect the USB cable so that the Arduino Ethernet is only connected to the Grove shield, which in turn is only connected to the particle sensor.

Next, connect your Arduino Ethernet to the internet by connecting one end of an ethernet cable to your Arduino Ethernet and the other end to a port on your router.

Finally, provide power to your Arduino Ethernet by connecting a power adapter to the Arduino and plug it in to a power source. You should begin to see your Xively device page posting data in just a few minutes.

In the next (and final) step, we'll edit the units of the data being posted to Xively and make sure everything is working properly.

Step 12: Change the Units on Xively and Be Done!

Picture of Change the Units on Xively and Be Done!

Go to your device development page on Xively if you weren't there already (you can access it by picking your device from the list that's on this page, not that you must be logged in). Underneath the graph of your data you'll see an Edit link. Click that.

The only value you'll need to edit here is the units. In the empty box below units, type in particles per 0.01 cubic feet.

That's it! You're done!


sandrinex made it! (author)2014-06-19

I made it following the instruction from Alex and it works perfect for me.

alxmjo (author)sandrinex2015-03-23

Thanks for using the guide, Sandrinex. Glad it worked for you!

EsmeraldaH2 (author)2017-06-13


can i use an arduino uno + ethernet shield instead of an arduino ethernet ?

alxmjo (author)EsmeraldaH22017-06-14

Probably. You might just need to use a different HTTP library and you'll also need to make sure that the Ethernet shield doesn't use any of the pins that you're using for the dust sensor.

RoyL6 (author)2015-07-24

Hi Alxmjo ,
I am in the market of air quality sensor from China, as I know the trends of IAQ monitoring is become more and more accuracy and digital sensor is become avialable for ordinary residents . The most advanced civil dust sensor is ±15% of reading now , maybe you can get a article of this kinds of sensor .

midnightcow (author)2014-11-17

Hi, Alxmjo.

It's so cool intstructable. It's very good marketability. Today, Air-Pollution is wordlwide hot issue. If your instructable made by those who thinks like as you and shared the data online, it will make the air of world to clean and people will be happy and healthy. I will contine to cheer-up you in the future.

Thanks so much.

alxmjo (author)midnightcow2015-03-23

Glad you liked it!

sandrinex (author)2014-06-19

This is an excellent step by step instruction which makes it failure free kindly easy to set up an air control sensor for particles with xively online data reporting.

I ,ade it and it works for me without any issues!

Great job and thanks to Alex!

Moose Dr (author)2014-06-05

Very cool. I don't have much interest in the internet aspect, but I may just implement a particle monitor.

BTW, I also came across an interesting way of cheaply reducing particles in indoor air. I heard that a guy in China linked a regular fan with the kind of HEPA filters you get in vacuum cleaners. The results were every bit as good as $500 air cleaners, but cost under $50.

alxmjo (author)Moose Dr2014-06-07

Thanks for reading. I've seen that guy's stuff, and in fact spent a good part of today driving around Doha trying to find HEPA filters. No luck, so far. Perhaps I'll have to bring them from the United States.

And as for the non-internet aspect, you can do the whole thing easier and cheaper by using a regular Arduino plus the code on Chris Nafis's site:

Moose Dr (author)2014-06-05

Oh, and I bookmarked epic tinker, the supplier of your particle sensor.