Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP32 CAM-Based Wi-Fi Controlled Smart Door Lock with OLED Display

View and Edit Project In Cirkit DesignerImage of ESP32 CAM-Based Wi-Fi Controlled Smart Door Lock with OLED Display

Circuit Documentation

Summary

This circuit is designed to control an electronic door lock using an ESP32 CAM module. The system includes an OLED display for status updates, an IR sensor for motion detection, a relay to control the door lock, and a toggle switch to switch between access and registration modes. The ESP32 CAM connects to a Wi-Fi network to communicate with a server for face recognition and registration.

Component List

  1. ESP32 CAM

    • Description: A microcontroller with a built-in camera module.
    • Pins: 5V, GND, GPIO12, GPIO13, GPIO15, GPIO14, GPIO2, GPIO4, 3.3V, GPIO16, GPIO0, 3.3V / 5V / P_OUT, GPIO3 / RX, GPIO1 / TX
  2. 0.96" OLED

    • Description: A small OLED display for showing status messages.
    • Pins: GND, VDD, SCK, SDA
  3. 12V SINGLE CHANNEL RELAY

    • Description: A relay module to control the electronic door lock.
    • Pins: NC, COM, NO, IN, GND, VCC
  4. 12V Power Supply

    • Description: A power supply to provide 12V DC.
    • Pins: +, -
  5. Buck Converter

    • Description: A DC-DC converter to step down voltage.
    • Pins: IN+, IN-, OUT+, OUT-
  6. IR Sensor

    • Description: An infrared sensor for motion detection.
    • Pins: out, gnd, vcc
  7. FTDI Programmer

    • Description: A USB-to-serial converter for programming the ESP32 CAM.
    • Pins: DTR, RX, TX, VCC, CTS, GND
  8. Toggle Switch

    • Description: A switch to toggle between access and registration modes.
    • Pins: L1, COM, L2
  9. 2.1mm DC Barrel Jack

    • Description: A connector for the 12V power supply.
    • Pins: switch, sleeve, center
  10. EML

    • Description: An electronic door lock.
    • Pins: -, +

Wiring Details

ESP32 CAM

0.96" OLED

12V SINGLE CHANNEL RELAY

12V Power Supply

Buck Converter

IR Sensor

FTDI Programmer

Toggle Switch

2.1mm DC Barrel Jack

EML

Documented Code

// AUTHOR : HARIHARAN P
// COMPANY : AQUAGROUP
// DATE :13.12.2024
//FINAL VC DEVICE SOURCE FILE 

#include "esp_camera.h"
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// WiFi credentials
const char *ssid = "PLC&IOT";
const char *password = "Aqua@12345";
const char *serverURL = "http://192.168.0.58:5000/api/verify";  // Python server API for face recognition
const char *registerURL = "http://192.168.0.58:5000/api/register"; // API for registration

#define DOOR_PIN 13  // Pin to control the door lock (EM lock)
#define SLIDE_SWITCH_PIN 12  // Slide switch to toggle between modes
#define DEVICE_ID "6477744974"
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET    -1  // OLED reset pin, not used
#define SCREEN_ADDRESS 0x3C  // I2C address for the OLED display

// Static IP configuration
IPAddress local_IP(192, 168, 0, 5);     // Desired static IP address
IPAddress gateway(192, 168, 0, 1);       // Gateway address
IPAddress subnet(255, 255, 255, 0);      // Subnet mask
IPAddress primaryDNS(8, 8, 8, 8);        // Primary DNS (optional)
IPAddress secondaryDNS(8, 8, 4, 4);      // Secondary DNS (optional)

// Initialize I2C bus 
TwoWire I2Cbus = TwoWire(0);

// Create an OLED display object
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &I2Cbus, OLED_RESET);

// Initialize camera settings
camera_fb_t* fb = NULL;

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

  // Setup Door Control Pin
  pinMode(DOOR_PIN, OUTPUT);
  digitalWrite(DOOR_PIN, LOW);  // Keep the door locked initially

  pinMode(SLIDE_SWITCH_PIN, INPUT_PULLUP); // Setup Slide Switch

  // Setup I2C for OLED
  I2Cbus.begin(15, 14);  // SDA, SCL pins for the OLED

  // Initialize OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println("SSD1306 allocation failed");
    for (;;); // Don't proceed, loop forever
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 10);
  display.println("Initializing...");
  display.display();

  // Configure Wi-Fi with static IP
  if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    Serial.println("STA Failed to configure");
    display.clearDisplay();
    display.setCursor(0, 10);
    display.println("IP Config Fail");
    display.display();
    for (;;);  // Halt if static IP setup fails
  }

  // Initialize Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    display.setCursor(0, 20);