[go: up one dir, main page]

0% found this document useful (0 votes)
7 views6 pages

MQTTBased Air Quality Monitoring System

This paper presents an MQTT-based air quality monitoring system utilizing ESP8266 NodeMCU and Node-RED to measure and report environmental data such as temperature, humidity, carbon monoxide, ozone, and PM2.5 levels. The system publishes sensor data to an MQTT broker and uses Node-RED to manage and visualize the data on a web dashboard, while also sending alerts via LINE Notify when pollutant levels exceed safe thresholds. The implementation aims to address air quality issues in Thailand, where poor air quality has significant health impacts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

MQTTBased Air Quality Monitoring System

This paper presents an MQTT-based air quality monitoring system utilizing ESP8266 NodeMCU and Node-RED to measure and report environmental data such as temperature, humidity, carbon monoxide, ozone, and PM2.5 levels. The system publishes sensor data to an MQTT broker and uses Node-RED to manage and visualize the data on a web dashboard, while also sending alerts via LINE Notify when pollutant levels exceed safe thresholds. The implementation aims to address air quality issues in Thailand, where poor air quality has significant health impacts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/328835535

MQTT Based Air Quality Monitoring System using Node MCU and Node-RED

Conference Paper · July 2018


DOI: 10.1109/ICT-ISPC.2018.8523891

CITATIONS READS

74 7,278

2 authors:

Somphop Chanthakit Choopan Rattanapoka


King Mongkut's University of Technology North Bangkok King Mongkut's University of Technology North Bangkok
4 PUBLICATIONS 114 CITATIONS 16 PUBLICATIONS 238 CITATIONS

SEE PROFILE SEE PROFILE

All content following this page was uploaded by Somphop Chanthakit on 25 June 2020.

The user has requested enhancement of the downloaded file.


MQTT Based Air Quality Monitoring System
using NodeMCU and Node-RED
Somphop Chanthakit Choopan Rattanapoka
College of Industrial Technology College of Industrial Technology
King Mongkut’s University of Technology North Bangkok King Mongkut’s University of Technology North Bangkok
Bangkok, Thailand Bangkok, Thailand
s5903053816027@email.kmutnb.ac.th choopanr@kmutnb.ac.th

