Introduction: Particle Powered Air Quality Monitor

About: I was known as the one who breaks things. As you could imagine, it may have been very inconvenient to live with. But, as I matured I’ve found not only ways to break stuff (still!) but also fix, improve and bui…

Air quality.

You probably think about it more now that our clean air has turned into a permanent haze across the sky.

Yuck.

One thing you do have control over is the air quality inside your home. In this tutorial, I'll show you how to build an air quality sensor in a few short steps.

Step 1: Gather the Goods

Get everything together that you'll need for this project.

This includes:

  • A Particle Mesh board (Argon, Boron, Xenon). You can get them almost anywhere. Buying direct always works too.
  • Particle^2 Air Quality Sensor.
  • Honeywell HPMA115S0 Particle Sensor.
  • Cable for HPMA115S0 Sensor. (The last three you can get here.)

Step 2: Assemble Them

  1. Attach the Particle to the Particle^2 board
  2. Connect the HPM Particle sensor to the Particle^2 using the cable
  3. Plug in USB!

Step 3: Configure Google Docs - Create the Script

  1. Create a new Google Sheet
  2. Then click the Tools menu and click Script Editor
  3. Create a new script
  4. Insert the below code into the script:

//this is a function that fires when the webapp receives a POST request
function doPost(e) {

//Return if null if( e == undefined ) { Logger.log(“no data”); return HtmlService.createHtmlOutput(“need data”); }

//Parse the JSON data var event = JSON.parse(e.postData.contents); var data = JSON.parse(event.data);

//Get the last row without data var sheet = SpreadsheetApp.getActiveSheet(); var lastRow = Math.max(sheet.getLastRow(),1); sheet.insertRowAfter(lastRow);

//Get current timestamp var timestamp = new Date();

//Insert the data into the sheet sheet.getRange(lastRow + 1, 1).setValue(event.published_at); sheet.getRange(lastRow + 1, 2).setValue(data.temperature); sheet.getRange(lastRow + 1, 3).setValue(data.humidity); sheet.getRange(lastRow + 1, 4).setValue(data.pm10); sheet.getRange(lastRow + 1, 5).setValue(data.pm25); sheet.getRange(lastRow + 1, 6).setValue(data.tvoc); sheet.getRange(lastRow + 1, 7).setValue(data.c02);

SpreadsheetApp.flush(); return HtmlService.createHtmlOutput(“post request received”); }

Step 4: Configure Google Docs - Configure the Webhook

Then,

  1. Go to Publish and click Deploy as Web App
  2. Set Execute the app as yourself
  3. Then set Who has access to the app to Anyone, even anonymous. (Important: if you're working with. mission critical data, you may want a more robust and custom solution. This allows anyone, if they have your web hook link to post data to that page!)
  4. Change the Project Version to new and deploy!
  5. Copy the Current App URL that the output provides.

Step 5: Configure Particle Cloud

  1. In the Particle.io console, go to the Integrations section and Create a New Webhook
  2. Fill in the name of the event that get's forwarded from the code (in this case it's blob)
  3. Enter the Current App URL from the last step in the URL Box
  4. Set the request type to POST
  5. Set the request format to JSON
  6. Target the device you'll be using (or leave it as is if you only have one device)
  7. Click save

Step 6: Program the Board

  1. Setup your Particle Account and Particle Mesh device. Use the Quickstart if you haven't done this before.
  2. Download Particle Workbench and install if you haven't already. Instructions here.
  3. Get the code here.
  4. Once the code is downloaded, open it with Visual Code (that you installed in Step 1)
  5. Login to Particle if you haven't already (The fastest way is to hit Command + Shift + P to open the command window. Then start typing login)
  6. Publish to Particle Cloud - Again this uses the command window. Use the same Command + Shift + P as above and type Cloud Flash.
  7. Once you've found the Cloud Flash option, press enter.
  8. Your board should be programmed shortly. You can watch the LEDs for changes during this time. Once it's glowing blue, you're good to go!

Step 7: Graph Everything

  1. In the Google sheet you can create a header in the first row with all the labels. (See the screenshot above)
  2. You should notice by now that new data is showing up in the sheet (if you set everything up correctly). Go back to the previous steps if you don't see it.
  3. You can graph the data by selecting a full column and creating a new chart from it.
  4. You can graph everything in one or in separate like I've done above.

If everything is working and you have some pretty graphs, congrats!! If you're ready to move on to the next step using an IoT service like Adafruit's check out my full guide here.

Arduino Contest 2019

Participated in the
Arduino Contest 2019