ESP32-CAM Face Recognition Door Lock Using Relay and 12V Solenoid Lock

 

ESP32-CAM Face Recognition Door Lock Using Relay and 12V Solenoid Lock



 Project Overview

The ESP32-CAM Face Recognition Door Lock System is a smart security project that uses AI-based face recognition to control a 12V solenoid door lock. When the camera detects and recognizes an authorized face, the system activates a 1-channel relay module, which powers the solenoid lock and unlocks the door automatically.

This project demonstrates how computer vision, IoT hardware, and embedded systems can be combined to build a secure smart door access system. It is an excellent Arduino and IoT project for students, makers, and smart home enthusiasts.

The system uses the ESP32-CAM module for image processing and face detection. Once a registered face is recognized, the microcontroller sends a signal through GPIO4 to trigger the relay module. The relay then completes the circuit of the 12V battery and solenoid lock, allowing the door to unlock.


 Components Required

  • ESP32-CAM Module

  • FTDI Programmer (for uploading code)

  • 1-Channel Relay Module

  • 12V Solenoid Door Lock

  • 12V Battery / Power Supply

  • Jumper Wires

  • Breadboard (optional)


 Circuit Description

The ESP32-CAM acts as the main controller of the system.

Connections:

Relay Module → ESP32-CAM

  • VCC → 5V

  • GND → GND

  • IN → GPIO4

Solenoid Lock → Relay

  • COM → Battery Negative

  • NO → Solenoid Lock Negative

Power Connections

  • Solenoid Lock Positive → Battery Positive

When the relay receives a HIGH signal from GPIO4, the relay closes the circuit, powering the solenoid lock and unlocking the door.

Code:

/*
 * This Arduino Sketch controls a 1-Channel Relay module to operate a 12V
 * Solenoid Lock based on face recognition input from an ESP32-CAM module.
 * The relay is connected to the ESP32-CAM's IO4 pin, and the solenoid lock
 * is powered by a 12V battery. When a recognized face is detected, the
 * relay will be activated, unlocking the door.
 */

const int relayPin = 4; // Relay signal pin connected to ESP32-CAM IO4

void setup() {
  pinMode(relayPin, OUTPUT); // Set relay pin as output
  digitalWrite(relayPin, LOW); // Ensure relay is off initially
}

void loop() {
  // Placeholder for face recognition logic
  // This should be replaced with actual communication from ESP32-CAM
  bool faceRecognized = false; // Simulated face recognition result

  if (faceRecognized) {
    digitalWrite(relayPin, HIGH); // Activate relay to unlock door
    delay(5000); // Keep the door unlocked for 5 seconds
    digitalWrite(relayPin, LOW); // Deactivate relay to lock door
  }

  delay(100); // Short delay to avoid rapid toggling
}


 Working Principle

  1. The ESP32-CAM camera continuously scans for faces.

  2. The system compares the detected face with the stored database of authorized faces.

  3. If a recognized face is detected:

    • GPIO4 goes HIGH.

    • The relay module activates.

    • The 12V solenoid lock opens the door.

  4. If the face is not recognized, the relay remains OFF and the door stays locked.

This setup provides a contactless and secure authentication system.


 Key Features

✔ AI-based face recognition security system
Automatic door unlocking using relay control
✔ Works with 12V solenoid locks
✔ Ideal for smart homes and office access control
✔ Low-cost and easy to build
✔ Perfect for IoT and embedded systems learning


 Applications

  • Smart Home Security Systems

  • Office Access Control

  • School Laboratory Entry Systems

  • Hostel / Dormitory Security

  • Smart IoT Door Locks

Comments