Design and Build a Home Security System based on an ESP32 Cam Microcontroller with Telegram Notification

— Along with the times and technology, the need for fast information is needed in various sectors of life, thus supporting the performance of these sectors, one of which is the security aspect, especially in security at home, considering that there are many things that happen such as crimes and negligence of residents of the house that can cause problems such as fires. In this case, a system is needed that can visually monitor the condition of the room from remote location. This is useful for the surveillance process so that if there is a crime and fire in the surveillance room, the system can monitor the state of a room via a smartphone. This study aims to create a device that is able to increase the security of the room at home by utilizing the Esp32 cam as a microcontroller and the PIR sensor as a detector of movement when crossing the corner area of the sensor and also the Fire sensor key as a detector of fire. In this study, the ESP32 cam is used as the main brain of the system which will read data from the fire sensor, PIR sensor, and remotely control the door lock and door unlock. The data from the sensor will be sent to the server by Esp32 cam. The test results have been running in accordance with the designed system. So that pictures taken and notifications of fire can be sent to the telegram application with a 100% success percentage.


I. INTRODUCTION
Security has become a very important requirement, especially for security at home, considering that there are many things that happen such as crimes and negligence of residents of the house that can cause problems such as fires. In this case, a system is needed that can visually inform the state of the room from a remote location. This is useful for the surveillance process so that if there is a crime and fire in the surveillance room, the system can inform the state of a room via a smartphone [1] [2]. Camera technology has now become one of the most important technologies as a room monitoring medium. Images present information that can be easily seen by the user. In the field of security, technology in the microcontroller plays an important role for monitoring and controlling [3] [4]. In practice, room monitoring technology already exists, but its application to houses that are often left out by residents has its own challenges, how to make a simple home security device that is able to monitor the state of the room and control the side of the door [3]. There is a microcontroller that can be used in terms of room monitoring is the Esp32 cam. In practice, room monitoring technology already exists, but its application to houses that are often left out by residents has its own challenges, how to make a simple home security device that is able to monitor the room and control the side of the door [4]. Based on these problems, it is necessary to conduct research to create and program a room security monitoring system using Esp32 Cam, where photos from image shooting can be viewed through mobile devices such as laptops and smartphones that are connected to the network so as to increase home security for the owner [5][6] [7]. In carrying out room surveillance and remote control of home security, certain customizations of security devices are needed so that residents of the house can manage home security facilities according to the system designed [8].
II. METHOD This section describes the type of research, research design, system design, preparation of tools and materials, as well as the determination of procedures and parameters for using facilities from "Design of a Home Security System Based on an Esp32 CAM Microcontroller with Telegram Notifications".

A. Research Design
The research design to be carried out in making the system is shown in Fig. 1.
In Fig. 1 the research flowchart can be described the process carried out during the research. Looking for various references to support what the author wants in terms of applying his design based on previous related research theories such as PIR sensors, fire sensors, Esp32 cam microcontrollers, relay modules and telegrams. After the literature study process is complete, it is continued with system planning, at this stage it will be carried out to start activities in planning an overview of the system to be built. The tools and materials needed are AM312 PIR sensor, Fire sensor, Esp32 cam microcontroller, L2596 stepdown module relay modules, solenoids, and for the software needed, namely Arduino IDE, fritzing, and the telegram application on a smartphone to display the results. Then the next process is making a system, where at this stage a program is made such as Arduino programming, and both telegram applications and mechanical tools are made and enter the program on the device to be used, with the hope of getting the desired results. The next stage is to test the system, which will test the tool made as a whole, this test is carried out to find out whether the tool is running according to plan or not. If there are still errors or errors, repairs and re-planning will be carried out. While the data collection process is needed to measure the maximum distance that cannot be accepted by the AM312 PIR sensor, the maximum distance of objects that cannot be accepted by the PIR sensor is 5M, the object distance on the PIR sensor can also affect the delay in the PIR response. Measuring the average delay in sending remote control commands, the remote control can be said to be able to respond to orders with an average delivery delay of 4.0975 Seconds, and the delay in Quality-of-Service Wireshark. For testing the Quality of Service on Delay the value obtained is 0.0597 s. While the block diagram of the system can be illustrated In Fig. 2. In Fig. 2 the block diagram of the system will explain the work process of the system carried out during the study, the description of Figure 2 is as follows: first, the fire sensor as a detector if there is a fire in the room, the program will send a notification in the form of a text message to the user's telegram application. On PIR sensor serves as an active camera trigger if there is a moving object, the camera on the Esp32 cam will take pictures and then send the data to the cloud database [9]. Where the data that has been sent can be monitored remotely in real time on the telegram application. Second, as a remote control on door security can be accessed via the telegram application [10]. Remote control on the door functions to lock the door and unlock the door if for example the occupants of the house are active outside the home and forget to lock the door, then the occupants of the house can lock the door via a smartphone on the telegram application by utilizing the Esp32 cam which is connected to the relay module so that the solenoid can controlled by the occupants of the house via a smartphone [11] [12].

