A Prototype of Smart Lock Based on Internet of Things (IoT) with ESP8266

Received 17 January 2020, Revised 30 January 2020, Accepted 11 February 2020. This study aims to design a prototype house that has an automatic safety system installed that has two inputs for its control. The developed system can be controlled via an Android or IOS smartphone that has the Blynk application installed, or by using a PIR sensor installed in the circuit. The output in this series of systems is a solenoid lock which is used as a door lock for the house later. This research refers to the ADDIE development model with details: (1) Analyze, (2) Design, (3) Development, (4) Implementation and (5) Evaluate. Based on the testing of each component used, the results are obtained in the form of PIR sensor readings with a radius of 90cm with an angle of 120 degree with a voltage of 5V, a solenoid lock that uses a 12V voltage, a pin from the Wemos D1 R1 board that has errors on its 2 input/ output pins, and a battery that can be used as a backup power source when the main power source goes out for more than 5 hours.


INTRODUCTION
The house is one of the buildings used as a place to stay for a long period of time. Most of the activities carried out by homeowners are usually done outside the home. Things like this often occur in big cities. This makes the house left empty for a long time, especially on celebrations such as Christmas, New Year and Eid.
Such housing conditions can lure criminals to commit theft. This can be seen based on data released by the Statistics and Security Sub-directorate in 2018 [1], that the theft rate that occurred in 2018 was in the range of 11.42 -73.76 percent of the total villages in each province. Of the 34 provinces in Indonesia, theft crimes are in the range of 44.94 percent. Apart from the condition of the vacant house, another factor that causes high theft rates is the security system used in most homes is still very minimal, to increase the theft rate.
Nowadays the internet is almost the center of the crowd in the middle of the city. People from all over the world will interact, socialize and also do business only through the internet. Currently, several large vendors have also begun to compete in creating technology where objects around us can interact with the internet, this technology is now better known as the Internet of Things (IoT).
To access the internet, each individual needs a device that can make it easier to use and when they want to travel. Thanks to technological developments, devices that can be used to access information when located anywhere and at any time can be used. The device is currently known as a smartphone. Currently, the use of smartphones that have mushroomed almost to every level of society makes it one of the must-have equipment. This is because of the ease of use when trying to access information, the relatively inexpensive price of a smartphone makes it available to anyone who needs it.
Installation of expensive security systems makes users very rare and only in certain groups. Plus security systems that already exist are mostly not accessible anywhere and anytime using a variety of electronic media, both smartphones, and PCs. The development of a home security system that can be accessed from anywhere and at any time is expected to overcome these problems. Control devices using an Android-based smartphone are easier to use [2]. Some research on existing home security includes using a surveillance camera [3], PIR sensor [4], Smart Card [5], and proximity or location detector [6]. In this study, researchers developed a product in the form of a safety system that can be controlled using a smartphone through the internet network so that it allows users to control home security remotely. In addition, the house is also equipped with sensors to detect thieves so that when there are strangers who enter the house, the owner of the house will immediately get notification directly and activate the buzzer installed at home to notify the house if there is a thief who enters the house.

LITERATURE REVIEW 2.1 Internet of Things
Today, we are living in the era of smart technologies which represent a "ubiquitous computing" or "web 0.3" [7]. The use of the internet in the future can dominate all work done and defeat human computing capabilities such as controlling electronic equipment remotely using internet media. All objects have an IP as their address and can be tracked [8].
Technology trends that will affect the IT field in the next five years will be laid out by Gartner and among them are the Internet of Things. Internet of Things is a concept or paradigm that considers the existence of various things/objects/applications/other services in the environment to create something new and achieve common goals. All objects have an IP as their address and can be traced [9]. Internet of Things is defined as an invention that can solve existing problems by combining technology and social impact, meanwhile if viewed from the standardization of IoT techniques it can be described as a global infrastructure to meet the needs of the community [10].
Every equipment used in life from transportation, household equipment, and industry can be connected to the internet and monitoring can be easier and can be done anywhere. According to Betts [11], there will be many technology towers referring to IoT, such as communication machines, cellular and telecommunications networks, applications, smart devices, and security. However, all that cannot be predicted for future development.

