Implementation and Analysis of an IoT-Based Home Automation Framework

The pervasive advancement in the field of an autonomous system is significantly influenced by the concept of integrating a large number of devices. The use Internet of Things (IoT) has increased day by day for making connected devices over the internet. Besides, mobile sensing devices operated by IoT including smartphones, tablets, digital cameras, sensors, etc. are providing access to a large variety of data and services based on human interaction. In this paper, the implementation and analysis of an IoT-based home automation framework using NodeMCU through the MQTT protocol are described. This helps the users to monitor and control home appliances from remote places by using a mobile application over the internet.


Introduction
A home automation system gives privileges to the users to control and monitor the home appliances through a remote mechanism like an IoT application. It implements the system as the integration of controllers, sensors, and actuators as a whole by following the radio frequency concept coined in 1999 [1]. The IoT enables the physical device to transmit real-time data in heterogeneous networks by maintaining the recent security protocols via the internet [2]. At the same time, the invention of the microcontroller offers most of the intelligent IoT building techniques of home automation. The IoT can be incorporated with the perception layer, the network layer, and the application layer. For example, wireless sensors, RFID, sensor cameras, GPS, etc. are operated in the perception layer. The network protocol mostly includes Gateways, Bluetooth, ZigBee, Wi-Fi, etc. [3]. Again, the automation system of building, home, city, power line is operated in the application layer.
The main component of the IoT based automation framework is a Wi-Fi-based node microcontroller unit (Node-MCU) [4]. It is a programmable circuit board using the IDE (Integrated Development Board) for coding the instructions and uploading them to a microcontroller. An android application is developed to control and monitor the automated devices using sensor data via smartphone. This home automation uses cloud-based MQTT protocol to the in-built security technique. The commands for the appliances are sent through the cloud by using the MQTT protocol [5]. We used the IoT cloud as an open-source platform. Node-MCU has a programmable circuit in an Arduino or a Raspberry Pi board. We use the IDE (Integrated Development Environment) for writing instruction codes [6]. Mobile apps are used for accessing and controlling home electronic devices.
The most important contribution of this research is to implement a low-cost and user-friendly IoT based home automation framework using open-source firmware Node-MCU through MQTT protocol. The proposed system monitors home environment parameters such as temperature, humidity, light, etc. After monitoring the parameters, it controls the home appliances through the internet at any time from anywhere. The contributions of this research are given below: 1) Implementation of an IoT-based smart home framework that monitors and controls home appliances remotely from anywhere without the need of a mobile provider to support home safety, security, and energy-saving. 2) A rain sensor is also added to detect the raindrops that automatically control the rain shed.
The organization of this paper is structured as follows: Section 2 describes the literature review, Section 3 presents the system design, Section 4 introduces the implementation, Section 5 discusses the results and finally, Section 6 concludes the paper.