Abstract—This paper present an implementation of MQTT they could communicate only when it is required. Devices
based air quality monitoring system. The air quality with constrained resources should be able to communicate
measurement device is a hardware using ESP8266 NodeMCU with various other devices. The Message Queue Telemetry
that connects to sensors for measuring temperature, humidity, Transport (MQTT) protocol [4] is one of the most popular
concentration of carbon monoxide (CO), ozone gas (O3), and protocol that play as an important role in IoT
PM2.5. The firmware of device makes the device act as a communication. Because MQTT is so lightweight and can be
publisher that reads the sensor data and sends them to MQTT used by some of the smallest measuring and monitoring
Broker. Node-RED is used to be a subscriber that subscribes to devices, and it is designed to overcome the challenges of
receive data from MQTT Broker. With Node-RED, we can
connecting the rapidly expanding physical world of sensors,
easily make a flow to manage and handle received data. Then,
Node-RED will send data to the air quality monitoring
actuators, mobile phones, and tablets with established
dashboard which is a responsive web application to display software processing technologies. These principles also turn
data in gauge, text and chart user interface. In addition, when out to make this protocol ideal for the emerging Machine-to-
the value of some data exceed the configured range, Node-RED Machine (M2M) or IoT world of connected devices where
will send an alarm message via LINE Notify to notify users. bandwidth and battery power are at a premium.
Thus, this paper presents an implementation of a low-cost
Keywords—Internet of things, MQTT, Air quality, Sensors,
air quality monitoring system by using a ESP8266 NodeMCU
Node-RED, ESP8266 NodeMCU
connects to a temperature and humidity sensor (DHT22), a
I. INTRODUCTION carbon monoxide sensor (MQ-7), an ozone gas sensor (MQ-
131), and PM2.5 dust sensor (PPD42NJ). The ESP8266
Indoor air pollution and poor urban air quality are listed collects the data from sensors and publishes them to a MQTT
as two of the world’s worst toxic pollution problems in the Broker and also we implement an air quality monitoring
2008 Blacksmith Institute World’s Worst Polluted Places dashboard using Node-RED [5] that subscribes to the MQTT
report [1]. From the 2014 World Health Organization report, Broker and retrieves sensor data to display them in the form
air pollution in 2012 caused the deaths of around 7 million of gauge, text and chart user interface. Moreover, when the
people worldwide [2]. Thailand’s Air Quality Index (AQI) is value of some data exceed the standard range, the system
an index for reporting daily air quality. The AQI focuses on will notify people via LINE Notify [6].
health effects that people may experience within a few hours
or days after breathing polluted air. The Pollution Control
Department (PCD) calculates the AQI from 5 major air
pollutants regulated by the National Ambient Air Quality II. BACKGROUND
Standards (NAAQS): ground-level ozone (O3), carbon A. MQTT Protocol
monoxide (CO), sulfur dioxide (SO2), nitrogen dioxide
(NO2) and airborne particulate matter 10 micrometers or less Message Queuing Telemetry Transport (MQTT) is an
in diameter (PM10). Ground-level ozone and airborne ISO standard (ISO/IEC PRF 20922) lightweight publish/
particles are the two pollutants that pose the greatest to subscribe messaging protocol. It is useful the devices with
human health in Thailand according to the PCD. In January limited resources.
2018, Bangkok air quality was extremely unhealthy with the The MQTT protocol is based on the principle of
level of particles sized at equal or smaller than 2.5 microns publishing messages and subscribing to topics, or “pub/sub”.
(PM2.5) reach over 200 µg/m3 while the Thai standards safe Multiple clients connect to a broker and subscribe to topics
level of PM2.5 is 50 µg/m3. However, The PCD had failed to that they are interested in. Clients also connect to the broker
warn the public because the lack of proper air-quality and publish messages to topics. Many clients may subscribe
warning system and the PM2.5 is not included in the AQI to the same topics and do with the information as they
calculation as the nationwide installation of PM2.5 please. The broker and MQTT act as a simple, common
monitoring devices was not yet complete. interface for everything to connect to. Messages in MQTT
Nowadays Internet of Things (IoT) [3] gained a great are published on topics. There is no need to configure a
attention from researchers, since it becomes an important topic, publishing on it is enough.
technology that allowing a communications between objects, Topics are treated as a hierarchy, using a slash (/) as a
machines and every things together with peoples. The IoT separator. Clients can receive messages by creating
represents a system, which consists things in the real world, subscriptions. A subscription may be to an explicit topic, in
and sensors attached to or combined to these things, which case only messages to that topic will be received, or it
connected to the Internet via wired and wireless network may include wildcards. Two wildcards are available, + or #.
structure. The connected devices need a protocol using which

978-1-5386-5538-2/18/$31.00 ©2018 IEEE


B. Node-RED
Node-RED is a flow-based development tool developed
originally by IBM for wiring together hardware devices,
APIs and online services as part of the Internet of Things.
Node-RED provides a browser-based flow editor, which can
be used to create JavaScript functions. The elements of
applications can be saved or shared for re-use. The runtime is
built on Node.js. The flows created in Node-RED are stored
using JSON. Since version 0.14 MQTT nodes can make
properly configured TLS connections. In 2016, IBM
contributed Node-RED as an open source JS Foundation
project.