B. Design of am312 pir sensor tool
In the design of the AM312 PIR sensor, the PIR sensor functions to detect movement, the magnetic door switch sensor functions as a switch on the state of the house door, the buzzer as an alarm if the PIR sensor and Magnetic door switch are logic 1 or in a High state. So if there is movement there will be a change in the readings on the sensor. The PIR sensor consists of three legs, namely the Vin pin, the Out pin (Data), and the GND pin, the Magnetic door switch sensor consists of 2 legs namely the Out pin (Data) and the GND pin, and the Buzzer consists of 2 legs, namely the pin pin. Out (Data), and Pin GND.
In Fig. 3 is the design of a PIR sensor device, for a voltage source it requires 5V. where the pin out of the PIR sensor is connected to the GPIO 12 of the microcontroller for data, the Vin pin of the PIR sensor is connected to the 5V VCC on the microcontroller and the ground pin of the PIR sensor is connected to the GND pin of the microcontroller. On the positive (+) buzzer pin connected to the GPIO pin 2 Esp32 cam microcontroller and the negative (-) buzzer pin is connected to the Esp32 cam microcontroller GND pin. The positive (+) magnetic door switch pin is connected to the GPIO 15 pin of the Esp32 cam microcontroller, and the negative (-) buzzer pin is connected to the Esp32 cam microcontroller GND pin [13] [14].  Fig. 4 is a design for door security control. The power supply is obtained from the PLN electricity network and uses a 12v 1a Power Jack adapter as a solenoid voltage source, the negative adapter pin is connected to IN-on the stepdown and also connected to the negative solenoid pin, while the positive pin is connected to the IN+ stepdown pin and is also connected to the relay pin NO. The COM pin on the relay is connected to the positive solenoid pin. The OUT+ stepdown pin is connected to the 5V pin of the microcontroller, while the stepdown module OUT pin is connected to the GND pin of the microcontroller. The VCC pin on the relay is connected to the 3v pin of the microcontroller, the IN pin on the relay is connected to the GPIO PIN 15 of the microcontroller, and the GND pin on the relay is connected to the GND pin on the microcontroller.  Fig. 5 is a design for a Fire Sensor. The power supply obtained from USB to ttl is connected to the laptop as a fire sensor voltage source, the negative adapter pin is connected to the GND pin of the fire sensor and is also connected to the GND pin of the Esp32 cam microcontroller, while the positive adapter pin is connected to the VCC pin of the fire sensor and is also connected to the pin 5V Esp32-cam microcontroller. Pin D0 on the fire sensor is connected to pin 2 on the Esp32 cam microcontroller [15].  Fig. 6 is a design for displaying information messages on Telegram. In Fig. 6, shows the design of the message notification content that is obtained when the homeowner controls the remote control on the Telegram application. Homeowners can also find out the condition of the door of the house that is currently locked or unlocked, and can also find out the state of the surveillance room in real time.

