0% found this document useful (0 votes)
16 views15 pages

Day Se La Report Cuoi Cung

This document outlines the design and implementation of a smart door system utilizing the ESP32 microcontroller for secure access control. The system integrates biometric authentication through an AS608 fingerprint sensor, a keypad for PIN entry, and remote management via the Blynk platform, ensuring robust security and user-friendly operation. Experimental results indicate reliable performance with quick unlocking and secure data transmission, presenting a scalable solution for modern access control needs.

Uploaded by

nhatmoon71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views15 pages

Day Se La Report Cuoi Cung

This document outlines the design and implementation of a smart door system utilizing the ESP32 microcontroller for secure access control. The system integrates biometric authentication through an AS608 fingerprint sensor, a keypad for PIN entry, and remote management via the Blynk platform, ensuring robust security and user-friendly operation. Experimental results indicate reliable performance with quick unlocking and secure data transmission, presenting a scalable solution for modern access control needs.

Uploaded by

nhatmoon71
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Design and Implementation of a Smart Door System Using

ESP32 for Secure Access Control

Nguyen Thanh Dien (DienNT)


Lecturer, Software Engineering Faculty, FPT University HCMC
[email protected]
Phung The Quan (SE193519) [Leader]
Student, Software Engineering Faculty, FPT University HCMC
[email protected]
Nguyen Thi Thu Huyen (SE182418)
Student, Software Engineering Faculty, FPT University HCMC
[email protected]
Mai Nhat Minh (SE190302)
Student, Software Engineering Faculty, FPT University HCMC
[email protected]
May 2, 2025

Group: 8
Subject Name: Internet of Things Applications (IOT102)
Class ID: IOT102 3W 04

1
Contents
1 Introduction 3

2 Hardware Components 3
2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 ESP32 Microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 AS608 Fingerprint Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 Keypad 4x4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.5 LCD Display With I2C Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 MG995 Servo Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.7 HC-SR501 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.8 330uF Electrolytic Capacitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 Circuit Design 8

4 Software Architecture 9
4.1 Design Choices and Rationale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

5 System Data Flow Analysis 9


5.1 Setup Phase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5.2 Loop() function on core 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
5.3 Reading data from sensors on core 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

6 Conclusion 15

2
Abstract
This paper presents a smart lock system designed to enhance residential security through IoT-
enabled access control, leveraging the ESP32 microcontroller. The system integrates the AS608
fingerprint sensor for biometric authentication, a keypad for PIN-based access, and the Blynk
platform for remote user interaction via a mobile application. Users can register fingerprints
with associated names, monitor lock status, and control access remotely, ensuring a seamless
and secure experience. The system utilizes Wi-Fi for real-time communication with Blynk. Key
features include robust security through biometric and PIN verification, and user-friendly remote
management. Experimental results demonstrate reliable unlocking with sub-second latency, and
secure data transmission. The proposed smart lock offers a cost-effective, scalable solution for
modern access control, with potential for future enhancements such as advanced encryption and
offline functionality.

1 Introduction
The Internet of Things (IoT) encompasses a network of interconnected physical objects—devices,
vehicles, appliances, and buildings—embedded with electronics, sensors, software, and network con-
nectivity, enabling seamless data collection and exchange [GBB18]. By leveraging existing network in-
frastructure, IoT facilitates remote sensing and control, fostering direct integration of physical systems
with digital platforms. This convergence enhances operational efficiency, accuracy, and automation
across diverse applications, from smart homes to industrial systems.
The advent of low-cost, powerful microcontrollers, such as the ESP32, ESP8266, and Arduino,
has revolutionized traditional household devices, transforming them into intelligent systems that of-
fer enhanced user experiences. Among these innovations, smart locks have emerged as a significant
advancement, replacing conventional mechanical locks with IoT-enabled solutions. Unlike traditional
locks, smart locks provide keyless entry, remote access control, and robust security features, effectively
mitigating unauthorized access to personal property. However, challenges such as cost, power efficiency,
and secure communication remain critical in designing affordable and reliable smart lock systems.
This paper presents the design and implementation of a smart lock system based on the ESP32
microcontroller, leveraging its dual-core processing and integrated Wi-Fi capabilities for real-time
access control. The proposed system aims to deliver a cost-effective, secure, and user-friendly solution
for residential security, integrating a mobile application for remote operation and MQTT for efficient
communication. The project addresses key IoT challenges, including low-power operation and secure
data transmission, while offering a scalable framework for future enhancements.

