This code implements a "Smart Safe System" involving multiple functionalities...
This code implements a "Smart Safe System" involving multiple functionalities using various hardware components such as an OLED for display, a keypad for input, a fingerprint sensor, a vibration sensor, a hall effect sensor, RFID, a WiFi-enabled alert system (via Telegram), and a relay-controlled lock mechanism. Here's a breakdown of what the code does:
1. Initialization (setup
method):
- OLED Display: Displays an initialization message "Smart Safe Initializing".
- Fingerprint Sensor: Sets up communication with a fingerprint sensor to authenticate users.
- Sensors:
- Vibration Sensor: Monitors for vibrations (e.g., tampering attempts).
- Hall Sensor: Detects whether the safe door is open or closed.
- RFID: Configures and initializes the PN532 RFID module for reading card/tag IDs.
- RTC (Real-Time Clock): Sets up the DS3231 real-time clock module, though it is not actively used in this context.
- WiFi: Initializes an ESP-01 WiFi module to connect to a wireless network and send alerts via Telegram.
- Buzzer & Lock: Configures the lock and buzzer pins.
The system also sends a Telegram alert ("Smart Safe Online") upon successfully starting up.
2. Main Functionality (loop
method):
The loop
method constantly monitors different inputs and executes appropriate actions based on certain conditions:
a) Keypad Input:
- Users can input a numeric code using the keypad.
- Pressing
#
signals the system to check whether the entered code matches a predefined password (1234
by default). - If the code matches, the safe unlocks via the
unlockSafe
function and sends a Telegram alert ("The Safe was Opened!").
b) Fingerprint Authentication:
- The system continuously checks whether a valid fingerprint is scanned. If a recognized fingerprint is detected, the safe is unlocked using the
unlockSafe
function.
c) Vibration Sensor:
- If vibration is detected (potentially indicating tampering), the system:
- Sends a Telegram alert ("Vibration Detected!").
- Activates the buzzer for 300 milliseconds to signal abnormal activity.
d) Hall Sensor:
- Detects whether the safe door is open or closed. It prints the status ("Safe is closed" or "Safe is open") to the serial monitor for debugging.
e) RFID Authentication:
- Checks for RFID card or tag authentication. If an RFID tag is successfully read, the safe is unlocked.
3. Support Functions:
a) unlockSafe
:
- Unlocks the safe by activating the lock pin (controlled by a relay or similar device).
- Sends a Telegram notification ("The Safe was Opened!").
- Sounds the buzzer for 200 milliseconds.
- Keeps the lock open for 5 seconds before re-locking the safe.
b) sendTelegramMessage
:
- Sends a message to a specified Telegram chat using an HTTP GET request to the Telegram Bot API.
- Used to send notifications like "The Safe was Opened!" or "Vibration Detected!" to the user.
4. Hardware and Protocols Used:
- OLED Display: Provides visual feedback (e.g., initialization messages).
- Keypad: Allows password input.
- Fingerprint Sensor: Fingerprint-based user authentication.
- Vibration Sensor: Detects tampering by monitoring vibrations.
- Hall Sensor: Monitors the open/closed state of the safe.
- RFID (PN532): Allows access via RFID cards or tags.
- ESP-01 WiFi Module: Sends alerts via Telegram.
- RTC (DS3231): Provides real-time clock functionality (though not used in the current logic).
- Buzzer: Signals events like unlocking or tampering.
- Relay-Controlled Lock: Controls the locking mechanism of the safe.
Summary:
This code creates a comprehensive smart safe system that supports multiple authentication methods (keypad, fingerprint, and RFID) and integrates security features like vibration detection and door monitoring. It also notifies the user of key events via Telegram alerts. This ensures robust security and user awareness of safe activities.