Have you ever wondered if the air around you is healthy especially if you like to run outside like I do?
Today I'm going to show you how you can analyze the air around you using an open IoT platform called ThingSpeak
We're going to learn how to create the monitoring system you currently see on the screen
The data we're going to examine is being collected by Purple Air sensors located at the top of MathWorks headquarters
We're going to learn how to acquire your data, analyze it and then create different visualizations all within ThingSpeak
Let's quickly see how to create a free ThingSpeak account if you don't already have one
You can create a free account or use your existing MathWorks account
Let's go back to the ThingSpeak website and learn how to create our own channel
Make sure you're logged into ThingSpeak when you click on the "Channels" button
You will see all the channels you have created on this page
Let's click on the new channel button so that we can enter the appropriate channel information such as the channel and field names
We're going to assign "Field 1" to be AQI which stands for Air Quality Index, which we will calculate in the next few steps
Once all the necessary information has been entered, scroll down and press "Save Channels"
Click on the highlighted tab for read and write API keys, which will be useful later
Since we are not gathering any data right now, you can remove this empty default plot
Let's create our first visualization
For this plot, we are going to use a template provided to us for a 2D line plot
Click create, a window with automated code will pop-up
Change the highlighted lines with channel information
Let's call the functions I built which will analyze and plot the particulate data
We're going to be using an input function that will write the Air Quality Index back to my personal channel
Now that I have written my functions, let's quickly review and see what they really do
We are first going to be using a moving median filter to smooth out the collected data in case it may have some noise
This function is used the same way as you would in desktop MATLAB
Let's take a look at our plot function which has several input parameters
You can use familiar MATLAB syntax
and in this case, we have plotted the raw data as well as to smoothed out data
I'm going to use several commands to format my plot and make it look pretty
We're now going to call our other function that will calculate a running average of the last 24 hours worth of collected data
This will be used to calculate the Air Quality Index which will indicate if the air is healthy or not for the 2.5 micron particles that are emitted by cars using the US government EPA standards
Let's scroll down to "Save and Run" this code
You can see the results of your code in the code output window at the bottom
As you can see the x and y axes are labeled correctly with the local time
Now, let's go back and see how this would look on our channel that we just created
Select the AQI test channel that we recently created
The ThingSpeak channel will take a few moments to refresh and when it's done, we will see the same plot we saw a few moments back
Now we're going to use a ThingSpeak widget to create a gauge for our Air Quality Index
As you can see, the budget is customizable as there are several options present
Let's see what a fully completed gauge looks like
We have changed the name added colors with Rangers and our reading Field 1 that has the Air Quality Index data being written to it
Now let's create a default line plot for Field 1
These series of steps will create a line plot for the data in Field 1
In our case, it will tell us what has the Air Quality Index been for the last several days
This is also customizable
In this case, we're just going to change the name and call is Historical AQI and press "Save"
Let's create the last visualization
This time, we're going to write our own code from scratch
In this code, we're going to read the Air Quality Index from the Air Quality Index Test Channel that we created previously and create a patch object
This patch object will change color and the text based on the Air Quality Index reading
Let's "Save and Run" to see what happens
Since the Air Quality Index is low, the air is healthy and is good
Let's go back to our channel and refresh it
As you can see, we have all the four components we saw at the beginning of the video
We can rename this last visualization to be Air Health
The changes are now live on our channel
You can use the techniques learnt in this how-to video for your own data or other publicly available channels
For more information, other useful resources and the code used in this example, visit the links in the description below