C. LINE Notify
LINE Notify is a notification service that allows users to Fig. 2. The Components of Device Hardware.
link to a web service and receive notification from the
official account “LINE Notify” that is provided by LINE [7].
LINE Notify can be used free of charge. LINE Notify
supports the event notification from Mackerel: a server A. Air Quality Measurement Device (Publisher)
monitoring platform for engineers, GitHub: a shared web The implementation of air quality measurement device
service for software development projects, IFTTT: a web- can be divided into two parts: hardware and software.
based service which allows users to link together other web
services, and also some other services that can connect to 1) Hardware
LINE Notify API. The device hardware’s design shown in Fig. 2. The main
hardware component of the device is a ESP8266 NodeMCU
board that connects to sensors. In this device, there are four
III. SYSTEM DESIGN sensors.
 Temperature and humidity sensor (DHT22), a low-
The air quality monitoring system consists of three main
cost digital temperature and humidity sensor. It uses
components shown in Fig. 1.
a capacitive humidity sensor and a thermistor to
The first component is an air quality measurement measure the surrounding air, and output a digital
device. We connected sensors to ESP8266 NodeMCU that signal on the data pin.
acts as a publisher. The ESP8266 NodeMCU will collect,  Carbon monoxide sensor (MQ-7), a simple to use
parse and transform data from sensors, then publish them to CO sensor. It can detect CO-gas concentrations
MQTT Broker. from 20 to 2000 ppm. The output of sensor is an
The second component is MQTT Broker. We use Eclipse analog resistance.
Mosquitto [8], which is an open source message broker that  Low concentration ozone gas sensor (MQ-131), a
implements the MQTT protocol version 3.1 and 3.1.1. gas sensor that use SnO2 as sensitive material. It can
Mosquitto is lightweight and is suitable for use on all devices detect ozone-gas concentrations from 10 ppb to 2
from low power single board computers to full server. ppm. The output of sensor is an analog resistance.
The third component is an air quality monitoring  Grove – particle sensor (PPD42NJ), a sensor that
dashboard and Line Notify Service. We use Node-RED that create digital output to particulate matters (PM)
acts as a subscriber to receive data from MQTT broker. With whose size is around 1 micro meter or larger.
Node-RED, we design flows to manage and handle the
received data to display them in the form of gauge, text and DHT22 and PPD42NJ sensors give digital output, so we
chart on the dashboard. In addition, we set some constraints can connect them directly to ESP8266 NodeMCU digital
in Node-RED that if the value of data exceed the configure GPIO pin. However, ESP8266 NodeMCU has only one
range, Node-RED will contact LINE Notify service to send a analog pin, thus we use ADS1115 that is a 16-bit analog to
LINE message to warn users. digital converter to take the analog outputs from MQ-7 and
MQ-131 sensors and convert them to digital outputs. Then,
we connect ADS1115’s SCL and SDA pins to ESP8266
NodeMCU’s digtal GPIO pins so that ESP8266 NodeMCU
can read data from these two sensors.

2) Software
The software or firmware that we implemented on the
device will collect the data from four sensors and transform
them to the standard unit of measurement. Then, we use a
MQTT client library [9] to publish data to MQTT Broker.
Fig. 1. Air Quality Monitoring System Architecture. For the temperature and humidity, the data from DHT22
sensors already give the value of temperature in degree
Celsius (°C) and the value of humidity in relative humidity
(%RH). Thus, we write a program to collect these two data
from sensors every 2 seconds. Then, the program will
combine two data into one string in the format of
temperature,humidity and publish this data to MQTT Broker
in the topic named “sensor/TEMPAndHUMID”.
For the data of CO-gas concentration from MQ-7 sensor
and the Ozone gas concentration from MQ-131 sensor, the
output that program can collect from these sensors are
voltage. Thus, we need to calculate the resistance of sensor Fig. 3. The Flow Management for PM2.5 Data.
(RS) using the equation in (1).

RS = ((VC / VRL) – 1) x RL (1) A flow design to handle the PM2.5 data shown in Fig. 3.
First, a subscribe node (number 1) subscribes the topic
sensor/PM2.5. This node will obtain the PM2.5 data from
Where
MQTT Broker whenever the device publishes the PM2.5
 VC is the circuit voltage (5V).
