Air Quality Analysis using ThingSpeak

Kalpataru Dash
IEEE-RAS VIT
Published in
4 min readNov 26, 2020

I have always wondered how does the health app on our phone tracks our activity like walking, running, sleeping, calories intake, etc., and then come up with either a diet plan or displaying a status of our overall health as fit, obese, or unhealthy, etc. Recently I found out that all of it is done using specific data analysis tools like MATLAB and due to my project I figured out how.

So coming to the main point of interest that is the Air quality monitoring and analysis using ThingSpeak. This project deals with collecting the data from the sensors in the hardware portion and then sending it to ThingSpeak.

The Hardware Model:

The model consists of a gas sensor a Node MCU(ESP8266), MQ135, and DHT11 sensors. The node MCU is a microcontroller that is used for establishing a connection between the sensors and computer. The MQ135 retrieves the air quality values and the DHT11 collects the data for temperature and humidity.

Hardware Model

Arduino IDE:

This is where the crucial part begins. We have to code the node MCU so that the data flows into ThingSpeak for further research. First I went ahead defining the sensor pins, and the Node MCU was set up to connect to the WiFi.

Initial Setup and Definition

In addition to initializing the sensors and the node MCU, there is a line that shows the API Key, this key is specific to unique to every user and it is obtained from the ThingSpeak login. Here the Write API key is used. Here is where you find it:

API KEY

After all this, we send the data to ThingSpeak, which makes a real-time graph out of each attribute like the PPM, Temperature, etc. These fields are defined via the following lines of codes:

Defining Fields for Specific Graphs

To send the value to ThingSpeak the node MCU takes 15 seconds so we give a delay command to synchronize with the time delay.

The Delay Command Line

ThingSpeak:

Then we go to ThingSpeak using the Url: thinkspeak.com. ThinkSpeak is a Mathworks venture to collect data in the cloud and then analyze it using MATLAB. Here we start with our data process and manipulation.

Due to our Arduino code, the data pushed from the sensor gives us real-time graphs in different fields in our ThingSpeak channel.

Real-Time Graph for PPM
Real-Time Graph for Humidity
Real-Time Graph for Temperature

MATLAB Analysis:

Now we move ahead to the main part where I had a hard time but while coming to the end I realized it wasn’t so tough after all. It just takes time when done for the first time. This feather in the cap was the MATLAB analysis code. This code takes the data and puts it in a visual standpoint for users to get a clearer image.

The MATLAB Code

I have explained the in very step as comments. The code in its entirety is taking the sensor values and predicting whether the air around us is safe to breathe or not.

ThingSpeak Visualization:

The Visual Prediction

This is how the result looked like. With a metric UI that displays the values of PPM and the quality is displayed along with the graph.

All the essential information and the code files are also present in my GitHub repository, do take a look:

https://github.com/kalpatarudash/Air_Quality_monitoring/

--

--