2 Hardware Components
2.1 Overview
Based on the block diagram presented in fig. 1, this IoT system constitutes a comprehensive smart
lock solution with both local and remote access capabilities. The system integrates hardware com-
ponents, microcontroller-based processing, and cloud connectivity to deliver a robust security access
system.
The solution utilizes an ESP-WROOM-32 microcontroller as the central processing unit, which
interfaces with several input/output components. For authentication, the system incorporates dual
access methods: a traditional 4×4 membrane keypad for PIN entry and an AS608 fingerprint sensor
for biometric verification.
User interaction is facilitated through an LCD monitor that displays system status, authentication
results, and operational messages. When access is granted, a servo motor is activated to physically
unlock the door mechanism.
What makes this a true IoT solution is the cloud connectivity layer. The Blynk Cloud Server
acts as the intermediary between the local hardware and remote user interfaces. This allows users
to interact with the system through both mobile applications (iOS/Android) and web applications.
These remote interfaces enable users to:

• Monitor the lock status in real-time

3
Figure 1: Block diagram.

• Grant or revoke access remotely


• Receive notifications about access attempts
• View access logs and history

The bidirectional communication between the ESP-WROOM-32 and Blynk Cloud Server ensures
that commands from mobile/web applications are executed by the hardware components, while sensor
and status data from the hardware are transmitted back to the cloud for user monitoring.
This integrated approach provides a flexible, secure access control system that combines the relia-
bility of local hardware authentication with the convenience of remote management through modern
digital interfaces.

2.2 ESP32 Microcontroller

Figure 2: ESP32 Dev Module.

ESP32 microcontroller (fig. 2), used in the smart lock system, offers robust performance from -40
° C to +125 ° C, with reliability calibration. It features ultra-low power consumption via proprietary
software and power modes, ideal for IoT applications. Highly integrated, includes antenna switches,
RF balun, amplifiers, and power management, reducing PCB complexity. Its hybrid Wi-Fi and Blue-
tooth capabilities enable standalone or slave operation, interfacing via SPI/SDIO or I2C/UART for

4
Table 1: AS608 Fingerprint Sensor Specifications

Parameter Specification Details


Value Unit
Operating Voltage 3.6 - 6.0 V DC
Current Consumption <120 mA
Backlight Green -
Baud Ratea 9600 - 57600 bps
Security Levels 1-5 -
FARb <0.001 %
FRRc <1.0 %
Storage Capacity 127 templates

a
Default: 57600 bps.
b
FAR: False Acceptance Rate (at level 3).
c
FRR: False Rejection Rate (at level 3).

(a) AS608 fingerprint sensor (b) Keypad 4x4 membrane keypad

Figure 3: I/O Devices enables communication between users and device

efficient wireless connectivity[Esp].

2.3 AS608 Fingerprint Sensor


The AS608 fingerprint sensor (fig. 3a) uses UART TTL or USB communication to interface with
microcontrollers or connect directly to a computer (via a USB-to-UART converter or USB interface).
Moreover, the sensor comes with a built-in fingerprint recognition processor. It automatically
converts the scanned fingerprint into a data string and sends it through the UART interface. Therefore,
there is no need for image processing operations. You simply send commands to read, write, or compare
fingerprint data, making it very easy to use and program.
Detail specifications are shown in Table table 1

2.4 Keypad 4x4


The keypad is composed of a group of buttons arranged in the matrix (rows and columns). A
button represents for a key.