Blynk
Blynk ( Figure 1) is a new platform that allows you to quickly build interfaces to control and monitor hardware projects from iOS or Android devices [12]. After downloading the Blynk application, we can create a project dashboard and arrange buttons, sliders, graphics, and other widgets to the screen. Using widgets, you can turn pins on and off or display data from the sensor. Blynk is perfect for interfacing with simple projects such as monitoring temperature or turning lights on and off remotely. Blynk is the Internet of Things (IoT) which is designed to make remote control and sensor data read from an Arduino or ESP8266 device quickly and easily.

Arduino UNO
The microcontroller is a computer on a single integrated circuit that includes a CPU, RAM, some form of ROM, and I/O ports [13]. It contains a processor core, memory and input/output equipment. Arduino microcontroller is a microcontroller board that is very popular and has been recognized for its superiority. Arduino is an electronic kit or open-source electronic circuit board in which there are main components, namely a microcontroller chips with AVR type from the company ATMEL.
Wemos D1 R1 ( Figure 2) is a microcontroller device which is equipped with a Wi-Fi module ESP8266. Wemos D1 R1 allows users to create a circuit that can be connected to the internet with quite a lot of input/output. ESP8266 has board processing and storage capabilities that allow it to be integrated with sensors and other application-specific devices through GPIO with minimal up-front development and minimal loading during processing time [14].

PIR Sensor
PIR (Passive Infra-Red) sensor is a sensor used to detect the presence of infrared rays. PIR sensor is passive, meaning that this sensor does not emit infrared light but only receives infrared radiation from outside. PIR sensor is shown in Figure 3. This sensor is usually used in the design of PIR-based motion detectors. Because all objects emit radiation energy, a movement will be detected when an infrared source with a certain temperature (e.g., human) passes another infrared source with a different temperature (e.g. wall), the sensor will compare the infrared rays received by each unit time, so if there is movement there will be a change in the reading of the sensor. PIR sensor consists of several parts, namely: Fresnel Lens, Infrared Filter, Pyroelectric Sensor, Amplifier, Comparator. In general, the PIR sensor has an effective reading range of up to 7 meters, and this sensor is very suitable as a human detector.

Solenoid Lock
A solenoid ( Figure 4) is a type of coil made of long, tightly wound cables and it can be assumed that its length is greater than its diameter. Whereas the Solenoid Key is a combination of a key and a Solenoid which is commonly used in the electrification of a device as an automatic lock and others The Solenoid Principle was discovered by a French physicist named Andre Marie Ampere. In the field of engineering, this term refers to a transducer device that converts energy to linear motion. When a coil is lit by an electric current, an electromagnetic force will appear and pull the iron in the center of the coil linearly.

METHODOLOGY RESEARCH
The method in designing the smart lock prototype is the Research and Development (RnD) method. The development model used is the ADDIE model consisting of Analysis, Design, Development, Implementation, and Evaluation [15]. The procedure in this study can be described in Figure 5.  Figure 5, each stage can be explained as follows. The first step is to find out the field conditions, the researchers make observations and study literature. The analysis conducted by the researcher is the gap between the existing problems in the field and the data released by the Central Statistics Agency, instructional objectives, targeted objectives, strategies and solutions provided, and finally compiling program plans based on the objectives to be addressed.
To look for gaps in problems, researchers first looked for problems through literature studies by looking at statistical data relating to theft rates that occurred in Indonesia through data released by the Central Statistics Agency based on data from 2018. The data says that the theft rate which occurred in Indonesia during 2018 was in the range of 11.42 -73.76 percent in each of the provinces. After obtaining the data, the researchers made observations at Permata Balaraja housing estate and found that the security installed in each house still uses ordinary house keys. If there is theft in the house, there is no special notification to the owner of the house if there is a theft or someone other than the owner of the house who entered the house.

Design
The design created is the initial stage as the design of the smart lock prototype. Researchers hope that with this tool, the existing security system will be better so that it can reduce theft rates. The following is the design used in the Prototype Smart Lock Based on the Internet of Things (IoT) With ESP8266.

