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.
- 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
Install the following Python libraries on your device:
pip install opencv-python face-recognition numpy firebase-admin pillow- Go to Firebase Console
- Create a new project
- Navigate to Build → Realtime Database, then click Create Database (choose test mode for development)
- Go to Project Settings → Service Accounts
- Click “Generate new private key” and download the JSON file
- Rename it to
firebase_config.jsonand place it inside your project folder
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"
}To keep your credentials secure, this project uses environment variables for Python and a headers file for ESP32.
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.jsonCreate 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"- Create a folder named
images/inside the project directory. - Place PNG images of authorized individuals in this folder.
- Example:
sample.pngetc. - The program automatically loads all images from this folder when started.
- ESP32 (or ESP8266)
- SG90 Servo Motor (for door lock)
- 2 LEDs (Red → Access Denied, Green → Access Granted)
- 5 V Power Supply / External Battery
| 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 |
-
Install Arduino IDE and ESP32 board support package
-
Install libraries from Library Manager:
FirebaseESP32by MobiztESP32Servo
-
Open
FaceLock.ino -
Update your credentials in the
secrets.hfile (as shown in Step 4). -
Select Board → ESP32 Dev Module and upload the sketch
-
Start the face detection module:
python main.py
-
When a recognized face is detected, Firebase updates:
/door_lock/access → "Yes" -
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”
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.”
+----------------------+ +---------------------------+ +-----------------------+
| 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 |
+--------------------+ +--------------------+
-
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 } }
-
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.
If you found this helpful, give a ⭐ to the repository — your support motivates future IoT innovations!