5
(a) LCD Monitor (b) I2C Module

Figure 4: This combination simplify and improve developer’s coding experience

In this project, a 4x4 keypad will be used since it is used and sold widely. A 4x4 keypad consists
of 4 rows and 4 columns. Switches are placed between the rows and columns.

2.5 LCD Display With I2C Module


I2C (Inter-Integrated Circuit, fig. 4b) is a serial communication protocol that uses two lines: a
serial clock pin (SCL) for timing and a serial data pin (SDA) for transferring data. In an I2C system,
a single controller device communicates with one or more peripheral devices, each having a unique
address.
Communication occurs as the controller sends data bit by bit over the SDA line, synchronized
with clock pulses on the SCL line. Devices take turns transmitting data, allowing the controller to
communicate with multiple devices using just two pins. This protocol is efficient for connecting various
devices like sensors or other microcontrollers to an Arduino board [Gee], [Ard].
One common application of I2C is interfacing with an LCD (Liquid Crystal Display), such as a 16x2
character display. Traditional LCDs require multiple digital I/O pins to control, typically involving
6–8 connections for data and control signals. However, by using an I2C backpack module—an add-on
circuit that connects directly to the LCD—these displays can be controlled with just two wires (SDA
and SCL), dramatically simplifying the wiring and freeing up valuable I/O pins on the microcontroller.
Using an I2C-connected LCD is especially advantageous in embedded systems with limited pin
availability. Libraries such as LiquidCrystal I2C in Arduino provide user-friendly functions to initialize
the display, control cursor behavior, and print text, making I2C LCDs ideal for displaying sensor values,
menus, or debugging information in compact projects.

2.6 MG995 Servo Motor


The Futaba MG995 as shown in fig. 5 is a popular standard servo motor used in robotics and
hobbyist applications, known for its size, strength, and affordability. It operates at 4.8V to 7.2V and
delivers a torque of 10 to 15 kg/cm. The motor speed is around 0.20 to 0.25 seconds per 60 degrees
of rotation, with a standard 180-degree operating angle. Controlled by a PWM signal, the MG995
provides precise rotation control but lacks position feedback. It comes with a three-wire connector for
power (VCC), ground (GND), and control (signal). Commonly used in robotics, RC vehicles, model
airplanes, and animatronics, the MG995 features plastic housing and gears with a brushed DC motor
mechanism [All].

6
Figure 5: MG995 Servo Motor.

2.7 HC-SR501
The HC-SR501, as shown in fig. 6, is a low-cost, widely used PIR (Passive Infrared) motion sensor
module designed to detect motion by sensing changes in infrared radiation emitted by warm bodies
like humans or animals. Operating on 4.5V–20V DC, it offers a detection range of 3 to 7 meters with a
120° field of view. The sensor provides a digital output (HIGH when motion is detected) and features
adjustable sensitivity and delay time. It supports two trigger modes—single and repeat—for flexible
use in automation or security systems [?].

Figure 6: HC-SR501 PIR Motion Sensor

2.8 330uF Electrolytic Capacitor


A critical but often overlooked component in the smart door lock system is the 330uF electrolytic
capacitor, which plays an essential role in stabilizing power delivery to the MG995 servo motor. The
servo motor experiences significant current spikes during operation, particularly at the moment of
activation when the door lock mechanism engages or disengages. These sudden demands for current
can cause voltage drops in the power supply, potentially affecting the operation of sensitive components
like the ESP32 microcontroller and the fingerprint sensor.
The 330F capacitor functions as a local energy reservoir, supplying additional current during these
transient high-demand periods. When the servo motor activates, drawing a momentary surge current
that can reach up to 1A, the capacitor discharges to supplement the power supply, preventing the
system voltage from dropping below critical thresholds. This stabilization is particularly important as
voltage sags can cause several undesirable effects:

• ESP32 brownouts or unexpected resets during critical authentication operations