Wiring Prototype Diagram
The wiring diagram of the prototype smart lock was created using fritzing software. This wiring diagram is used to illustrate the sequence before it is assembled into a complete tool. In this fritzing software the researcher must prepare some material in the form of a library of several components that will be used because when installing the initial application, the library of components is not so complete that they must download several component libraries again. Figure 6 shows the components used in this prototype. There are 3 parts to this wiring diagram, namely the input part, the process part, and the output section. On the input, there is a PIR sensor which is used to activate or operate the solenoid lock from inside the house. In addition to operating the solenoid lock, the PIR sensor is also used to detect strangers entering the house when the house is empty.

Development
In this research, the development process carried out in the form of designing a model house and designing a prototype smart lock based on IoT with ESP8266 which includes:

Prototype House
In the design of a house model to test the prototype smart lock, the material used is a 12mm thick plywood with a length of 1.22m and a width of 2.44m. The design phase of the house model can be described as follows: Measurement on plywood boards, Plywood board cutting, Plywood board smoothing and Assembling a model house.

Smart Lock
In designing the smart lock prototype which consists of several components such as Wemos D1 R1 as the processor or brain of the device, PIR sensor as Input Hardware, Solenoid Lock and Buzzer as Output, and smartphone used to control the prototype remotely. The design stages of Prototype Smart lock with ESP8266 will be explained in Figure 8.  Figure 8, which consists of sensors and Blynk applications as input, solenoid lock and buzzer as output. The first step is to define the pin as input or output. When the pin has been defined, the program will call several files in the form of a library, then connect the Wemos D1 R1 board with the Blynk application.
Researchers use 8 pins for input and output circuits. 3 pins for input and 5 pins for output. In addition to using input/output with hardware, researchers also use smartphones that have been mediated with the Blynk application. In this application, the researcher uses 2 buttons to give commands to solenoid lock 1 and solenoid lock 2. The 3 input pins are connected to the PIR sensor. PIR Sensor 1 is used to control solenoid 1, PIR Sensor 2 is used to control solenoid 2, and PIR Sensor 3 is used to control the buzzer.
The output used by researchers is only 3, but researchers use 5 pins for output, where 3 output pins receive commands from the PIR Sensor, while the other 2 output pins get commands from the Blynk application. The PIR sensor issues a signal in the form of a digital signal taken from the pin of the Wemos D1 R1 board while the Blynk application issues a command in the form of a virtual signal that does not use a pin on the Wemos D1 R1 board. Each component is mounted according to the pin used on the Wemos D1 R1 board. The PIR sensor uses pins D3, D4 and D7. As for the relay pins connected to the solenoid and buzzer are pinned D5, D6, D9, D2, and D10. PIR 1 on pin D3 is connected to pin D2 as relay 1. Pin D4 as PIR 2 is connected to pin D5 as relay 2, and pin D7 is connected to pin D6 as relay 3. For relays 1 and 2 connected to solenoid lock 1 and 2, while for relay 3 it is connected to the buzzer. D9 and D10 pins are used as relays 4 and 5 which are connected to the solenoid as well, but the commands obtained by these relays are commands from smartphones with the Blynk application.
This pin set is performed on the Arduino IDE software where the language used is C language which is uploaded to the Wemos D1 R1 board using a USB cable. In this Arduino IDE, the uploaded program consists of the head of the program, the variable initiation or setup section, and the main part of the program or loop. This program head contains variables that will be used in the main program and also to add the program files needed.
The head of this program contains the files needed or also known as libraries. In addition to the library, researchers also included several components used in this program. One of them is information about tokens, Wi-Fi SSID and Wi-Fi Password. This token is the address used to connect hardware with the Blynk application. This token is obtained from the Blynk application by sending it to the user's email. Meanwhile, the SSID and Wi-Fi Password are used to connect the hardware to the Wi-Fi that is being used. Because the device that will be developed will be operated with an internet connection and therefore requires a Wi-Fi address that is used. Also, the head of the program contains information about the pins used and their names. Because this program uses the PIR sensor as its input, then the last time function is also added to the head of the program so that when the object does not hit the sensor again the output will turn off automatically.
In the second part, there is a setup that is used to initiate or name variables used in this program. The initiation in question is to give a name and make what the pins are on the pins used in the program. As an example of LED1 which in the program section is pin D5 as output. After the setup section, there is a loop section where this section is the most important part of the program. In this loop section, several functions are used, including the IF, ELSE and ELSE IF functions. The IF-ELSE function is used to compare variables with logical conditions. For example, if the variable has a value of 1, then statement 1 will be executed, but if not, then statement 2 will be executed.

