Introduction
The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data. Moreover, ML analyses past behavior to identify the pattern and offers future prediction using different kinds of algorithms.
Components
The implementation of the project comprises three major parts as described.
- Internet of Things
- Data Logger
- Machine Learning
Architecture
1. Internet of Things
IoT part includes,
- Sensors
- An IoT device
Sensors – Firstly, Measurement of multiple parameters can be done using primary sensing elements or electronic sensors, For Project, DHT11(Temperature Humidity sensor).
An IoT device – After that, an IoT device is used to establish a stable connection with the Internet. In addition, it can make a connection with any data logger for data-storage and data-analysis. For Project, ESP8266(NodeMCU).
Circuit diagram
Generally, DHT11 consists of three pins VCC, Data pin, and GND(ground). Interfacing of DHT11 with ESP8266 can be represented by connecting DHT11,
DHT11 | ESP8266 |
VCC | VIN |
Data pin | D0 |
GND | GND |
2. Data Logger
The main function of the data-logger is to store the acquired data with respective dates and timestamps in a server-based database. So that it could be accessed remotely. Moreover, based on the collected data logger provides specific features like,
- Graphical Representation,
- On-field and Off-field monitoring,
- Mathematical analytics,
- Future prediction of acquired data.
Google drive comes up with Google sheets in which data can be inserted using Google scripts over a network. Admin can publish Google sheets via Google scripts as a web app.
3. Machine Learning
The main aim of Machine Learning is to observe data and perceive upcoming events. It provides systems the ability to learn automatically and control actions over the measuring variable so that it does not exceed the limit.
The Random Forest algorithm is one of the most popular algorithms that works on a supervised technique. It can be used for both Classification and Regression problems in ML. Above all, It is based on the concept of ensemble learning. In other words, it is a process of combining multiple classifiers to solve a complex problem and to improve the performance of the model.
Working diagram
Firstly, It applies 75% of the data to the Training set and the remaining 25% of the data to the Test Set. Consequently, the decision tree comes up, and at the end prediction takes place with ±error and specific percent of accuracy.
Source – JavaTpoint
Working and Code Implementation
Part-I (Data Logger)
First of all open Data-logger for the project, Google sheets from Google drive account.
Rename your sheet and give names to the 1st row of the spreadsheet as described below.
Open Google scripts from Tools–Script editor.
Insert the code in Google scripts.
Part-II (IoT)
After that start measurement of the temperature using DHT11. DHT11 contains in the structure NTC temperature sensor(Thermistor) to measure surrounding temperature. Measurement of the temperature includes three parts,
Request to DHT11 – Microcontroller unit (For instance, ESP8266 board) sends low to high pulse as a request to DHT11. Respond from DHT11 – After receiving the request DHT11 sends low to high pulse as a response to the ESP8266 board. Data transmission – At last, data transmission from DHT11 to the ESP8266 board done in 5 bytes(40 bits).
2 bytes for RH(Relative Humidity), 2 bytes for Temperature, and 1 byte for checksum which checks whether the data is received or not.
Source code
After making circuit connections as per the circuit diagram given above and managing board and library setting upload the code given below in Arduino IDE.
As a result, Output of the code in Serial Monitor of Arduino IDE.
Part-III (Machine Learning)
In the end, after gathering a large amount of the data at the end apply machine learning online using Python from Jupyter Notebook.
After downloading the acquired data Google sheet Excel file, open it in Jupyter Notebook. Subsequently, In the terminal install the XLRD.
At the end open the given python code file into the Jupyter Notebook. Most importantly, change your excel file name.
Consequently, Prediction after Machine Learning,
So basically I have collected the temperature data of Basel, Switzerland from 1st January 2019 to 31st October 2020. After that implemented machine learning on that data in python and made the prediction of the temperature.
In the above two photos, the left side photo is representing the predicted temperature of 25th November 2020 based on machine learning with ±4 °C error and the right side photo refers to the actual temperature on the same day.