7
• Corruption of data being written to flash memory
• Interruption of wireless connectivity during security event transmission
• Incomplete servo motor rotations resulting in partial locking/unlocking
• Wires melting and unstable energy discharge.
The capacitor value of 330uF was selected as an optimal balance between adequate energy storage
and physical size constraints. While smaller values proved insufficient to handle the servo current
demands in testing, larger values did not provide significant additional benefits to justify their increased
footprint on the circuit board.
During system operation, the capacitor charges when the servo is inactive and discharges when
needed, creating a more stable power environment throughout the entire circuit. This implementation
detail, while simple, significantly enhances the reliability of the door lock mechanism—an essential
consideration for security applications where consistent operation is paramount.

Figure 7: Electrolytic Capacitor

3 Circuit Design
The table 2 and table 3 provide a comprehensive overview of the biometric access control system’s
hardware implementation. table 2 details all essential components with their respective pin configura-
tions and power sources, showing how the ESP32-WROOM-32 microcontroller forms the central hub
of the system, with various peripherals requiring different power levels (3.3V for the AS608 fingerprint
sensor and VIN for most other components including the LCD display, servomotor, and motion sensor).
table 3 illustrates the data connection architecture, mapping each connection point from the ESP32
to its corresponding peripheral component.
The simulated diagram can be found in fig. 8. This circuit implements a biometric access control
system with the following features:
• Primary authentication via fingerprint verification using the AS608 sensor
• Secondary authentication through PIN code entry on a 4×4 keypad
• User feedback via a 16×2 character LCD display with I2C interface
• Physical access control using a MG995 servo motor
• Motion detection for improving users’ experience HC-SR501 sensor
• Power stability and brief backup power provided by a large capacity electrolytic capacitor
The ESP32 microcontroller serves as the central processing unit, handling all authentication logic,
sensor input processing, display control, and output actuation.

8
Component Pins Power Source
ESP32-WROOM-32 EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, External Power
D14, D12, D13, GND, VIN, 3V3, D15, D2, D4, RX2,
TX2, D5, D18, D19, D21, RXD, TXO, D22, D23
AS608 Fingerprint Sensor VCC, TX, GND, RX ESP32 3.3V
LCD 16x2 (I2C) GND, VCC, SDA, SCL ESP32 VIN
4x4 Keypad R1, R2, R3, R4, C1, C2, C3, C4 N/A (Digital I/O
only)
HC-SR501 Motion Sensor GND, OUT, VCC ESP32 VIN
Servomotor MG995 SIG, VCC, GND ESP32 VIN
Electrolytic Capacitor -, + ESP32 VIN (con-
nected to +)

Table 2: Components of the access control system

From To
ESP32 RX2 AS608 TX
ESP32 TX2 AS608 RX
ESP32 D22 LCD SCL
ESP32 D21 LCD SDA
ESP32 D14 Keypad R1
ESP32 D27 Keypad R2
ESP32 D26 Keypad R3
ESP32 D25 Keypad R4
ESP32 D33 Keypad C1
ESP32 D32 Keypad C2
ESP32 D18 Keypad C3
ESP32 D19 Keypad C4
ESP32 D13 Servomotor SIG
HC-SR501 OUT ESP32 D4

Table 3: Data connections between components

4 Software Architecture
4.1 Design Choices and Rationale
• PlatformIO: Chosen for its robust library support, integrated debugging tools, and compati-
bility with the ESP32. It reduces development time compared to the Arduino IDE and supports
version control integration.
• Blynk is chosen as the intermediate platform, allows users to communicate with their devices in
real-time. Blynk has a packaged solution called BlynkEdgent which provide a comprehensive
IoT connectivity solution. This package delivers secure device-cloud communication, streamlined
credential provisioning over WiFi/BLE via Blynk.Inject, and OTA firmware updates through
Blynk.Air. The implementation features RGB LED status indication and button-based config-
uration reset. By adopting this solution, we eliminated custom IoT connectivity development
needs, focusing instead on core smart lock functionality while maintaining security and reliability
standards for our fingerprint-based access system[Bly].
• Preferences: The Preferences library is utilized to store and retrieve critical configuration data
in the ESP32’s non-volatile storage (NVS), ensuring settings persist across power cycles.

