Electronic lock scheme design and development

With the improvement of people's quality of life, science and technology are also advancing rapidly, but high-tech thieves also appear in our harmonious society, which makes how to achieve safe an

With the improvement of people's quality of life, science and technology are also advancing rapidly, but high-tech thieves also appear in our harmonious society, which makes how to achieve safe and effective anti-theft attract more and more people's attention. Traditional mechanical locks cannot be greatly and effectively improved due to their structural limitations. Incidents of being pryed are not uncommon. Electronic locks are welcomed by users because of their strong confidentiality, flexibility in use, and high safety factor. . Now there are various electronic locks on the market, such as voice locks, fingerprint locks, computer sensor locks, video alarm locks, etc. After the appearance of these locks, many thieves were successfully shut out, but there are still a small number of criminals with high intelligence who still ignore their existence. The main reason is that the country requires that electronic locks must have a device that can be opened by mechanical methods. The result is that electronic locks cannot reflect the advantages of anti-technological opening. This design idea not only improves the anti-technical opening performance of the electronic lock part, but also Improved the performance of preventing technical opening of the mechanical part.


1. The overall design of the electronic lock

1.1 The structure of the electronic lock


The general structure of an electronic lock is shown in Figure 1. The control part of the electronic lock is composed of input, storage, coding, identification, anti-interference, drive, display and alarm units. Among them, the encoding and discriminating circuit is the core of the entire control section. The power supply is essential for both the control part and the execution part of the electronic lock.


图1图2 电子锁结构与硬件框图

The actuator of the electronic lock generally uses an electromagnet or a micro motor to drive the lock body.


1.2 Design of electronic lock