Literature Review
This section outlines the related works. Suneetha and Sreekanth [7] proposed a smart home system that can control electronic devices based on the environment. Raspberry pi board and Arduino UNO have been used in the system. The system can notify the people about gas leakage and the presence of fire. It also has security system facilities and can also detect object motion, temperature, and humidity. The system is very simple and user-friendly. But it cannot control the brightness of the light or the speed of the fan.
Sy et al. [8] proposed a wireless home automation and security system that is designed for the homeowners to feel secured and comfortable. They used an RFID tag card for the security purpose of the home users. They used Arduino, an infrared (IR) receiver, RFID card reader, to read the RFID tag. They used IR based wireless communication to control home appliances. They designed this low-cost home automation with a security system. The limitation of this system is the working range (approximately 10 meters).
Thakur and Han [9] proposed a ubiquitous framework that aims to leverage the immense potential of activity centered computing in an IoT environment. Elderly people face different problems like motor disabilities, physical limitations. To ensure smooth functioning, the proposed framework should address the aforementioned challenges.
In recent years, the home automation system is important to the research community as it helps us in leading a good quality of lifestyle. Sivapriyan et al.
[10] reviewed different types of communication methodologies such as GSM, IoT, Wi-Fi, and Bluetooth for the development of home automation.
Martirano [11] described a bimodal low cost as well as energy-efficient lighting control architecture using an android-based smartphone. This technique works using a Wi-Fi module for communicating among remote users and household appliances. Here ESP8266 plays the role of a server and Arduino UNO plays the role of an interpreter of instructions. Chakrabarti and Engels [12] developed an android smartphone-based nice automation method that is low cost as well as secured. The proposed method utilizes RESTful based web services with an interoperable application layer for communication of remote users with the home appliances.
In paper [13], the author presented a smart home based on a smartphone with a touch to speech feedback. This approach solves the problems of accessibility and comfort inside the home. This is especially useful for visually disabled people. They designed the technological part by developing a web server. This web server uses an Arduino UNO board with a Wi-Fi module. The smartphone is connected to the webserver through a router. The router receives the information about the home location and sends a signal to power up the electronic devices. Experimentation was performed with the subjects of visual disabilities and motor disabilities.
In [14], the authors described the design of a home automation system using dual-tone multiple frequencies (DTMF) based home automation system. The purpose of this DTMF based home automation is to develop an embedded system. This system can control remote home appliances remotely by using telephone lines.
Paper [15] described a low cost and flexible home control and monitoring system. This system is based on a Raspberry PI module and a static relay for accessing and controlling the appliances remotely by using a smartphone-based android application. The proposed system does not require a dedicated server PC concerning similar systems. The system offers a novel communication protocol to monitor and control the home environment with more than just the switching functionality. Paper [16] gives the concept of a new circuit topology for monitoring and controlling the electrical devices which use the android system implemented by a wireless transceiver. In [17], the author presented a cloud-based home automation system using the MQTT protocol. It gives the users the facility of controlling and monitoring home appliances through a mobile app or a web page.
In the present paper, we describe a home automation framework that provides indoor and outdoor control, safety, security, monitoring from distant places through the Wi-Fi interface and a NodeMCU. The system is implemented in real-time with smartphones and web-based technologies.

System Design
The prototype of the proposed smart home is designed and shown in Figure 1. The smart home has two rooms, one kitchen, one bathroom, one veranda. There is a ventilator in the kitchen. Figure 2 depicts the framework of the proposed architecture including different components.
For the design and implementation of an IoT based home automation system, it uses an opensource firmware Node-MCU through MQTT protocol along with diverse sensors, such as temperature and humidity sensor DHT11, PIR motion sensor HC-SR 505, gas sensor MQ2, rain sensor YL-83 for measuring the temperature, humidity, smoke, gas leakage, and rain. Several actuators control the activities of electronic devices of the home. The lights and fans are controlled by the dashboard. A graphical user interface (GUI) helps to interact with users and the system and ensures the comfort and safety of the users.
The main entrance of the home has a door with a motor and motion sensor. This PIR motion sensor attached to the door detects the motion. This will let the door open and close automatically. The working flow of this prototype is depicted in Figure 3.   Our smart home automation system uses web services as an interoperable application layer. The system has a micro web server that is based on Arduino ethernet and hardware interface module. The proposed system allows authorized users to control and monitor connected appliances. A graphical user interface (GUI) for accessing and controlling the devices is provided by the webserver.
In Figure 3, first of all, the ESP8266 is connected to the power switch. After that, it is connected to Wi-Fi and it gathers the data from different sensors. Then it sends the data to the MQTT dashboard. If the gas is detected from the gas sensor, the exhaust fan of the kitchen is ON. Otherwise, the exhaust fan is OFF. If the temperature value is greater than the threshold value, the room fan or AC is ON. Otherwise, the fan or AC is OFF. If it is raining, then the rain detector detects it and the window is shut down. Otherwise, it is open.