concentration data. Then, the PM2.5 data will pass to gauge
 VRL is the output voltage from sensor. node, chart node and text node in number 2, 3, and 4
 RL is the load resistance (we use 10k). respectively. These three nodes will be displayed as user
interface on the air quality monitoring dashboard that is a
After we obtain the value of RS , we can find the CO-gas responsive web application. In addition, the subscribe node
and Ozone gas concentration in ppm (parts per million) by passes the PM2.5 data to the PM2.5 Notify function node
using the sensitivity characteristic curve in datasheet of each (number 5).
sensor. The program will collect these two data from sensors The algorithm in PM2.5 Notify function node indicated
every 1 second, Then, the program combines two data into in the flowchart shown in Fig. 4. At the first time, a static
one string in the format of co-gas-value,ozone-gas-value variable State is set to Normal.
and publish this data to MQTT Broker in the topic named If the PM2.5 data is more than 50 µg/m3 and State is
“sensor/COAndO3”. Normal, then State is set to Alarm and a variable Msg is set
For the data of PM2.5 from PPD42NJ sensor, the to a warning message “Unhealthy, PM2.5 is more than 50
program needs to sample the total duration of “logic low” in µg/m3”. Then, this function node sends the warning message
30 seconds (Ratio: R) because this duration illustrates the to the http request node (number 6).
dust density of environment. Then, we can calculate the If the PM2.5 data is less than 35 µg/m3 and State is
PM2.5 concentration (C) in particles per 1/100 of a cubic Alarm, then State is set to Normal and a variable Msg is set
foot (pcs/0.01cf) unit by using the equation in (2). to a notify message “Good, PM2.5 is less than 35 µg/m3”.
Then, this function node sends the notify message to the http
C = (1.1 x R3) + (3.8 x R2) + (520 x R) + 0.62 (2) request node (number 6).
Otherwise, no message passes to the http request node in
Because the air quality standard unit for PM2.5 is in order to prevent the users to receive multiple warning or
µg/m3, our program will transform the value C in pcs/0.01cf notify messages.
unit to CS in µg/m3 unit using the equation in (3).