The electronic code lock uses a single-chip microcomputer as the main control core. The special functions of the single-chip microcomputer (AT89S51) greatly enhance the security performance of the electronic code lock, which can effectively prevent the possibility of multiple attempts to test the password. With the further development of microcontrollers and other smart chips, the anti-theft lock will be intelligent, which will greatly improve the security performance of the lock. This design realizes the prompt function of one-time password input. If the password is not entered correctly, a "di di" alarm sound will be emitted to alert others. At the same time, peripheral equipment can be added to realize remote alarm (such as adding a relay and other equipment can be connected to the owner's phone, so that the owner knows that someone is operating illegally at home and alarms in time). If the password is entered correctly, the door bell of "Ding Dong" will sound. The single-chip microcomputer used in this system has powerful functions that can realize intelligent control to complete the password input, judgment and comparison to perform corresponding unlocking display or alarm functions.


Second, the development process of electronic locks

2.1 Hardware design


The design is composed of six parts: a single-chip microcomputer (AT89S51), a 4×4 determinant keyboard, a seven-segment digital tube, an alarm, a motor drive chip, and a motor.


2.1.1 Hardware design principle structure block diagram The hardware design principle structure block diagram is shown in Figure 2.


2.1.2 The main control device of the single-chip microcomputer is a single-chip microcomputer. AT89S51 is a low-power, high-performance CMOS 8-bit single-chip microcomputer. The chip contains 4k bytes of programmable system Flash read-only program memory. The device adopts ATMEL's high-density, Non-volatile storage technology production, compatible with the standard 8051 instruction system and pins, both online programming (ISP) can also be used for traditional programming.


2.1.3 Selection of various components (chips): (1) This design adopts a 4×4 matrix keyboard with a total of 10 number keys and 6 function keys. 4×4 is used to form 0~9 number keys, confirmation keys F and Modify key C, 10 number keys are used to input password, and the other 6 function keys are: A, B, C, D, E, F. The function of the C key is to clear the previously entered data and re-enter it when the password is entered incorrectly. The function of the F key is to confirm the entered password. (2) The digital tube uses the common cathode 4-in-one digital tube SR420561K. (3) The most common choice for the motor drive chip is the 15-pin Multiwatt package L298N. (4) The interface of the ISP downloader is designed in the circuit, and the ISP-USB download cable is selected. (5) The motor used in the electronic lock needs to be small in size, high in efficiency, and large in starting torque, and the motor in the tape recorder meets this feature. Finally, the selected motor is the recorder motor EG-530AD-6B, the working voltage of the motor is 6V, the speed is 2400 rpm, and the direction is CCW (counterclockwise). (6) Plastic gears are selected for the transmission components here, and the transmission ratio is determined and selected directly from the market. (7) There are no special requirements for the structure and material of the electronic lock body, bolt and common pin lock, so these elements can be directly used for the modified common pin lock.


2.1.4 Hardware connection on the system board: (1) Connect the 4 horizontal lines and 4 vertical lines of the 4×4 determinant keyboard to P3.0-P3.3 and P3.4-P3.7 respectively , Used to complete the password input. (2) Connect P0.0 in the "Single Chip Microcomputer System" area to the alarm with a wire to prompt the correct or wrong password input and make a corresponding sound. (3) Connect P1.0-P1.7 in the "Single Chip Microcomputer System" area to the other end of the digital tube display with a wire to realize the display of the digital tube. (4) Connect P2.0-P2.7 in the "Single Chip Microcomputer System" area with a wire to one end of the triode, and then amplify the input to the digital tube display through the transistor, which is shared by the P1 and P2 ports in the "Single Chip Microcomputer System" area. Complete the display of the digital tube. (5) Connect P0.1-P0.3 in the "Single Chip Microcomputer System" area to the L298N chip with wires to achieve unlocking control.


2.2 Software design


This design is a single-chip microcomputer control scheme with AT89S51 as the core. Using the flexible programming design and abundant I/O ports of the single-chip microcomputer, and its control accuracy, not only can realize the basic password lock function, but also add sound and light prompts and even add remote control functions. The content of the design program is: ① Password setting, in this program the password is fixed in the program memory ROM, the password is 6 digits. ②Password input question: According to the pre-designed password input, after inputting, press the confirm key to execute the corresponding function. The source program of this system is written in C language, and the overall block diagram of the design program flow is shown in Figure 3.



图 3 电子锁程序流程总框图

2.2.1 Keyboard input part: The keyboard in this system adopts a 4×4 determinant keyboard. The task of the keyboard processing program is: to determine whether a key is pressed, to determine which key is pressed, and what the function of the key is; to eliminate the jitter when the key is closed or disconnected. Of the two parallel ports, one outputs the scan code to dynamically ground the keys line by line, and the other parallel port inputs the key status. The line scan value and the feedback signal form the key code to identify the key. Check the table through the software to find out the key Features.


2.2.2 Digital display part: This system uses a display circuit composed of 8-digit digital tubes as prompt information. When initializing, it displays "P", and then enter the maximum 6-digit password. When the password is entered, press Confirm the key "F" to compare the passwords. When the password is correct, the prompt message of "1HELLO" will be displayed on the digital tube, and the prompt message of "2ERROR" will be displayed on the digital tube when the password is incorrect. In the process of inputting the password, only one "8." will be displayed on the display from right to left for each password input. When the number of digits entered exceeds 6 digits, an alarm message will be given. During the password input process, if you make a mistake, you can use the "C" key to delete the wrong number you just entered. You can modify the entered password at any time during the password input process.


2.2.3 Buzzer sound prompt part: This system uses P0.0 as the interface for the buzzer alarm, and compares the entered password with the set password. If the password is correct, the buzzer will sound "dingdong" ; If the password is incorrect, the buzzer will sound a "di, di" alarm.


2.2.4 Motor drive part: This system connects P0.1-P0.3 to the motor drive chip, and drives the motor to rotate through the program. When the password is correct, the motor rotates.


3. Electronic lock function test and expansion improvement

3.1 Electronic lock function test


Set an initial password 123456 according to programming, and use a 4×4 matrix keyboard to realize the password input function, as shown in Figure 4. During initialization, the display tube displays "P", and when the password is entered, the display tube only displays "8.". When the password is entered, press the F key to confirm. When the password is correct, the digital tube displays "1HELLO" and sounds "dingdong" at the same time. And drive the motor to start to rotate, then unlock the lock; after the motor rotates and stop, if the lock key A is pressed, the motor reverses and locks can be realized. If the password is incorrectly entered, "2ERROR" will be displayed as the prompt message, and a "di, di" alarm will sound. The C key can be used to modify the entered password during the password input process. After unlocking, you can press D key to set a new password. You can use the B key as the switch key to switch the power supply. The E key returns to the previous page. According to the above steps and operation test, the system runs normally and the basic functions can be realized.


图 4 电子锁按键键盘

3.2 Electronic lock expansion and improvement


Since the day when the electronic lock was invented, designers have continued to expand its functions, turning a simple electronic lock into a multifunctional electronic lock, and then developed an intelligent electronic lock—the entry control system and the identification system. The typical representative of the entrance control system is the card reading system. The card reader uses a type of plastic card similar to a credit card to replace the mechanical key. The panel of the reader contains a narrow gap for inserting cards with different code numbers. The card reader is connected to the central control computer. The card reading system can be programmed to allow everyone to enter the designated room within a specified time, realizing the so-called multi-level access control in time. The system can print out a list of people entering and leaving within a specified time. Another important function of card reading is that the same card cannot be used by two people successively. If the card is recorded "IN" twice, the system will issue an alarm. When the code card is lost or stolen, or when a person's access authority has changed or ended, the card controller can be reprogrammed to make the card immediately invalid. Due to the development of human physiological characteristics detection technology, the entrance control system has been developed into a personnel identification system. It uses computer recognition pattern technology to verify human physiological characteristics, such as fingerprints, palm prints, hand shapes, voice prints, retinal diagrams, and signatures. Its authenticity has been generally accepted by people because physiological characteristics are difficult to imitate or be Transform. The best way to verify identity is to use a combination of human physiological characteristics, cards, passwords, and identification numbers to form a highly secure entrance control system-intelligent electronic locks.


It can also be improved in the following aspects: no matter when the inner door handle is used, the door will be automatically locked, and the safety door handle will prevent any illegal intrusion, and will automatically lock when it is detected that the door is closed. When the power of the door lock is low, an alarm will be issued and a warning will be displayed on the LED screen. If the battery is completely used up, you can easily use the 9 V standard battery as an emergency power supply for the door lock.


4. Design and implementation of network fingerprint electronic lock based on single chip microcomputer

With the continuous advancement of technology, electronic locks have begun to enter everyone's lives. At present, electronic locks are developing rapidly and have begun to gradually replace traditional door locks and are widely used in communities, enterprises, public facilities and home environments. The emergence of electronic locks has greatly facilitated people's lives, and access control can be unlocked and locked without taking out the key. With the development of technology, electronic locks are not only very convenient for people, but also more and more secure. Common electronic lock verification methods include password verification, RFID verification and fingerprint verification. These methods are very safe and only those who meet the identity can Open the door lock.


Now the more popular electronic lock cores use the following methods: First, the electromagnetic lock, through the strong suction generated when the current passes through the silicon steel sheet, tightly attracts the iron plate to lock the door. Second, push and pull the electromagnetic lock. After the electromagnetic coil is energized, it generates magnetic force to attract the movable iron lock core to achieve the effect of locking and opening the door. Third, the deceleration motor locks, through the DC deceleration motor to rotate the gear, push out the lock to achieve the door lock effect.


Although the current electronic locks on the market have many advantages, they also have some shortcomings: First, the price is relatively high, and the price of fingerprint locks on the market is basically above 500 yuan, which is still difficult for ordinary consumers to accept. Secondly, the installation method is not compatible with the original lock, and the original door lock must be replaced, resulting in waste. Thirdly, there is no network function, and when the lock needs to be unlocked temporarily, the user who must hold the key must be present or publish the electronic lock password, which is neither safe nor convenient.


Aiming at the above shortcomings, I designed a network fingerprint electronic lock, which can be compatible with the current popular door lock types, so as to realize the electronic lock function without destroying the original door lock. This electronic lock can provide two verification methods: fingerprint verification and RFID verification, and has added network functions to provide users with remote control functions, and can also upload electronic lock usage logs to improve security.


电子锁方案

4.1 Hardware design of network fingerprint electronic lock


(1) The overall framework of the electronic lock system: This electronic lock uses the AVR microcontroller ATmega328P as the main control chip. This chip has the characteristics of high performance, low power consumption, affordable price, convenient development, and is fully suitable for the functions of the electronic lock. The fingerprint module adopts the common FPM10A module on the market. The module uses serial port communication and can store 1000 fingerprint information, with fast recognition speed, high accuracy and high cost performance. For cost considerations, the RC522 module is used for RFID identification. The RC522 is inexpensive and uses SPI communication to communicate with the main control module without occupying a serial port. The system uses W5100 module for network communication. This module provides RJ-45 network interface and encapsulates TCP/IP protocol stack on chip, which is very suitable for network development. In order to improve the user experience, the system also adds an LCD screen and function buttons.


(2) Electronic lock body design: Install a MG996R metal steering gear at the knob position of the door lock, and fix the steering gear head to the knob, and then fix the steering gear body to the bracket, so that you can control the steering gear Turn the knob to achieve the effect of locking the door. This design method still uses the structure of the original door lock and does not require replacement of the door lock.


4.2 Network fingerprint electronic lock software design


(1) Network development: This electronic lock uses a network platform to realize remote control and upload usage records. The main control chip communicates with the server through the network module, and reads the switch status of the remote server every 5 seconds. When the switch status is off, the program does nothing. If the read switch status is on, the electronic lock will control The servo opens the door lock until it reads that the switch status is off. Each time the lock is unlocked using fingerprint verification or RFID verification, the door lock will automatically upload the user ID of the unlock, that is, the fingerprint ID number or the RFID tag ID number, and the platform will automatically record the date and time of the unlock. The record can be stored for 5 years , The user can obtain the unlocking record by logging in to the platform.


(2) Other designs: In order to ensure the stability of the electronic lock, I added a watchdog timer to the program. The program will reset the watchdog timer every 8 seconds. If the timer is not reset on time, the program Software reset will be performed automatically. In order to prevent accidental power failures, a power supply USB port is installed outside the system, which can use an external power supply for power supply during a power failure to ensure the operation of the electronic lock.


to sum up


This design makes full use of the software and hardware resources of the AT89S51 system microcontroller, introduces intelligent analysis functions, and improves the reliability and safety of the system. In addition, the smart password lock can form an intelligent distributed monitoring network with slight changes in software and hardware, and realize centralized monitoring and management within a certain range. It has a wide range in finance, insurance, military power and other security fields. Application prospects.