F. Preparation of Tools and Materials
Here are the tools and materials needed as shown in Table  I. III. RESULTS AND DISCUSSION The results of this study begin with the display of the system flowchart. The overall system flowchart of the tool is shown in Fig. 7. from Fig. 7 can be described as follows: When the system is first run Esp32 cam will connect to the wifi network according to the specified network. If it is successfully connected, the system will try to connect with the telegram API key. Furthermore, on the pir sensor if movement is detected, the Esp32 cam will take a picture and send it to the telegram bot application, and on the fire sensor if a fire is detected then the sensor will take data processed by the microcontroller and sent to the telegram application and the telegram application is used to give orders to Esp32 cam in the form of Lock the door, Status, Unlock the door. then if the door lock command then the solenoid on the door will be locked, if the door unlock command then the door solenoid will open, and if the status command will display the status on the telegram application that the door is locked or not locked. While the motion detection circuit of the AM312 PIR sensor, fire sensor and door security remote control with Esp32 cam is illustrated in Fig. 8,  9 and 10.   A. PIR sensor test PIR Sensor Testing aims to determine the delay in the PIR response to the distance of the object and the state of the room during the day and night as a monitoring place. The following are the results obtained during the measurements shown in Table II.  Table 2 shows the results of measurements in room samples taken from differences in the state of the room during the day and night which will be used as security in the room. The results of the PIR sensor test can be said to be able to capture movements that occur during the day and night.

B. Remote Control Test
Remote control testing aims to determine the delay in sending each order for door locks, door unlocks, status, photos on telegram bots. The following are the results obtained during the measurements shown in table III. Delay in shipping options that will be used as security on house and room doors. Remote control can be said to be able to respond to orders with an average delivery delay of 4097 seconds. Figure 3.4 shows an example of the test results for sending remote control on the telegram application.

C. Fire Sensor Test
The Fire sensor test aims to determine the success of sending notifications to Telegram. The following results obtained during the measurements are shown in Table IV.  Table IV shows the results of sending notifications in the form of a fire being detected which will be used as security. The fire sensor can be said to be able to detect the presence of fire in a 3x3M room with a distance of 35cm from the source of the fire on the candle, the rest cannot detect the presence of a fire source in the candle.

D. Telegram Application Implementation Results
In this test it can be concluded that all the menus in the application used can work well and successfully perform each function.

E. Measuring Delay on Wireshark
Delay measurement is carried out to test the quality of the system that is made to have adequate quality or not. Testing is done using Wireshark by looking at the IP of the destination used. Based on the IP obtained later, it will be able to process data for communication that is built from this system. Here is a picture of the delay reading on Wireshark.  Based on the data obtained in Fig. 12, it can be seen the data in the delay Table 5.
From Table 5 it is found that the delay for this system is 0.0597 seconds. based on the existing delay classification, it can be concluded that the average delay is index 4 (very good).

F. Packet Loss Test on WireShark
Packet Loss is the number of packets lost on a packet network caused by collisions, full network capacity, and packet drops caused by the end of TTL (Time to Live) packets. Testing packet loss using a Wireshark software.  Based on the data obtained in Figure 13, it can be seen that the packet loss value is 7%. based on the classification of packet loss in the previous chapter, it is concluded that the packet loss category includes index 2 (medium).

IV. CONCLUSION
The design of the security system uses the Esp32 Cam microcontroller which is connected to the Am312 PIR sensor and the MC-38 magnet sensor, the Ky-026 fire sensor runs very well with an average delay value of 1.37 seconds. Data transmission is transmitted via the internet by utilizing the wifi module on the Esp32 Cam microcontroller. If the smartphone is connected to the internet network, the system can send data to the Telegram application. For testing the Quality of Service on Delay, the average result is 0.0597s in the good category, while for packet loss testing the value obtained is 7.0% including the good category.