Next Builder
Published © CC BY-NC

Face Recognition Door Lock with Smartphone Notification

An Advanced Door Lock System

IntermediateFull instructions provided5 hours17
Face Recognition Door Lock with Smartphone Notification

Things used in this project

Hardware components

HUSKYLENS AI Camera
DFRobot HUSKYLENS AI Camera
×1
Beetle ESP32 C6 Mini Development Board for Wireless Smart Wearable Device
DFRobot Beetle ESP32 C6 Mini Development Board for Wireless Smart Wearable Device
×1
DFRobot MP1584 Buck Converter
×1
DC Female Socket
×1
12v Solenoid Lock
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE
Fusion
Autodesk Fusion
PCBWay 3D Printing Service

Hand tools and fabrication machines

DFRobot Smart Soldering
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Custom parts and enclosures

Main Panel

Sketchfab still processing.

Back

Sketchfab still processing.

Schematics

Connection Diagram

Code

Code

C/C++
#include "HUSKYLENS.h"
#include <WiFi.h>
#include <WiFiClientSecure.h>

// WiFi credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

// Telegram Bot credentials
const char* botToken = "YOUR_BOT_TOKEN";
const char* chatID = "YOUR_CHAT_ID";

// HuskyLens (UART2 on ESP32)
HUSKYLENS huskylens;
HardwareSerial huskySerial(2); // Use UART2 (RX2=16, TX2=17)

// Solenoid Lock Pin
#define LOCK_PIN 4 // D4 on Beetle ESP32-C6
bool unlocked = false;

void setup() {
Serial.begin(115200);
delay(1000);
Serial.println("Booting...");

pinMode(LOCK_PIN, OUTPUT);
digitalWrite(LOCK_PIN, LOW); // Initially locked

// Connect to WiFi
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\n✅ WiFi Connected");

// Initialize HuskyLens (UART2)
huskySerial.begin(9600, SERIAL_8N1, 16, 17); // RX=16, TX=17
if (!huskylens.begin(huskySerial)) {
Serial.println("❌ HuskyLens not connected!");
while (1); // Stop if HuskyLens fails
}
Serial.println("✅ HuskyLens connected!");

Serial.println("System ready.");
}

void loop() {
if (huskylens.request()) {
while (huskylens.available()) {
HUSKYLENSResult result = huskylens.read();
int id = result.ID;
Serial.print("Detected ID: ");
Serial.println(id);

if (id >= 1 && id <= 5 && !unlocked) {
Serial.println("✅ Authorized face. Unlocking...");
digitalWrite(LOCK_PIN, HIGH); // Unlock
unlocked = true;

String message = "🔓 Door unlocked by ID-" + String(id);
sendTelegramMessage(message);

delay(5000); // Keep unlocked for 5 sec
Serial.println("🔒 Locking again...");
digitalWrite(LOCK_PIN, LOW); // Lock
unlocked = false;
}
}
}
delay(100);
}

void sendTelegramMessage(String message) {
WiFiClientSecure client;
client.setInsecure(); // Skip SSL verification (not secure for production)

if (!client.connect("api.telegram.org", 443)) {
Serial.println("❌ Telegram connection failed");
return;
}

String url = "/bot" + String(botToken) +
"/sendMessage?chat_id=" + String(chatID) +
"&text=" + message;

Serial.println("Sending to Telegram: " + message);

client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: api.telegram.org\r\n" +
"Connection: close\r\n\r\n");

delay(1000);
}

Credits

Next Builder
12 projects • 20 followers
Student

Comments