Application of the Internet of Things in the Development of a “ Smart ” Door

— In this article we propose the development of a prototype that consists of two systems that make a door "intelligent". These door-coupled systems allow a person through an application to have control and access to the door, gaining information about who the door is by unlocking and locking it without having to move to the door. For the development of these systems was used the microcontrollers of the esp8266 family, as these allow connection to wi-fi network, making other devices with access to this network can connect, such as a smartphone with application. During the development of the prototype one can observe the complexity for the production of the application and the communication between the systems by wi-fi. However, the low cost of systems and the availability of peripherals that allow the integration of these systems with the most varied applications, make electronic security accessible to all those who wish to enjoy, further enabling technological inclusion in society.


INTRODUCTION
The definition of the "internet of things" is to say that all "things" can be monitored or given data and can be used for various purposes. More technically, through sensors and embedded electronics providing access to data over the internet. (STEVAN JR., 2018) Internet devices and equipment are usually marketed with high prices, as they offer comfort, practicality and a differential for the user of the technology, making it difficult and limiting access to a certain public. How then is it possible to enjoy such benefits at low cost?
The development of a prototype, us ing low cost electronic components and knowledge of electronics, automation and basic programming can show how it is possible to have access to such resources, solving problems, bringing practicality to our everyday life and giving us the possibility to follow the technological evolution in real time.

II. THEORETICAL REFERENCE
When we think of an autonomous microcontrolled system, we think of a system that does the task alone, without the need for human interference. For this, our system must be endowed with some intelligence, such as a computer or artificial system. In systems the ESP8266 will be used as the brain of our system.
The smart door will be built into systems installed at strategic points in the door. On the outside we will have system 1, which will be composed by presence sensor, NodeMCU (ESP8266), LCD Display and IP camera.
The presence sensor is an electronic module that functions as an input peripheral within a system, ie, it sends information to the brain of the system (NodeMCU) and it decides which function to perform. Here, the sensor will have the function of identifying the presence of an individual at the door.
The NodeMCU is a microcontroller that has the feature of being able to connect to Wi-Fi networks. It will perform two functions in this system from the moment you receive information from the presence sensor, the first being to send a notification to the smartphone of the owner of the system that there is a person at the door and trigger a message on the LCD to inform the person that their presence has been identified, so the person does not have to worry about using any means to inform the owner of their presence.
The IP camera is a separate device, ie without interaction with the system, only with the owner's smartphone containing the application that will give access to the camera, so when the owner receives the notification it will open the application to know who the door is, if you recognize the person, this through the application can unlock the door. System 2 is inside the door. And it will be responsible for the control of the door, consisting of the Wemos D1 Mini (ESP8266), relay module and solenoid lock. Basically, this system has the function of receiving the command of the application to unlock or lock the door. However, for this command to be sent from the Wemos D1 mini to the latch, it is necessary that there is a relay module interlocking them, as they both operate at different levels of electrical current.

Programming and Applications
The systems composed of the ESP8266 microcontrollers have been programmed in the C language through the Arduino IDE, software that allows programming through the creation of sketches. These sketches would be what we could define as instructions.
Working in conjunction with the Arduino IDE, we have the Blynk App. This application allows the development of applications that require connectivity, ie, internet interaction for sending data and remote control devices. In the proposed system, BlynkAppterá an application that will notify the owner whenever there is a person at the door.
Finally, we have App Inventor, a software developed for anyone who has never programmed, but wants to start creating applications. With this tool it was possible to develop the application responsible for accessing the IP camera and controlling the port.

Communication
The default mode of Wi-Fi communication used in most applications is called "fixed infrastructure" due to the presence of an access point (AP) that is intended to connect to Wi-Fi network communication. In this mode, all communication must go through the AP, which identifies its recipient and passes the communication.
In the prototype developed, the two systems together with the smartphone that owns the application are connected to a router. This functioning as access point, will have the function of mediating the communication between these devices, thus allowing them to form a Wi-Fi network.