CS = C x 3531.5 x (1.65 x 1012) x ((4/3)(0.44 x 10-6)3 (3)

Noted that:
 All particles are spherical, with a density of
1.65E12 µg/m3.
 The radius of a particle in the PM2.5 channel is
0.44 µm.
 0.01 ft3 can be converted to m3 by multiplying
by 3531.5.

After we obtain the value of the PM2.5 concentration in


µg/m3 unit, the program will publish this value to MQTT
Broker in the topic named “sensor/PM2.5” every 1 minute.

B. Node-RED (Subscriber)
Node-RED is a MQTT client that subscribes to MQTT
Broker on the topic that the device publishes. We design the
flow to manage and handle data from device’s four sensors
via 3 topics (sensor/TEMPAndHUMID, sensor/COAndO3,
and sensor/PM2.5) in Node-RED.

Fig. 4. The Algorithm of the PM2.5 Notify Function Node.


Fig. 5. The Overall Flow Management Design in Node-RED.

The http request node (number 6) is a node that connects IV. RESULTS
to LINE Notify service via Web API. It will send a received
A. Air Quality Measurement Device
message to LINE Notify service to notify user on LINE
messenger application. The real device is implemented as we designed shown in
Fig. 5 shows the overall flow designed in Node-RED to Fig. 6. The size of device is quite small as we compare to a
handle data from three topics. All of these three flows are Thai Baht coin. In addition, the total cost of the device is
mostly the same. The flow of sensor/TEMPAndHUMID and quite cheap. It is only around 2,000 Baht (62 USD).
sensor/COAndO3 have one more addition node, a split node.
B. Air Quality Monitoring Dashboard
Because, the data of the topic sensor/TEMPAndHUMID
contains temperature and humidity value, separated by The dashboard is a responsive web application provided
comma. Also, the data of topic sensor/COAndO3 contains by Node-RED. It displays three kinds of user interface from
CO-gas and Ozone-gas concentration, separated by comma. each sensor data (gauge, text, and chart). Moreover, because
Thus, the split node is set to separate two data and feed them the dashboard is a responsive web application, so it can
to the appropriated flow. display perfectly on both mobile phone as shown in Fig. 7.
and web browser as shown in Fig. 8.

Fig. 6. The Complete Air Quality Measurement Device. Fig. 7. The Air Quality Monitoring Dashboard on Mobile Phone.
Fig. 11. The Notification Message on LINE Messenger Application.

V. CONCLUSION
We presents a low-cost real-time air quality monitoring
system. The air quality measurement device is built on
ESP8266 NodeMCU board connects to 4 sensors: DHT22,
MQ-7, MQ-131 and PPD42NJ to detect the temperature,
Fig. 8. The Air Quality Monitoring Dashboard on Web Browser.
humidity, carbon monoxide (CO) concentration, ozone-gas
(O3) concentration, and PM2.5 concentration. The air quality
monitoring dashboard is implemented on Node-RED to
C. Line Notify receive and display air quality data. With Node-RED, we can
We simulate the notification by heating the device. In design the flow to manage and handle air quality data, thus
our setup the temperature that exceeds 40 degree Celsius, we can set the condition to notify users about the unhealthy
we mark it as an unhealthy condition. For the temperature environment through LINE Notify service. The device and
that is lower than 35 degree Celsius, we mark it as a good Node-RED communicate via MQTT Broker in the publish
condition. and subscribe model.
The Fig. 9. is a chart on the dashboard that is showing However, the Air Quality Index (AQI) does not take and
when we heat the device. It detects that the temperature is calculate the value from real-time data. It need to use the
over 40 degree Celsius at 15:10. And the Fig. 10. shows that average value of each kind of gas concentration. Hence, the
the temperature went down to below 35 degree Celsius at future works will be store the data into the database and
15:12. calculate the unhealthy condition to notify users from it to
Thus, users who register to our LINE Notify service will make a proper air quality monitoring system.
receive the warning message at 15:10 and the notification
message at 15:12 as shown in Fig. 11.
REFERENCES
[1] Worstpolluted.org, “The World’s Worst Pollution Problems: The Top
Ten of The Toxic Twenty”, 2008. [Online]. Available: http://www.
worstpolluted.org/reports/file/World's%20Worst%20Pollution%20Pro
blems%202008.pdf. [Accessed: 19 May 2018].
[2] World Health Organization, “7 million premature deaths annually
linked to air pollution”, 2014. [Online]. Available: http://www.who.
int/mediacentre/news/releases/2014/air-pollution/en/. [Accessed: 19 May
2018].
[3] K. Ashton, “That “Internet of Things” Thing: In the Real World
Things Matter More than Ideas”, 2019. RFID Journal. [Online].
Available: http://www.rfidjournal.com/articles/view?4986. [Accessed:
19 May 2018].
[4] A. Banks, R. Gupta, “MQTT version 3.1.1 Plus Errata 01, OASIS
Fig. 9. The Chart when the temperature is over 40 °C at 15:10.
Standard Incorporating Approved Errata 01”, 2015, [Online].
Available: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1
-os.html. [Accessed: 19 May 2018].
[5] Node-RED, [Online]. Available: http://www.nodered.org. [Accessed:
19 May 2018].
[6] LINE Notify, [Online]. Available: https://notify-bot.line.me/en/.
[Accessed: 19 May 2018].
[7] LINE, [Online]. Available: https://line.me/en/. [Accessed: 19 May 2018].
[8] Eclipse Mosquitto, [Online]. Available: https://mosquitto.org/.
[Accessed: 19 May 2018].
[9] Arduino Client for MQTT, [Online]. Available: https://pubsubclient
.knolleary.net/. [Accessed: 19 May 2018]

Fig. 10. The Chart when the Temperature is below 35 °C at 15:12.

View publication stats

You might also like