Purpose
The Simple Air Sensor is a device that detects particulate matter and displays a green, yellow, or red light to indicate low, medium, and high PM2.5 levels, respectively. An air sensor is connected to a small programmable circuit board (an Arduino), which tells the light when to change color based on the sensor reading. The colored light is a quick way to visualize relative air quality.
You can also get quantitative data on particulate matter concentration from the device with some extra steps. There are a couple ways documented at the links below:
- Record data from a Simple Air Sensor using a program called WebJack, by @warren
- Log Simple Air Sensor data to SD card, by @imvec
The purpose of this activity is to describe another way to read data from the Simple Air Sensor. We'll use serial communication hardware that's built into the device to send air sensor data to a computer, and the serial plotter tool in free Arduino software to visualize the data.
Materials needed
- An assembled Simple Air Sensor with the USB cable for connecting the device to a computer
- A computer for running the Arduino software and visualizing data
- Free Arduino software, called the Integrated Development Environment (IDE), installed on your computer (I found the downloaded desktop software to work better than the cloud-based "web editor" that Arduino also offers)
- A software program (called a "sketch" in Arduino coding lingo) named "plantower-rgb-plotter.ino". Originally written by @warren, modified by @bhamster. Download the program here.
Steps
Step 1. Connecting the Simple Air Sensor to a computer
Open the Arduino IDE software on your computer. Connect the Arduino board on your Simple Air Sensor to your computer with a mini USB cable.
Step 2. Choosing settings
Make sure the software is talking to the Arduino board properly by going to "Tools" in the software menu and selecting the correct Board, Processor, and Port:
- Board = "Arduino Nano" is the board model in Simple Air Sensors from the Public Lab store
- Processor = Note that "ATmega328P (Old Bootloader)" is selected. See * below for a side story with details on why!
- Port = make sure it says "usbserial" in there
*📖 Fun side story on the processor, or skip down to step 3.
The chip on this particular Arduino board that enables data to go from serial-to-USB is a cheaper CH430 chip. Previously, this caused some problems when Macs tried to read serial data from the board. Fixing the problem involved searching for and downloading drivers.
I did encounter a problem when I first tried to upload a program to the board. I got the error: "avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x0d"
I did not know what this meant 🤷🏻♀️, so I copy/pasted the error into a search engine and got this:
In addition to a funny post where one person complains that "some mean dude named avr came along and stopped me," I found an answer. It seems that the MacOS has since fixed its issue with the chip, and we just need to select the "old bootloader." No more messing with extra drivers.
Step 3. Uploading a program to the Arduino board
If you got the Simple Air Sensor from the Public Lab store, the Arduino board that came with it was already programmed with code called "plantower_rgb_webjack" (by @warren. You can find the download link here). This program includes code that enables the Arduino to output particulate matter data from the sensor via serial. In other words, we can "read" the sensor data from the Arduino board.
The original program produces more data than I wanted to visualize in a simple graph, though. So I modified the original code a bit to make it display three particulate matter readings: PM1.0, PM2.5, and PM10 in standard concentrations units. (More on what standard concentration units mean here.)
Download the modified program called "plantower-rgb-plotter.ino" here, and then open the file. We're going to write over the original program already on the Arduino board. This should not affect how the Simple Air Sensor lights display, just what shows up when we read serial data from the device. Note that the modified program also removed code for reading sensor data via WebJack.
On the panel that opens, you'll see a circle icon with an arrow pointing right--this is the upload button. Press that button and the modified program will be written to your attached Arduino board.
Step 4. Using the "serial plotter" to see sensor data
One way of reading and visualizing the sensor data uses the Serial Plotter. In the Arduino menu, go to "Tools" again and select Serial Plotter. A new window will appear.
Within the Serial Plotter window, you'll see a dropdown with a number next to the word "baud." Change the baud rate to 115200. See ** below for another side note about why.
Now we'll see this on the plotter!
The air around my sensor was still clearing from an earlier test with a lit match, so the readings aren't starting right at zero.
Here's the plot I got when I tested the air sensor and plotter visual with cornstarch and then a lit match. PM1.0 is represented by the blue line, PM2.5 by the red line, and PM10 by the green line.
**Note about the baud rate:
I'll admit I had no idea what this meant. Someone who was helping me suggested we look in the program code for clues.
The program behind the Simple Air Sensor contains these lines showing that the baud rate for outputting data to the computer over serial is 115200.
Step 5 (optional). Using the "serial monitor" to see sensor data
You can also view the PM concentration numbers in a table form using the Serial Monitor. Go to "Tools" again and select Serial Monitor. A new window will appear and look something like this. You might need to adjust the baud rate again.
Wrap up
If you're seeing graph lines on the serial plotter that respond to sensor tests with matches or dusty substances, hooray! 🎉
I'm pretty new to the Arduino platform and one thing I learned while doing this activity is that when encountering errors, searching online for what the errors mean is super helpful.
If you have any other ideas or tips to add to this activity, please comment below!
2 Comments
Instructions worked fine. Thanks to @warren and @bhamster. See results, in these screenshots:
Is this a question? Click here to post it to the Questions page.
Looks great, Pat! Thanks for posting!!
Reply to this comment...
Log in to comment
Login to comment.