Components
The home automation system in our experiment includes ESP8266 or Node-MCU board v2, temperature sensor, gas sensor, motion sensor, humidity sensor, LED, potentiometer, motor drivers whose physical views are shown in Figure 4. a) Node-MCU Node-MCU 1.0 (ESP-12E Module) is an IoT development board consisting of ESP8266, SoC integrating a 32-bit microcontroller [18] that uses Wireless 802.11 b/g/n standards and supports three operating modes STA/AP/STA+AP. In the study, we used the microcontroller (NodeMCU/ESP8255) as the central unit of the prototype. We connected all the devices to the microcontroller board through jumper cable. The actuators such as light, fan and potentiometer through the 4 channel relay board. The power supply may be from the battery or other power source. b) 4-Channel 5V DC relay module. It is well known for controlling a high powered circuit by a low power signal. Usually, a DC signal is used for controlling the circuit which is driven by high voltage such as controlling AC home appliances through DC signals from microcontrollers [19]. The relay board is used for controlling high voltage AC, fan washing machine. We used a 4-channel relay module. We connected to light, Fan/AC through the relay module. c) DHT11 temperature sensor. DHT11 sensors are generally used for sensing the temperature and humidity of an area. It works for triggering related devices with a relay module [20]. DHT11 is one of the most popular and low-cost temperature sensors. DHT22 is another one. But its cost is high and it's not available. We measured the temperature and humidity through this sensor. It is connected to the microcontroller board. d) PIR motion sensor (HC-SR 505). A passive infrared (PIR) sensor is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view [21]. PIR sensors are commonly used in security alarms and automatic lighting applications. In this study, we used the imaging motion sensor. It detects Journal of Computer and Communications the presence of a person at the door. We can monitor the presence of any intruder through the motion detector from a remote place. e) MQ2 gas sensor. MQ2 gas sensor is an electronic sensor used for sensing the concentration of gases in the air such as LPG, propane, methane, hydrogen, alcohol, smoke, and carbon monoxide. MQ2 gas sensor is also known as chemical-resistor [22]. It contains a sensing material whose resistance changes when it comes in contact with the gas. It can detect gases in the concentration of range 200 to 10,000 ppm. There are different types of gas sensors such as MQ4, MQ5, MQ7 etc. Especially, we used the gas sensor MQ2 in the kitchen of the smart home.
f) Other components. A light-emitting diode (LED) is a semiconductor light source that emits light when current flows through it. Electrons in the semiconductor recombine with electron holes, releasing energy in the form of photons. The colour of the light (corresponding to the energy of the photons) is deter-mined by the energy required for electrons to cross the bandgap of the semiconductor. Appearing as practical electronic components in 1962, the earliest LEDs emitted low-intensity infrared (IR) light [23]. We used the LED for visualizing the status of a device. Suppose Motion is detected in the door, then the LED is ON. This is used as an indicator for showing the status of the devices or sensors.
YL 83 is a rain sensor. It has two parts: the electronic board and the collector board. It works on the principle of droplet detection. If the raindrops fall on the collector board, it sends the signal to the electronic board. We set the collector board at the veranda without a roof so that it can collect the droplet of the rain. FC 37 is another rain detector sensor. But we choose YL 89 because we can get the value in two minutes.
Cytron 10A Switch Control Potentiometer DC Motor Driver (MD10POT) is made for DC brushed motors which are widely used in many applications due to the ease of use. We can control the speed and direction of the DC motor through this driver MD10-POT is a motor driver or speed controller that enables us to control the start/stop, direction, and speed of the motor without any hassle [24]. We used the potentiometer for controlling the speed and direction of the sliding window or sliding door. A motor driver is used with a cable that performs the work for opening or closing the door.

