Development of Iot Weather Monitoring System Based On Arduino and Esp8266 Wi-Fi Module
Development of Iot Weather Monitoring System Based On Arduino and Esp8266 Wi-Fi Module
Andriy Holovatyy
Department of Computer-Aided Design Systems, Lviv Polytechnic National University,
5 Mytropolyta Andreya St., building 4, 79013 Lviv, Ukraine
Email: [email protected]
Abstract. In the paper, the hardware and software of the IoT weather monitoring system have
been developed. The hardware of the IoT weather monitoring system consists of the
microcontroller device which is developed on the Arduino Mega2560 board, digital pressure,
temperature and humidity sensor BME280, Wi-Fi module ESP-01 built on the ESP8266 chip
and the 16×2 alphanumeric LCD based on the Hitachi HD44780 controller. The electronic
circuit and the model of the microcontroller weather monitoring device have been created in
Proteus VSM. The operation algorithm of the IoT weather monitoring system has been
developed. The IoT device monitors such weather parameters as: atmospheric pressure,
temperature and relative humidity. The software modules for communication with the BME280
sensor and Wi-Fi module ESP-01 and main data collection and acquisition software for the
ATmega2560 microcontroller of the Arduino Mega2560 board have been created. The
software for communication with the ThingsBoard IoT platform and Mosquitto MQTT broker
has been created. The dashboards for weather data visualization on the IoT platform
ThingsBoard using ThingsBoard Dashboard and from the Mosquitto MQTT broker using
Node-RED have been created. The operation of the microcontroller weather monitoring device
has been simulated in Proteus ISIS. The prototype of the microcontroller weather monitoring
device has been built on a solderless breadboard and the operation of the IoT weather
monitoring system has been tested.
1. Introduction
The development of electronics, programming technologies and Internet has led to the emergence of
the Internet of Things. The Internet of Things (IoT) is a set of technologies for collecting information
from a system of distributed sensors and remotely controlling devices connected to the Internet, as
well as for storing, processing and visualizing data on local or remote servers. Devices that are part of
the Internet of Things are any stand-alone devices that are connected to the Internet and can be tracked
and/or controlled remotely [1-2].
One IoT device connects to another to transmit information over Internet protocols. IoT platforms
serve as a bridge between device sensors and the data network [3]. Today, there is a wide variety of
IoT platforms, such as: Amazon Web Services, Microsoft Azure, ThingWorx IoT Platform, IBM's
Watson, Cisco IoT Cloud Connect, Salesforce IoT Cloud, Oracle Integrated Cloud, GE Predix, Node-
RED, ThingsBoard, Adafruit IO , Kaa IoT Platform, thinger.io.
Content from this work may be used under the terms of the Creative Commons Attribution 3.0 licence. Any further distribution
of this work must maintain attribution to the author(s) and the title of the work, journal citation and DOI.
Published under licence by IOP Publishing Ltd 1
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
Today, one of the commonly-used data communication protocol for IoT is MQTT. MQTT is a
lightweight publish/subscribe messaging protocol designed for M2M (machine-to-machine) telemetry
in low-bandwidth environments. MQTT stands for Message Queuing Telemetry Transport, but was
previously called Telemetry Transport with a message queue [4].
MQTT (Message Queue Telemetry Transport) protocol is a lightweight messaging protocol for
sending simple data flows from sensors to applications, middleware or analytics platforms and cloud
solutions. Today, MQTT is the main protocol used for the Internet of Things (IoT). The MQTT
publish-subscribe model is shown in Fig. 1.
The purpose of this work is to create hardware and software IoT system for monitoring weather
parameters. For the development of the hardware of the IoT weather monitoring system the Arduino
Mega2560 board based on the ATmega2560 microcontroller [5], BME280 digital atmospheric
pressure, humidity and temperature sensor [6], ESP-01 Wi-Fi module built on the ESP8266 chip [7]
and alphanumeric 16×2 LCD module based on the HD44780 controller are used.
The microcontroller device has to measure weather parameters and transmit them over Wi-Fi
network using the MQTT protocol to the Mosquitto server (broker) [8] or to the ThingsBoard IoT
platform [9]. The ThingsBoard IoT platform collects, processes the received IoT data and displays
them on the created weather data visualization dashboard using ThingsBoard Dashboard. The
Mosquitto server (broker) sends the weather data to the MQTT client subscribed to the topic. The
MQTT client displays them on the monitoring and visualization dashboard created by using Node-
RED [10].
Many modern electronic devices are built on microcontrollers [11-16]. The important feature for
the designer is that they make possible to implement easier and cheaper the operation algorithm of the
device and reduce its dimensions. Using the microcontrollers the data can be easy received from
different sensors and different actuators (motors, heaters, lighting devices, servos, etc.) can be
controlled, mathematical calculations can be performed.
2
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
4 buttons
In Fig. 3 the developed hardware of the IoT weather monitoring system in the Proteus CAD
software is shown. In the circuit, the BME280 digital atmospheric pressure, temperature and humidity
sensor is connected to the I2C bus to the pins 20 (SDA/INT1) and 21 (SCL/INT0)) on the Arduino
Mega2560 board. The pins ESP_RX and EXP_TX of the ESP8266 Wi-Fi module are connected via
the UART interface to the pins 16 (TX2) and 17 (RX2) on the Arduino Mega2560 board. The 16
character×2 line LCD module based on HD44780 controller is connected to the pins 2…7
(PE0/PCINT8/RXD0, PE1/TXD0, PE4/INT4/OC3B, PE5/INT5/OC3C, PG5/OC0B, PE3/AINT
PH3/OC4A, PH4/OC4B) on the Arduino Mega2560. The register select pin (RS) of the LCD module
is connected to the Arduino Mega2560 digital pin 2. The enable/control pin (E) is connected to the
digital pin 3 on the Arduino Mega2560 board. The data pins D4…D7 of the LCD module are
connected to the digital pins 4…7 on the Arduino Mega2560 board, respectively. The 10 kOhm RV1
potentiometer is connected to the VEE LCD module pin. This potentiometer is used to supply 0…5V
voltage to adjust the display contrast.
The MENU_BTN button is connected to the pin 19 (PD2/INT2/RXD1), the SELECT_PLUS_BTN
(select/increase) button to the pin 23 (PA1/AD1), the SELECT_MINUS_BTN button (select/decrease)
to the pin 22 (PA0/AD0) and the button to exit from the menu into the operation mode EXIT_BTN to
the pin 24 (PA2 / AD2) on the Arduino Mega2560 board.
Figure 3. Hardware of the IoT weather monitoring system developed in Proteus VSM
3
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
Begin 1
ESP8266
ESP8266 WiFi
WiFi module
module connection
connection to
to Weather data sending every 3 seconds to
WiFi
WiFi access
access point
point the Mosquitto MQTT broker or IoT platform
status
status == WiFi.status();
WiFi.status();
1 End
Begin 1
End
true
!status
Figure 5. Initialization algorithm of the LCD module, BME280 sensor, ESP8266 Wi-Fi module and
MQTT client
4
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
After supplying the power to the IoT weather monitoring device, the program written in the
microcontroller flash memory starts. First of all, the setup() function initializes the LCD interface and
determines the display size of 16 columns and 2 rows, then initializes the serial interface and sets up
its speed in bits per second (bauds) (Fig. 5).
The next step is the initialization of the BME280 atmospheric pressure, temperature and humidity
sensor connected via the I2C interface with the address 0×44. The initialization of the pins as inputs to
which the MENU_BTN, SELECT_PLUS_BTN, SELECT_MINUS_BTN and EXIT_BTN buttons are
connected:
Next, the ESP8266 Wi-Fi module is initialized as the MQTT client, the setting up the MQTT server
and the connection port for messaging by using the setServer method of the PubSubClient object.
Begin
true
WiFi.status() == WL_NO_SHIELD
false while(1)
status
status !=
!= WL_CONNECTED
WL_CONNECTED
false
true
status == WL_CONNECTED
“Connecting to AP …”
true
Figure 6. Algorithm of initializing the ESP8266 Wi-Fi module and setting up the connection to AP
Then, the measuring loop of the weather parameters starts, their values transmit to the MQTT
server and the measured weather data are displayed on the LCD module.
// reading temperature, humidity and pressure from the BME280 sensor
temp = bme.readTemperature();
lcd.setCursor(0, 0); lcd.write((byte) 0); lcd.print(' ');
lcd.print(temp,1); lcd.print(char(223)); lcd.print("C ");
Serial.print("Temperature = ");
Serial.print(temp); Serial.write(176); Serial.println("C");
humidity = bme.readHumidity(); lcd.write((byte) 1); lcd.print(' ');
lcd.print(humidity, 1); lcd.print(F("% RH "));
Serial.print("Humidity = "); Serial.print(humidity);Serial.println(" %");
pressure = bme.readPressure() / 100.0F * 0.7500616827;
lcd.setCursor(0, 1); lcd.write((byte) 2); lcd.print(' ');
lcd.print(pressure, 1); lcd.print(" mmHg");
Serial.print("Atmospheric pressure = ");
Serial.print(pressure); Serial.println(" mmHg");
altetude = bme.readAltitude(SEA_LEVEL_PRESSURE_HPA);
Serial.print("Altitude = ");
Serial.print(altetude); Serial.println(" m"); Serial.println();
5
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
After collecting data, the device connects to the Wi-Fi access point and sends weather data to the
MQTT server as MQTT message in JSON format. MQTT messages are published to the appropriate
topic using the publish() method, which takes as parameters a topic and message. Next, attempting the
connection to the MQTT server in the loop until the connection to the server is successful:
char jsonBuffer[512];
size_t jsonMessageSize;
if (!mqtt_server_ind) {
// {"sensorId":"bme280", "data":[{"temp": 27.83}, {"humidity": 62.05},
{"pressure": 1013.25}]}
const int capacity = JSON_ARRAY_SIZE(3) + 3*JSON_OBJECT_SIZE(1) +
JSON_OBJECT_SIZE(2);
DynamicJsonDocument doc(capacity);
doc["sensorId"] = bme.sensorID();
JsonArray data = doc.createNestedArray("data");
JsonObject temp_obj = data.createNestedObject();
temp_obj["temp"] = temp;
JsonObject humidity_obj = data.createNestedObject();
humidity_obj["humidity"] = round(humidity*100)/100.0;
JsonObject pressure_obj = data.createNestedObject();
pressure_obj["pressure"] = round(pressure*10)/10.0;
serializeJson(doc, jsonBuffer);
}
else {
// {"temp": 27.83, "humidity": 62.05, "pressure": 1013.25}
const int capacity = JSON_OBJECT_SIZE(3);
DynamicJsonDocument doc(capacity);
doc["temp"] = temp;
doc["humidity"] = round(humidity*100)/100.0;
doc["pressure"] = round(pressure*10)/10.0;
serializeJson(doc, jsonBuffer);
}
Serial.println("Sending message to MQTT topic..");
Serial.println(jsonBuffer);
…..
if (!client.connected() ) {
reconnect();
}
if ( millis() - lastSend >= 1000 ) { // data update and sending
if (client.publish(topic[mqtt_server_ind], jsonBuffer,
jsonMessageSize) == true) {
Serial.println("Success sending message");
} else { Serial.println("Error sending message"); }
lastSend = millis();
}
client.loop();
The interrupt subroutine ISR_BtnPressed() is called when the external interrupt INT2 occurs. The
external interrupt is generated when the MENU_BTN button, connected to the pin 19 (INT2), is
pressed. The interrupt is generated each time the pin output state changes - CHANGE mode.
void ISR_BtnPressed() {
if (digitalRead(MENU_BTN_PIN) == HIGH) {
detachInterrupt(digitalPinToInterrupt(interruptPin));
mainMenuInvoke = true;
}
}
In the main loop, only pressing the MENU_BTN button is processed. After pressing it, the main
menu is invoked. In the main menu a user can set up the IoT weather monitoring device:
6
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
In Fig. 8-17 the prototype testing of the IoT weather monitoring system is shown.
Figure 8. Test circuit (prototype) of the IoT weather monitoring device built on the Arduino
Mega2560 board, BME280 digital atmospheric pressure, temperature and humidity sensor, ESP8266
Wi-Fi module
7
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
Figure 9. Node-RED dashboard flow for the IoT weather data visualization
8
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
Conclusions
In the work, the hardware and software of the IoT weather monitoring systems have been developed.
The hardware of the IoT weather monitoring system consists of the microcontroller device that
measures weather parameters such as temperature, relative humidity, atmospheric pressure and sends
them to the IoT platform for further processing and visualization.
The microcontroller device is built on the Arduino Mega2560 board based on the ATmega2560
microcontroller, the BME280 digital atmospheric pressure, temperature and humidity sensor, ESP-01
Wi-Fi module based on the ESP8266 chip and 16×2 HD44780 LCD module. The microcontroller-
based device for weather monitoring has the menu that allows a user to select Wi-Fi access point,
MQTT server (IoT platform) and data format.
The electronic circuit and model of the IoT weather monitoring device in Proteus VSM have been
developed. The operation algorithm and software of the IoT weather monitoring device have been
developed. The software consists of modules for communicating with the BME280 digital sensor,
ESP-01 Wi-Fi module and the main program for the ATmega2560 microcontroller of the Arduino
Mega2560 board. The main program collects, processes weather data and sends them via MQTT
protocol to the Mosquitto server or to the ThingsBoard IoT platform. The dashboards for visualization
9
CAD in Machinery Design: Implementation and Educational Issues (CADMD 2020) IOP Publishing
IOP Conf. Series: Materials Science and Engineering 1016 (2021) 012014 doi:10.1088/1757-899X/1016/1/012014
of the received IoT data from the Mosquitto server using Node-RED, and on the ThingsBoard IoT
platform using ThingsBoard Dashboard are created.
The operation of the IoT device in the Proteus ISIS emulator has been simulated. The test circuit of
the IoT weather monitoring device on the solderless breadboard has been built and its operation has
been tested. The results of simulation and testing of the IoT weather monitoring system have showed
the correct operation of the developed hardware and software.
References
[1] Peter Waher Pradeeka Seneviratne Brian Russel and Drew Van Duren 2016 IoT: Building
Arduino-Based Projects (Packt Publishing) p732
[2] Adeel Javed 2016 Building Arduino Projects For The Internet Of Things: Experiments With
Real-World Applications p 285
[3] Rajesh Singh Anita Gehlor Lovi Raj Gupta Bhupendra Singh and Mahendra Swain 2020
Internet of Things with Raspberry Pi and Arduino (CRC Press Taylor & Francis Group LLC)
p 190
[4] Electronic resources on MQTT protocols: http://mqtt.org/documentation, http://www.steves-
internet-guide.com/mqtt-protocol-messages-overview/
[5] Tim Pulver 2019 Hands-On Internet of Things with MQTT:Build connected IoT devices with
Arduino and MQ Telemetry (Transport (MQTT) – Packt Publishing 1 edition October 4) p
350
[6] Electronic resource on datasheet of the humidity, pressure and temperature sensor BME280:
http://www.embeddedadventures.com/datasheets/BME280.pdf
[7] Electronic resource on description of the ESP8266 Wi-Fi module connection to the Arduino
board and its programming: http://wiki.amperka.ru/%D0%BF%D1%80%-
D0%BE%D0%B4%D1%83%D0%BA%D1%82%D1%8B:esp8266-wifi-module
[8] Electronic resource on the ThingsBoard IoT platform: https://thingsboard.io/docs/user-
guide/install/installation-options/?ceInstallType=liveDemo
[9] Electronic resource on MQTT broker Mosquitto: https://mosquitto.org/
[10] Electronic resource on Node-RED: https://nodered.org/docs/getting-started/windows
[11] Iwaniec M Holovatyy A Teslyuk V Lobur M Kolesnyk K and Mashevska M 2017 Development
of vibration spectrum analyzer using the Raspberry Pi microcomputer and 3-axis digital
MEMS accelerometer ADXL345 XIIIth International Conference on Perspective
Technologies and Methods in MEMS Design (MEMSTECH) 25-9 doi:
10.1109/MEMSTECH.2017.7937525
[12] Holovatyy A Teslyuk V Lobur M Pobereyko S and Sokolovsky Y 2018 Development of
Arduino-Based Embedded System for Detection of Toxic Gases in Air IEEE 13th
International Scientific and Technical Conference on Computer Sciences and Information
Technologies (CSIT) 139-42 doi: 10.1109/STC-CSIT.2018.8526672
[13] Holovatyy A Teslyuk V Lobur M Sokolovskyy Y and Pobereyko S 2018 Development of
Background Radiation Monitoring System Based on Arduino Platform IEEE 13th
International Scientific and Technical Conference on Computer Sciences and Information
Technologies (CSIT) 121-4 doi: 10.1109/STC-CSIT.2018.8526696
[14] Kosobutskyy P and Ferens R 2017 Statistical analysis of noise measurement system based on
accelerometer-gyroscope GY-521 and Arduino platform 14th International Conference The
Experience of Designing and Application of CAD Systems in Microelectronics (CADSM)
405-7 doi: 10.1109/CADSM.2017.7916162
[15] Lobur M Korpyljov D Jaworski N Iwaniec M and Marikutsa U 2020 Arduino Based Ambient
Air Pollution Sensing System IEEE XVIth International Conference on the Perspective
Technologies and Methods in MEMS Design (MEMSTECH) 32-5 doi:
10.1109/MEMSTECH49584.2020.9109460
[16] Matviykiv O et al 2019 Lab-chip Diagnostic Device for the Rainwater Monitoring System
Using Wireless Sensors Network MIXDES - 26th International Conference "Mixed Design
of Integrated Circuits and Systems 241-5 doi: 10.23919/MIXDES.2019.8787185
10