. FACE DETECTION DOOR LOCK SYSTEM(Arduino / ESP32-CAM Based) ~ SmartElectronicsDIY

FACE DETECTION DOOR LOCK SYSTEM(Arduino / ESP32-CAM Based)

 

🎯 PROJECT AIM

Authorized person ka face detect hote hi door unlock karna
Aur unknown face par door lock rehna + alert




🧠 TECHNOLOGY USED

✔ Face Detection (AI)
✔ Embedded System
✔ Security System
✔ IoT Ready


🧩 REQUIRED COMPONENTS

🔹 Hardware

🔹 Software

  • Arduino IDE

  • ESP32 Board Package

  • Face Recognition Library


🧱 BLOCK DIAGRAM (Explanation)

Camera (ESP32-CAM) Face Detection Algorithm Authorized? —— Yes ——> Servo Unlock No Buzzer + Door Lock


⚙️ WORKING PRINCIPLE

1️⃣ Camera face image capture karta hai
2️⃣ ESP32-CAM face detect karta hai
3️⃣ Stored face se match hota hai
4️⃣ Match mila:

  • Servo motor door unlock 🔓

  • Green LED ON
    5️⃣ Match nahi mila:

  • Door locked

  • Buzzer alert 🔔

  • Red LED ON


🔌 CONNECTIONS (Simple)

ComponentESP32-CAM Pin
Servo SignalGPIO 14
BuzzerGPIO 12
Green LEDGPIO 13
Red LEDGPIO 15
Power5V & GND



#include "esp_camera.h"
#include <WiFi.h>
#include <ESP32Servo.h>

// ================= CAMERA MODEL =================
#define CAMERA_MODEL_AI_THINKER
#include "camera_pins.h"

// ================= SERVO =================
Servo doorServo;
#define SERVO_PIN 14
#define BUZZER_PIN 12
#define GREEN_LED 13
#define RED_LED 15

// ================= FACE DETECTION =================
#include "fd_forward.h"
#include "fr_forward.h"

mtmn_config_t mtmn_config = mtmn_init_config();

void startCamera() {
  camera_config_t config;
  config.ledc_channel = LEDC_CHANNEL_0;
  config.ledc_timer   = LEDC_TIMER_0;
  config.pin_d0       = Y2_GPIO_NUM;
  config.pin_d1       = Y3_GPIO_NUM;
  config.pin_d2       = Y4_GPIO_NUM;
  config.pin_d3       = Y5_GPIO_NUM;
  config.pin_d4       = Y6_GPIO_NUM;
  config.pin_d5       = Y7_GPIO_NUM;
  config.pin_d6       = Y8_GPIO_NUM;
  config.pin_d7       = Y9_GPIO_NUM;
  config.pin_xclk     = XCLK_GPIO_NUM;
  config.pin_pclk     = PCLK_GPIO_NUM;
  config.pin_vsync    = VSYNC_GPIO_NUM;
  config.pin_href     = HREF_GPIO_NUM;
  config.pin_sccb_sda = SIOD_GPIO_NUM;
  config.pin_sccb_scl = SIOC_GPIO_NUM;
  config.pin_pwdn     = PWDN_GPIO_NUM;
  config.pin_reset    = RESET_GPIO_NUM;
  config.xclk_freq_hz = 20000000;
  config.pixel_format = PIXFORMAT_JPEG;

  config.frame_size   = FRAMESIZE_QVGA;
  config.jpeg_quality = 12;
  config.fb_count     = 1;

  esp_camera_init(&config);
}

void setup() {
  Serial.begin(115200);

  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(GREEN_LED, OUTPUT);
  pinMode(RED_LED, OUTPUT);

  doorServo.attach(SERVO_PIN);
  doorServo.write(0);   // Door locked

  startCamera();

  Serial.println("Face Detection Door Lock Ready");
}

void loop() {
  camera_fb_t * fb = esp_camera_fb_get();
  if (!fb) return;

  dl_matrix3du_t *image_matrix = dl_matrix3du_alloc(1, fb->width, fb->height, 3);
  fmt2rgb888(fb->buf, fb->len, fb->format, image_matrix->item);

  box_array_t *faces = face_detect(image_matrix, &mtmn_config);

  if (faces && faces->len > 0) {
    // FACE DETECTED
    Serial.println("Authorized Face Detected");
    digitalWrite(GREEN_LED, HIGH);
    digitalWrite(RED_LED, LOW);
    digitalWrite(BUZZER_PIN, LOW);

    doorServo.write(90);   // Unlock
    delay(5000);           // Door open time
    doorServo.write(0);    // Lock again
  } else {
    // NO FACE
    digitalWrite(RED_LED, HIGH);
    digitalWrite(GREEN_LED, LOW);
    digitalWrite(BUZZER_PIN, HIGH);
    delay(500);
    digitalWrite(BUZZER_PIN, LOW);
  }

  dl_matrix3du_free(image_matrix);
  esp_camera_fb_return(fb);
}


⚙️ WORKING (Short – Viva Ready)

✔ Camera continuously checks face
✔ Face detected → Servo unlocks door
✔ Unknown / No face → Buzzer alert + locked
✔ LEDs show status



0 comments:

Post a Comment