5 System Data Flow Analysis


This section presents the data flow architecture of the ESP32-based smart door system, following
a sequential processing model. The program consists of 2 different phases, beginning with the phase

9
Figure 8: Circuit diagram.

of setting up, then repetively executing the loop() function on default core (core 1) and reading data
from sensors on another core (core 0) repetively.

5.1 Setup Phase


The initialization process illustrated in fig. 9 demonstrates a multi-core embedded system startup
sequence. Core 1 manages the following sequential operations:

1. Initialize global variables for system-wide use

2. Initialize sensor and peripheral modules and loading configuration stored in flash memory.
3. Set up Blynk Edgent for IoT connectivity
4. Initialize tasks to be executed on the secondary core

Following initialization, the system branches into parallel execution paths:


• Core 1 continuously executes a loop() function

• Core 0 handles designated tasks independently


Both cores interact through shared global variables, enabling inter-core communication while main-
taining separate execution responsibilities.

5.2 Loop() function on core 1


After initialization, the system enters its main operational loop on Core 1, as illustrated in fig. 10.
This continuous execution cycle handles real-time communication with the Blynk IoT platform and
processes user requests.
The loop() function performs the following operations:

1. Maintains Blynk Edgent and WiFi communication to ensure consistent connectivity


2. Polls for incoming requests from Virtual Pin interfaces in the Blynk application
3. Processes three types of user requests:

• Door opening requests: When detected, activates a servo motor to rotate and unlock the
door
• PIN modification requests: Updates security credentials by changing the PIN code and
persisting it in flash memory

10
Figure 9: Door’s setup phase.

• Fingerprint deletion requests: Removes specified fingerprint IDs from the system database
This continuous monitoring and response system enables the smart lock to respond promptly to
user commands while maintaining secure access control. The loop executes indefinitely, returning to
the beginning after completing each cycle or when no actionable requests are detected.

5.3 Reading data from sensors on core 0


The flowchart in fig. 11 depicts a comprehensive control system for a smart door lock after the
initialization of the input task on core 0:

1. Task Start: The entry point of the task.

2. Initialize Local Variables: System sets up all variables needed for operation including timers,
counters, and status flags.
3. Loop Start: The beginning of the main operational loop that continuously monitors and controls
the door lock.

4. Lockout Mode Check: System checks if it’s currently in lockout mode (high security state).
• If YES: Displays remaining lockout time on LCD and continues to status display.
• If NO: Proceeds to auto lock mode check.
5. Auto Lock Mode Check: Determines if auto-locking feature is enabled.

• If YES: Proceeds to motion detection.


• If NO: Skips to failed attempts check.
6. Motion Detection: When in auto lock mode, checks for motion near the door.
• If motion detected: Resets the auto-lock timer (postpones locking).

11
Figure 10: loop() function flow on core 1.

12
Figure 11: Core 0 Flowchart.

13
• If no motion: Checks if timer has expired.
7. Timer Expiration Check: Determines if the auto-lock countdown has completed.
• If not expired: Displays remaining time before auto-lock.
• If expired: Activates servo to physically close and lock the door.

8. Failed Attempts Check: Examines if there have been previous failed authentication attempts.
• If YES: Checks if 2 minutes have passed since last failed attempt.
• If NO: Proceeds to door lock status check.
9. Time Since Failed Attempt: Determines if the cooling period after failed attempts has passed.

• If 2+ minutes passed: Resets the failed attempts counter.


• If less than 2 minutes: Keeps the counter intact.
10. Door Lock Status Check: Determines if the door is currently locked.
• If locked: Proceeds to authentication processing.
• If unlocked: Returns to loop start.
11. Keypad Processing: Monitors and processes input from the numeric keypad.
• If data received: Proceeds to PIN verification.
• If no data: Moves to fingerprint processing.