III.
MATERIAL AND METHOD The development of each system occurs in such a way that all the components that have pins, these pins will be responsible both for the connection of the components to each other, and for performing certain functions. Therefore, the pins that would be responsible for establishing electrical connections between the components are defined. So programming is developed through the Arduino IDE. With the pinout having been defined, they must be declared in programming.
With the development of the programming finished, the program is transferred to the microcontroller of each system through USB connection. Then, it is observed whether the components of each system were performing the functions that had been defined during programming.
Starting the most important stage of the project, we established communication between the systems through the implementation of each program and the use of Wi-Fi network, along with the development of the application to be used by the user. The same was installed on a smartphone to test communication with the systems.

Sistema 1
In system 1, we have the presence sensor that for its operation, needs a power of 5 to 20 volts. The LCD display needs 5V. Note that both operate at 5 volts, so an external 5-volt power supply has been added to the design, as the NodeMCU is not able to supply such voltage as it works with the 3.3 V voltage on its pins. Thus, VCC and GND will be the respective pins fed by the source as shown in figure 1.
The NodeMCU will work with the D1 pin running on a GPIO and pins D3 and D4 have functioned as SDA and SCL respectively. D1 will be connected to the OUT pin of the presence sensor that works with an output voltage of 3.3V, meaning that a detected movement remains at 0V if there is no movement. However, pin D1 running as GPIO interprets these values as 1 or 0 respectively. The OUT pin remains energized for a certain time, this is due to the presence of a trimpot that is responsible for the time the output remains at high level. With this, the trimpot was adjusted according to the time in which it was desired that the display would be shown the message to the client. This will be better explained in the programming logic part.
Regarding the LCD display, the SDA pin will be connected to the D3 for serial data transmission and the SCL pin connected to the D4 for sync, also serial. In order to read the presence sensor, it is necessary to state in the sketch in which pin the sensor communicates with the NodeMCU, how it is operating, in this case, as input, ie, sending data to the NodeMCU, and add the function that will be responsible for reading the digital pin, reading is with two values, 1 or 0.
A decision making is done according to the value read by the NodeMCU, actions will be defined through a

International Journal of Advanced Engineering Research and Science (IJAERS)
[ Vol -6, Issue-5, May-2019]  https://dx.doi.org/10.22161/ijaers.6.5.46  ISSN: 2349-6495(P) | 2456-1908(O) conditional structure. In this case, the value that interests us is 1, since it indicates that a presence has been identified. And it is based on this value, that the conditional structure will perform two actions.
In order for the welcome message to be displayed, it is necessary to establish a communication between the NodeMCU and the LCD Display, and this is done through the I2C protocol and also the definition of the pins that will be the communication channels. The display will show the message only for the time that the OUTPUT pin of the presence sensor is set to 1. As the sensor trimpot has been set.
Sending notification to your smartphone through Blynk takes place in two steps. The first step is to install Blynk App on your smartphone, in this application we will develop a secondary application that will send a notification if someone is detected. Each application that is developed in the Blynk App, receives an access key. This access key will be responsible for establishing communication between the NodeMCU and the Blynk App. In step 2, we configure the NodeMCU to communicate with the Internet, to access the Blynk Server. Thus, the NodeMCU is identified by the server through the acces s key and the server sends the notification to the smartphone. System 2 To connect the magnetic sensor to the Wemos D1 mini, we need to add a resistor so as not to short-circuit the microcontroller. Insertion of the resistor is necessary to reverse the input. Without the drive, the 0 volt signal arrives at the GPIO input by the resistor. When it is activated, the 3.3 volt signal arrives directly at the GPIO pin, which can understand the change of the input signal. With this we use pin D3 for the magnetic sensor according to Figure 2. The relay module used in this project is nothing more than a shield to be attached to the mini D1, this shield has a circuit in its bottom that allows interaction as the D1 mini without complications.
Like the NodeMCU, the Wemos D1 mini runs 3.3 V on its pinout. Therefore, the addition of a transistor circuit allows the activation of relay of 5 volts. The transistor acts as a switch powered by 5V, voltage that can be obtained through the board itself through the pin VIN or VCC.
The relay is driven by pin D1. When the signal sent by the board is high, ie 3.3 V, the transistor is polarized and creates a channel between the 5 V VCC and the relay activation pin. The resistors are calculated precisely to make possible the polarization of the transistor.
The electric lock requires a power supply of 12 V and 2 A. The Wemoscan not supply the lock and therefore an external source is used. The interaction between the lock and the Wemos is done through the relay module. The contacts used in the NO (normally open) relay module, which is open until the coil is powered (when it is closed). In this is the positive part of the power supply that connects the lock. And the COM (common) contact that receives the positive from the source.
Finally, Wemos shares as the NodeMCU the two I2C communication pins of the LCD, all Wemos pins have support for I2C communication accepted to D0, in case the selected ports were D2 and D4.