Switch Design in Blynk Applications
In this Blynk application (Figure 9), researchers use 2 switch buttons that are used to change the state of outputs 1 and 2 via a Wi-Fi connection. In addition to using Wi-Fi, this application also provides a token code that is used to connect hardware devices (Board Wemos D1 R1) with the Blynk application. Figure 9 is the appearance of the Blynk application used.

Implementation
The implementation phase is carried out after the product has been evaluated and approved by the product expert. Researchers conduct product performance testing to determine the performance of each component. Components tested include D1 R1 Wemos board, PIR sensor, solenoid lock, and battery batteries. The results of testing the components used in the smart lock prototype can be seen in the results and discussion.

Evaluate
This evaluation stage is the stage where the authors see the feasibility of the product that has been developed to be used after passing the evaluation process. The evaluation process was carried out by three evaluators who were product experts. This evaluator consisted of 2 lecturers in the Electrical Engineering Vocational Education Study Program UNTIRTA and one teacher at SMK 1 Cikande.
The assessment conducted by this product expert is in the form of eligibility as seen from three aspects, namely the quality aspect, the technical aspect, and the benefit aspect. This evaluation process is carried out after the implementation process is completed. This assessment was carried out in the UNTIRTA Vocational Electrical Engineering Education lab and workshop majoring in Industrial Electronics at SMKN 1 Cikande.
This evaluation process is carried out to determine the level of product viability so that the product that has been developed can be marketed and used by many people. This evaluation was carried out using a questionnaire containing 20 statements with 4 rating scales, ranging from strongly agree to strongly disagree. Suggestions that have been obtained from product experts are collected and processed to determine the feasibility of the products that have been developed.

RESULT AND DISCUSSION 4.1 Result
The results and discussion that will be presented in this study are the results of testing of each component used in this smart lock prototype. Components tested are Wemos D1 R1, PIR Sensor, Solenoid Lock, and Battery batteries.

Testing Result Wemos D1 R1
Wemos D1 R1 testing is by testing each pin contained on this board. There are 25 pins on this board. After testing, 2 pins cannot work properly. A pin that has a breakdown or error cannot execute the command to the maximum so that makes the controlled output work irregularly. Table 1  Based on Table 1, from the 25 pins owned by the W1 D1 R1 board, researchers used 10 pins as input/output. It is estimated that 2 input/output pins cannot be used. This Wemos. The maximum voltage that can be received by this board is 5V.

Testing Result Sensor PIR
PIR sensor testing aims to determine the maximum radius of the sensor. PIR sensors work by detecting infrared waves emitted by living things. PIR sensor on the smart lock is used to open/close the lock from inside the house so that homeowners do not need to use their smartphone to open/close the house key. Based on the testing that has been done, Table 2 is obtained. Based on Table 2, the PIR sensor works well because each indicator that is tested matches the datasheet. In addition to opening/closing the lock, the PIR sensor here is also used as a detector for strangers entering the house when the house is empty. When a stranger enters the house the sensor will detect it and give notification to the homeowner via e-mail and activate the buzzer that is installed outside the house.

Testing Result Solenoid Lock
A solenoid lock is used as a door lock. As explained in the theoretical study, the solenoid lock consists of a tightly wound coil of cable. Solenoid works when it gets voltage. The voltage required by a solenoid is 12V. Table 3 are the results of tests on the solenoid lock. Output Voltage (V) 12V Based on the data in Table 3, the solenoid lock works well. The applied voltage is 15V because there are 2 solenoids used in this prototype.

Testing Result Battery
The battery used is a dry battery which has a capacity of 12.4V. This battery is used to be a backup source when the main power source goes out. Table 4 are the results of battery testing.  Table  4, the battery that becomes the source when the prototype is on standby for 7 hours does not experience a significant voltage drop. This proves that the battery can work well as a backup source when the main power source is off. Based on the results of overall component testing, it can be concluded that the prototype smart lock can work well so that it can be implemented in an actual home.