Algorithms
The algorithm of the prototype describes the whole procedure step by step that is shown in Algorithm 1. Node-MCU gets connected to the server along with the other devices. The LED is on/off by the push button on the app through a virtual switch on the dashboard. We can control the home appliances from anywhere using internet connectivity. The room temperature and humidity are displayed on the dashboard. We can use a fan or air conditioner in U3 by adding relays. We can turn on AC if the temperature above 25˚C. Similarly, we can turn off the AC if the temperature below 18˚C. The gas sensor can detect the presence of gas and smoke and the motion sensor can detect the presence of an intruder.  The prototype of the dashboard is implemented using Arduino IDE (Sketch). Ubidot IoT server monitors the condition of home environmental parameters and controls the home electronic devices through the MQTT protocol. A graphical user interface (GUI) is for controlling the devices with fingertips on a mobile screen. First of all, we implemented all the sensors and actuators in the breadboard. The enhancement program is conducted in the virtual breadboard shown in Figure 5. Then we implemented it in a real breadboard shown in Figure 6. Journal of Computer and Communications

Development of Android APP
To develop an android application, we need to set up an Android IDE with some custom settings to access the PAHO library which is an MQTT client library. This library is written in Java. This is used especially for developing applications on Android [25]. The Paho has been created to provide a reliable open-source platform. It implemented an open and standard messaging protocol. The intension was to give a new and emerging application for Machine-to-Machine (M2M) and the Internet of Things (IoT) [26]. Paho gives the following facilities: 1) Reduces the physical and cost constraints of device connectivity.
2) It provides effective levels of decoupling between devices and applications.
3) It designs scalable web and enterprise middleware and applications. 4) Eclipse hosts a Nexus repository for those who want to use it. 5) It manages application dependencies and sets up a build environment so that we can use the same repository to get the Paho Android Service.
Adding the repository definition and the dependency code is shown in Appendix A. To complete the setup, we have to add few permissions to the android manifest such as-internet, network state, and phone state.

Result and Analysis
The process of this smart monitoring approach is shown in Figure 7. Here first activity allows the user to scan a QR code to get the server information since each user has a unique dashboard on the server. The second activity asks the user to connect to the MQTT broker and the third activity shows all the data provided by the broker. We can control the appliances from the MQTT dashboard. Figure 7 shows that the light is on, motion detection gives NORMAL status and the rain detector gives DETECTED indicating that no one is waiting in front of the door and it is raining.
The process of this smart monitoring approach is shown in Figure 7. Here first activity allows the user to scan a QR code to get the server information since each user has a unique dashboard on the server. The second activity asks the user to connect to the MQTT broker and the third activity shows all the data provided by the broker. We can control the appliances from the MQTT dashboard. Figure 7 shows that the light is on, motion detection gives NORMAL status and the rain detector gives DETECTED indicating that no one is waiting in front of the door and it is raining.
The price of the sensors and actuators used in the implementation of the smart home does not differ very much for changing their brand. But the price of the microcontroller board (Node-MCU or ESP8266) is different. Due to this reason, the cost of the smart home implementation mainly depends on the price of the microcontroller board. The comparative study is given in Table 1.
We compared the performance and cost of four microcontroller boards (ESP8266). The chart in Figure 8 shows the parameters. We find that the ESP8266 is the best performer. The Galileo board is too costly. Arduino Uno uses more current and voltage and also needs extra board for the extension. We   Figure 8. Comparison of microcontroller boards. compared the operating system, clock speed, SRAM, Digital I/O, DC current and cost parameters. In X axis, we represent the properties of the microcontroller boards and in the Y axis, we represent the units of measurement.

Conclusion and Future Work
Home automation based on IoT is one of the promising and essential issues in recent times. It provides a comfortable living. In this paper, we implemented an IoT-based low cost and flexible home automation system framework through a mobile android app. We used ESP8266 as a microcontroller board with the Wi-Fi module. However, in future work, we will develop a smart building and as well as a smart city. The big challenge is to manage all in real-time data in a well-organized pattern.