12. PIN Verification: Compares entered PIN with stored credentials.


• If matched: Logs event to Blynk cloud and unlocks the door.
• If not matched: Increments failed PIN attempts counter.

13. PIN Failure Limit Check: Determines if maximum PIN failures have been reached.
• If 3 failures: Activates lockdown mode and sends alarm to Blynk.
• If less than 3: Returns to the loop to allow further attempts.
14. Fingerprint Processing: Monitors and processes input from the AS608 fingerprint sensor.

• If data received: Proceeds to fingerprint matching.


• If no data: Returns to loop start.
15. Fingerprint Matching: Compares scanned fingerprint with stored templates.
• If matched: Logs event to Blynk cloud and unlocks the door.
• If not matched: Increments failed fingerprint attempts counter.
16. Fingerprint Failure Limit Check: Determines if maximum fingerprint failures have been
reached.
• If 5 failures: Returns to the system status display (likely with warnings).
• If less than 5: Returns to the loop to allow further attempts.
17. Status Display: Throughout all operations, current system status is continuously displayed on
the LCD screen for user feedback.

14
6 Conclusion
This paper presented the successful design and implementation of a smart door lock system using
the ESP32 microcontroller as its central processing unit. The system effectively integrates multiple
authentication methods, including biometric verification through the AS608 fingerprint sensor and
PIN-based access via a 4×4 keypad, providing layered security while maintaining user convenience.
By utilizing the ESP32’s dual-core architecture, the system achieves efficient task distribution, with
core 0 handling sensor data processing and access control logic while core 1 manages cloud connectivity
and user interface operations.
The implementation of a comprehensive security protocol with graduated response to authentication
failures demonstrates the system’s robust design. Features such as automatic lockdown after multiple
failed attempts, auto-locking functionality with motion detection override, and remote management
capabilities through the Blynk platform collectively create a secure yet flexible access control solution.
The real-time feedback through the LCD display enhances the user experience by providing clear status
information and authentication results.
Throughout development, several technical challenges were addressed, including efficient power
management, secure data transmission between the device and cloud platform, and reliable physical
actuation through the servo motor mechanism. The system’s modular software architecture facilitates
future enhancements and customizations without requiring substantial redesign of the core function-
ality.
Future work could focus on implementing more advanced security features such as two-factor au-
thentication, expanding the system’s offline capabilities during network outages, and incorporating
additional sensors for environmental monitoring. Integration with broader smart home ecosystems
would further extend the system’s utility and convenience.
In conclusion, the ESP32-based smart door lock system represents a viable alternative to commer-
cial solutions, offering comparable security features at a fraction of the cost. The project demonstrates
how IoT technologies can be leveraged to enhance residential security while providing the flexibility
and convenience expected in modern smart home applications.

References
[All] AllDataSheet. AllDataSheet. https://www.alldatasheet.com/datasheet-pdf/pdf/
1132435/ETC2/MG995.html. [Online; accessed Apr. 22, 2025].
[Ard] Arduino. Inter-Integrated Circuit (I2C) Protocol. https://www.arduino.cc/en/
Reference/Wire. [Online; accessed Apr. 20, 2025].

[Bly] Blynk. Blynk.Edgent. https://docs.blynk.io/en/blynk.edgent. [Online; accessed Apr.


22, 2025].
[Esp] Espressif. Espressif. https://www.espressif.com. [Online; accessed Apr. 19, 2025].
[GBB18] Pradyumna Gokhale, Omkar Bhat, and Sagar Bhat. Introduction to iot. International
Advanced Research Journal in Science, Engineering and Technology, 5(1), 2018.

[Gee] GeeksforGeeks. I2C Communication Protocol. https://www.geeksforgeeks.org/


i2c-communication-protocol/. [Online; accessed Apr. 20, 2025].

15

You might also like