System Programming Logic 2
To establish communication between the Wemos and the Application will require the creation of WebServer through the Arduino IDE. The WebServer will have to send Wemos data to the application by Wemos, the latter will act as server receiving, processing and responding to requests made by the client, in this case, the Application.
The port sensor will function as a digital input sending signals, depending on the state of the port, this sensor works as an NF (normally closed) switch, ie if the sensor contacts are close the signal sent to the Wemos will be 3.3 V , at this time, the Wemos running as a server will send the client a message that corresponds to the status of the port, in case the port is closed, in addition to sending the status, will also perform the door lock. If the sensor contacts are distant the signal sent will be 0 indicating only that the status of the sensor is sent.
Responsible for triggering the lock through the application, wemos functions as a server waiting for the requested requests from the client, these requests will be made by creating a URL, in the case of the project, two web pages will be created for the URL, one page will be created responsible for triggering the other relay of the

International Journal of Advanced Engineering Research and Science (IJAERS)
[ Vol -6, Issue-5, May-2019]  https://dx.doi.org/10.22161/ijaers.6.5.46  ISSN: 2349-6495(P) | 2456-1908(O) lock by disengaging the relay of the lock by unlocking the door. In the application, the web pages will be represented by a button represented by an icon of an open lock if the relay is not activated, and a closed lock icon if relay is activated according to Figure 3. The smartphone will interact with both the NodeMCU and the Wemos D1 mini. For this to be possible, all devices in the system must be accessing the same network. In the project in question, a router will be functioning as access point, to have access to the router is necessary to know the name and password of the same. Thus, with all the devices connecting to the same access point, it is possible to establish a communication between all of them.
NodeMCU will communicate with the smartphone through the Blynk App only if a presence has been detected, in this case the Blynk App will trigger a notification on the smartphone home screen notifying the user of the presence.
Next, the user will open the Smart Port 1.0 application as shown in Figure 4. On your main screen we will find two buttons, one for port control and the other for viewing the IP camera application. The idea is that when receiving the notification the user opens the application and press the button to view the IP camera, in order to know who the door is.
In the application, we will also find the status display area, which will help the user know when the door is open or closed when it is unlocked, so that we can activate the same unlock button to lock. Analysis and discussion of results During the development of the project, there were difficulties that were already foreseen, among them, we had the first one that was with regard to the notification, which would aim to warn the user of the presence of someone. Initially, it had been planned that the notification was from the door application itself. For this, during the development of the application would be added an extension called TaifuNotification, which would be responsible for the notification. However, it was found that the extension only executed the notification if the application was running or sending some command to notify.
With this, we looked for other alternatives, like using Telegram message application. In this, a bot was used called BotFather, this bot allows to use commands of residential automation, through sending and receiving messages, the results were positive, but the idea of having to run two applications with basically the same functions is not interesting. Finally, Blynk App was used, an exclusive application for the development of project and of easy understanding, that met the needs.
Another difficulty found in the project was in relation to wi-fi communication between the systems. Due to the lack of knowledge in programming, and delimitation of processing systems, another alternative was to establish I2C communication to share the LCD Display.
During project development, other ways were known to simplify, reduce project components, and use only the door application as interaction. One of them, would be to use the esp32, development board that has wi-fi and bluetooth communication, plus two processing cores, which allows to perform various tasks, reduce the number of boards. The esp32-cam model, besides having all these functions, also comes with a camera attached to the board, here we would reduce space, components and above all cost. For both boards do not reach more than 10 dollars in international shopping sites.

IV. CONCLUSION
The development of the prototype allows us to understand that the Internet of Things has become a reality due to the low cost of electronic components and microcontrollers, allowing the development of microcontroller systems that are used for certain applications that do not require much energy or many tasks. Alongside this, we have the development of portable devices that complete the scenario bringing mobility and easy access to information from these systems. Finally, the control of digital access to a port increases the level of security of an environment, in addition to bringing comfort to the user.