Skip to content

AayushParekh-1/Link-Lock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔒 LINK-LOCK: IoT-Based Door Security System

🧠 Project Overview

Link-Lock is a smart IoT-powered door locking system that integrates computer vision, cloud connectivity, and embedded control to provide secure and automated access based on facial recognition.


🌟 Features

  • Real-time cloud synchronization via Firebase
  • Pre-stored face verification
  • Face recognition using OpenCV and face-recognition library
  • Automated door lock/unlock using a servo motor
  • Visual feedback via LED indicators
  • Cross-platform and wireless operation using ESP32 Wi-Fi
  • Scalable for real smart-home integration

⚙️ Setup Guide

1️⃣ Install Dependencies

Install the following Python libraries on your device:

pip install opencv-python face-recognition numpy firebase-admin pillow

2️⃣ Setup Firebase

  1. Go to Firebase Console
  2. Create a new project
  3. Navigate to Build → Realtime Database, then click Create Database (choose test mode for development)
  4. Go to Project Settings → Service Accounts
  5. Click “Generate new private key” and download the JSON file
  6. Rename it to firebase_config.json and place it inside your project folder

3️⃣ Configure firebase_config.json

Make sure your file follows this format:

{
  "type": "service_account",
  "project_id": "your-project-id",
  "private_key_id": "your-private-key-id",
  "private_key": "-----BEGIN PRIVATE KEY-----\\nYOUR_PRIVATE_KEY\\n-----END PRIVATE KEY-----\\n",
  "client_email": "your-service-account-email",
  "client_id": "your-client-id",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "your-cert-url"
}

4️⃣ Environment Variables & Secrets

To keep your credentials secure, this project uses environment variables for Python and a headers file for ESP32.

🐍 Python Environment (.env)

Create a file named .env in the root directory and add the following:

FIREBASE_DATABASE_URL=https://your-project-id-default-rtdb.firebaseio.com/
FIREBASE_CREDENTIALS_PATH=firebase_config.json

📡 ESP32 Secrets (secrets.h)

Create a file named secrets.h in the root directory and add:

#define FIREBASE_HOST "https://your-project-id-default-rtdb.firebaseio.com/"
#define WIFI_SSID "YOUR_WIFI_NAME"
#define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"
#define FIREBASE_AUTH "YOUR_FIREBASE_DATABASE_SECRET"

5️⃣ Add Person’s Images

  1. Create a folder named images/ inside the project directory.
  2. Place PNG images of authorized individuals in this folder.
  3. Example: sample.png etc.
  4. The program automatically loads all images from this folder when started.

6️⃣ Setup ESP32 for Door Lock Control

🔧 Required Components

  • ESP32 (or ESP8266)
  • SG90 Servo Motor (for door lock)
  • 2 LEDs (Red → Access Denied, Green → Access Granted)
  • 5 V Power Supply / External Battery

🔌 Wiring Connections

Component ESP32 Pin Function
Red LED GPIO 25 Turns ON when access is denied
Green LED GPIO 26 Turns ON when access is granted
Servo (Signal) GPIO 18 Controls door lock rotation
VCC 5 V Servo + LEDs Power
GND GND Common ground for all components

7️⃣ Flash ESP32 with Code

  1. Install Arduino IDE and ESP32 board support package

  2. Install libraries from Library Manager:

    • FirebaseESP32 by Mobizt
    • ESP32Servo
  3. Open FaceLock.ino

  4. Update your credentials in the secrets.h file (as shown in Step 4).

  5. Select Board → ESP32 Dev Module and upload the sketch


8️⃣ Run the Link-Lock System

  1. Start the face detection module:

    python main.py
  2. When a recognized face is detected, Firebase updates:

    /door_lock/access → "Yes"
    
  3. The ESP32 reads this value in real time and:

    • Rotates the servo to 90° (unlocks)
    • Turns ON the green LED
    • Keeps the door locked (servo = 0°) for “No”

📸 System Workflow

🔁 Detailed Process Flow

1️⃣ The camera captures the live video feed using OpenCV and detects faces using the face-recognition library. 2️⃣ If the detected face matches a pre-stored image, the system sends a “Yes” signal to Firebase Realtime Database. 3️⃣ If the face is not recognized, Firebase updates the value to “No”. 4️⃣ The ESP32 continuously monitors Firebase and reads this value in real time. 5️⃣ If the value is “Yes”, the ESP32 sends a control signal to the servo motor, causing it to rotate and unlock the door. Simultaneously, the green LED turns ON indicating “Access Granted.” 6️⃣ If the value is “No”, the servo motor remains in the locked position and the red LED lights up indicating “Access Denied.”

🧱 Project Architecture

+----------------------+        +---------------------------+        +-----------------------+
|  Webcam (OpenCV +    | -----> |  Python Face-Recognition  | -----> |  Firebase Realtime DB |
|  face_recognition)   |        |  + Firebase update        |        |  /door_lock/access    |
+----------------------+        +---------------------------+        +-----------+-----------+
                                                                            |
                                                                            v
                                                                 +-----------+-----------+
                                                                 |       ESP32 (Wi-Fi)   |
                                                                 | Reads /door_lock/access|
                                                                 +-----------+-----------+
                                                                             |
                                                +-----------------------------+-----------------------------+
                                                |                                                           |
                                                v                                                           v
                                      +--------------------+                                     +--------------------+
                                      |  Servo Motor (90°) |                                     |   LEDs Feedback    |
                                      |  Door Unlock       |                                     |  Green = Yes       |
                                      |                    |                                     |  Red = No          |
                                      +--------------------+                                     +--------------------+

💡 Notes

  • Ensure the ESP32 and the computer running the Python script are on the same Wi-Fi network.

  • If OpenCV installation fails, search “Install OpenCV Python Windows/Linux” on YouTube — several step-by-step guides exist.

  • The servo requires a 5 V supply (not 3.3 V). Use VIN or external 5 V with a shared GND.

  • For first-time use, set Firebase rules to:

    {
      "rules": {
        ".read": true,
        ".write": true
      }
    }

🧠 Future Enhancements

  • Integrate OTP / fingerprint as backup authentication.

  • Migrate from Firebase to Flask API and SQL for offline use and maintaining the history of people who scanned their face.


Contribute / Support

If you found this helpful, give a ⭐ to the repository — your support motivates future IoT innovations!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages