G8: Password Based Door Lock System - shalan/CSCE4301-WiKi GitHub Wiki
Password Based Door Lock System
Contributors:
- Ahmed Ali 900171421
- Zaki Elsayed 900171230
Github Repo:
https://github.com/a9aly/Door-Lock-System
Project Description:
With the increased demand for smart systems that provides more flexibility and security, people started looking for alternatives to replace their old downgraded systems. In Our project we aim to provide one of these smart solutions that provide more security, which is a password based door locking system circuit designed using STM32l432kc microcontroller. A secure password will act as a door unlocking system instead of keys. Our project will be an integration of mechanical and electronic devices and it will consist of electronic control assembly, which controls the output load through a password and this output load is the Servo Motor.
Hardware Components:
-
STM32l432kc Microcontroller
-
16*2 LCD Display
-
Active Buzzer
-
Mobile Phone "Supports Bluetooth"
-
Servo Motor
-
HC05 or HC06 module
-
Ultrasonic Sensor HC-SR04
-
Optional:
USB to TTL Serial Converter "Replaces Mobile Phone"
Software Components
-
Keil uVision
-
CubeMX
-
Bluetooth Terminal on Mobile Phone
-
Optional:
Tera Term "In USB to TTL Serial Converter Case"
System Design
Input
- Entering Password Via Mobile Phone Keypad "Only numbers 0-9 are acceptable".
- Distance between the door and surroundings for auto-lock technique.
Output
- LCD Display providing user interface.
- Buzzer produce an alarm in case of wrong password entry for many times.
- Servo Motor locks and unlocks the door.
- Duration remaining for the door until it locks again.
Communication:
- LCD display instructions to user.
- User will interface with the STM32l432kc via mobile keypad.
- STM32l432kc analyzes and computes user input to produce output.
- Servo Motor acts as door lock/unlock.
How it works:
1 - The user is asked whether he wants to enter pin to unlock the door or reset pin "which is by default it's 1,1,1,1".
2 - User enters his choice through mobile keypad.
3 - In case the user wants to unlock the door: if pins match, PWM signal is generated with certain duty cycle to rotate the servo motor.
4 - if pins does not match the user has 2 more chances to re-enter pin before an alarm starts buzzing.
5 - To stop the buzzer the user has to enter the correct password.
6 - In case the user wants to reset the pin: he is asked to enter the old pin.
7 - If pins match, user is asked to enter the new password.
8 - If pins does not match, the user has only 2 more chances to re-enter pin before an alarm starts buzzing with the same stopping condition mentioned above.
9 - While the door is open and with the aid of ultrasonic sensor, the distance between the door and any passing object is calculated.
10 - If calculated distance is more than ~ 100cm (1m) "No one is passing", the LCD display time remaining until the door is locked and door is locked after 10 seconds.
11 - If calculated distance is less than ~ 100cm (1m) "Someone is passing", the period of 10 seconds starts over.
Servo Motor
Timer Setup (with 50Hz output and 20ms cycle)
My clock frequency is 4MHZ.
To get 50HZ ->> 4MHz/[(1+799)(1+99)] = 50Hz
Then I need to change the duty cycle as mentioned below and according to values in data sheet to rotate the motor for 90 degrees.
Timer Setup
Coding
LCD
We are using LCD 16*2 in 4 bit mode to allow more space for other peripherals in our microcontroller. In this mode we send data as upper 4bits (D4-D7) at once.
LCD APIs
LCD_INIT
LCD_SEND_DATA
LCD_Clear_Screen
LCD_Mark_DATA
LCD_Print_String
LCD_Print_Charachter
LCD_Move_Cursor
LCD_Print_Start_Message
LCD_Asking_User_Input
For More Details You Can Check Links in Reference Under LCD.
Challenges:
- LCD communications.
- Servo Motor application.
- Integrating all components and using parallel timers for different purposes.
- Surely Wiring.
Limitations and some possible modifications:
- User cannot unlock the door without having Bluetooth on his mobile phone. "Keypad can solve this situation".
- In case of power failure, password resets to its default value again '1,1,1,1'. "Either provide an alternative electric source in cases of emergency or provide a memory to keep passwords".
- It is better to replace the ultrasonic sensor with infrared sensor to detect infrared radiations in the surrounding environment and detect the presence of anyone around the door, to activate auto lock.
Flow Chart
Connections
Milestones
Milestone 1: Delivered Project Idea, initial design and needed components.
Link for presentation: Video: https://drive.google.com/file/d/1_QvPrNRB5fkZt5riAR7BM_xWUSAOQpFg/view?usp=sharing
Slides: https://drive.google.com/file/d/1qtrtT6t22YvlvgQRgkdDXzheQyB7dB2h/view?usp=sharing
Milestone 2: Presenting current progress, issues and proposed solutions.
Link for presentation: Video: https://drive.google.com/file/d/1gNHlCwkZpUsNdF1QvZrVAzDLdOZh-J1j/view?usp=sharing
Slides: https://drive.google.com/file/d/1dnXGEMY6RVx7bOdLDq9_yzasSQSWkWGV/view?usp=sharing
Milestone 3: Finalized project.
Final Demo Video: https://drive.google.com/file/d/1GTTRV4BRQ5Ibrempgn3UVgtp5dj9P2ku/view?usp=sharing
Demo goes as following:
1 - First, I choose to unlock the door and I input the correct pin numbers, so the servo motor rotates "representing unlocking the door".
2 - Distances readings are taken and time remaining is updated every 2 seconds for 10 seconds period. I pass my hand in front of the sensor and the period starts over again. After the end of the period the lock locks itself.
3 - Then I test resetting the password, I enter the right pin and I am allowed to set a new pin, otherwise I see a message that I entered a wrong pin and am not allowed to change the current pin.
4 - After 3 wrong pin entry trials, the buzzer goes on and produce a tone that never goes silent unless I put the right pin.
Pictures showing some LCD outputs:
References
1- Servo Motor Datasheet http://www.ee.ic.ac.uk/pcheung/teaching/DE1_EE/stores/sg90_datasheet.pdf
2- HC-SR04 Datasheet http://web.eece.maine.edu/~zhu/book/lab/HC-SR04%20User%20Manual.pdf
3- LCD
1602 Datasheet https://www.waveshare.com/datasheet/LCD_en_PDF/LCD1602.pdf
Interfacing LCD16x2 with AVR ATmega16/ATmega32 in 4-bit mode https://www.electronicwings.com/avr-atmega/interfacing-lcd-16x2-in-4-bit-mode-with-atmega-16-32-
4- STM32l432kc Datasheet https://www.st.com/resource/en/datasheet/stm32l432kc.pdf