Smart Lock Prototype Work System
This smart lock prototype is equipped with a solenoid lock as a lock (Output) and PIR sensor as an input. In addition to the PIR sensor, this prototype smart lock can also be controlled remotely using a smartphone. This smart lock prototype can work using an internet connection. This is what makes this smart lock can be accessed from anywhere and anytime using a smartphone.
The smartphone used to access this house key is a smartphone that has the Blynk app installed. This application is a user interface that has a widget in the form of buttons that can be used to control any output. Also in this application features a widget that allows researchers to give notifications to users. Researchers use the notification widget via e-mail when a stranger enters the house. Messages delivered to homeowners can be set according to the user's wishes.
In addition to using a smartphone, users can also use PIR sensors to unlock when inside the house. So that homeowners do not have trouble when they want to open the door lock when they are in the house. When the householder approaches the door within the sensor radius, the house key in the form of a solenoid lock will open automatically.
The PIR sensor here is not only used to open/close the jar but is also used to detect strangers entering the house. When the house is in an unoccupied condition, the homeowner can activate the 'burglar mode' to activate the PIR sensor which is connected to the buzzer as output. So when there are strangers detected through the PIR sensor, the PIR sensor will activate the buzzer as an alarm to get around the house and provide notification to the user via e-mail.

Discussion
The safety system is an important thing that must be installed inside the house. This can reduce the possibility of theft that will occur inside the house. Smart Lock prototype developed aims to reduce the crime rate in the form of theft that occurs in the home. This prototype is equipped with a Wemos D1 R1 board which is the brain in this system and is equipped with a Wi-Fi module that allows the board to be connected to the internet. On the input/output, there is a PIR sensor and a solenoid lock. PIR sensor is used to open/close the lock when the homeowner is inside the house. Also, the PIR sensor is also used to detect strangers who enter the house when the house is empty and will provide immediate notice around the house and homeowner. Notification obtained for around the house is an alarm generated by a buzzer mounted on the outside wall of the house. Whereas notification to homeowners is in the form of e-mail received by homeowners when a stranger enters the house.
Based on the test results in Table 1, two pins cannot be used as input/output. This is due to the researcher's error when entering the voltage in the circuit. In this system, the researchers used 3 pins as input and 5 pins as output. From a total of 15 input/output pins found on the Wemos board, only 8 pins are used by researchers. This makes it possible to add the output or input you want to use in the house. Table 2 is a table of test results on the PIR sensor. The testing process is done by measuring the maximum radius that can be reached by the sensor that has been set for use on this prototype. Based on the data in Table  II, the PIR sensor can work with an input voltage of 5V and the radius used on this prototype is 90cm.
The data presented in Table 3 is data that is owned by a solenoid lock. Testing on the solenoid lock aims to determine the voltage used in this component. Based on the data in Table III, the solenoid lock can work with an input voltage of 12V and under product specifications. Based on research conducted by Arafat [9]. the solenoid lock will be locked when it does not get voltage, this makes the house cannot open when it does not get the main voltage. Therefore, we need a backup voltage source to overcome this problem In Table 4 researchers get the test results on the battery. This battery testing aims to determine the maximum ability of the battery to become the main source of the system when the main power source is being extinguished. Researchers conducted tests for 7 hours with the system in standby and got stable results. This allows the battery to survive as a backup source for operating the system.
After testing each component, the researcher tests the whole system. Based on the test results, the component can work well and in accordance with the instructions given by the researcher. All of these commands are programmed in the Wemos D1 R1 board. Figure 10 is the final products that have been installed in the model house.

CONCLUSION
Based on testing that has been done regarding the design of prototype smart locks based on the internet of things with ESP8266, that this research succeeded in designing automatic home security that can be controlled remotely using a smartphone. In the component testing that has been done, the result is that each component works very well and according to the specifications given by the manufacturer in the datasheet of each component. Based on the testing of each component used, the results are obtained in the form of PIR sensor readings with a radius of 90 cm with an angle of 120o with a voltage of 5V, a solenoid lock that uses a 12V voltage, a pin from the W1 D1 R1 board that has errors on its 2 input/output pins, and a battery that can be used as a backup power source when the main power source goes out for more than 5 hours.