Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Wi-Fi Controlled ESP32-Based Smart Lock with RFID and OLED Display

Image of Wi-Fi Controlled ESP32-Based Smart Lock with RFID and OLED Display

Circuit Documentation

Summary of the Circuit

The circuit in question appears to be a smart lock system that can be controlled via Wi-Fi. It uses an ESP32 Devkit V1 microcontroller to manage the communication and control logic. The system includes an OLED display for user interface, an RFID-RC522 module for access control, and a r307 fingerprint sensor for biometric verification. A TIP120 Darlington Transistor is used to drive a 12V Solenoid Lock, which acts as the physical locking mechanism. The circuit is powered by a 12V power supply, and a diode is used to protect against reverse polarity. A pushbutton is also included, possibly for manual control.

Component List

Battery 12V

A power source for the circuit.

OLED 1.3"

A small display for outputting information to the user.

TIP120 Hi-Current Darlington Transistor

Used to switch high current loads with a low current control signal from the ESP32.

Resistor

A passive two-terminal electrical component that implements electrical resistance as a circuit element.

ESP32 Devkit V1

A microcontroller with Wi-Fi capabilities for controlling the circuit and communicating with external devices.

r307

A fingerprint sensor module for biometric input.

12V Power Supply

Provides a stable 12V power source for the circuit.

12V Solenoid Lock

An electromechanical lock controlled by the circuit.

RFID-RC522

An RFID reader/writer module for contactless communication using radio frequency.

Diode

A component that allows current to flow in one direction, used for reverse polarity protection.

Pushbutton

A simple switch mechanism for control of a circuit.

Wiring Details

Battery 12V

  • + to 12V power supply +
  • - to 12V power supply -

OLED 1.3"

  • GND to ESP32 GND
  • VCC to ESP32 3V3
  • SCL to ESP32 D22
  • SDA to ESP32 D21

TIP120 Hi-Current Darlington Transistor

  • BASE to Resistor pin1
  • COLLECTOR to Diode anode and 12V Solenoid Lock -
  • EMITTER to 12V power supply -

Resistor

  • pin1 to TIP120 BASE
  • pin2 to ESP32 D15

ESP32 Devkit V1

  • 3V3 to OLED VCC, r307 VCC, and RFID-RC522 VCC (3.3V)
  • GND to 12V power supply -, TIP120 EMITTER, r307 GND, RFID-RC522 GND, and OLED GND
  • D15 to Resistor pin2
  • D4 to RFID-RC522 RST
  • RX2 to r307 RX
  • TX2 to r307 TX
  • D5 to RFID-RC522 SDA
  • D18 to RFID-RC522 SCK
  • D19 to RFID-RC522 MISO
  • D21 to OLED SDA
  • D22 to OLED SCL
  • D23 to RFID-RC522 MOSI

r307

  • VCC to ESP32 3V3
  • RX to ESP32 RX2
  • TX to ESP32 TX2
  • GND to ESP32 GND

12V Power Supply

  • + to Diode cathode and 12V Solenoid Lock +
  • - to ESP32 GND and TIP120 EMITTER

12V Solenoid Lock

  • + to Diode cathode and 12V power supply +
  • - to TIP120 COLLECTOR

RFID-RC522

  • VCC (3.3V) to ESP32 3V3
  • RST to ESP32 D4
  • GND to ESP32 GND
  • IRQ (Not connected)
  • MISO to ESP32 D19
  • MOSI to ESP32 D23
  • SCK to ESP32 D18
  • SDA to ESP32 D5

Diode

  • anode to TIP120 COLLECTOR and 12V Solenoid Lock -
  • cathode to 12V power supply + and 12V Solenoid Lock +

Pushbutton

  • Pin 3 (out) (Not connected)
  • Pin 4 (out) (Not connected)
  • Pin 1 (in) (Not connected)
  • Pin 2 (in) (Not connected)

Documented Code

#include <WiFi.h>
#include <WebServer.h>

const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

WebServer server(80);

// Define GPIO pin for the relay
const int relayPin = 15;

void setup() {
  Serial.begin(115200);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);  // Lock is initially locked

  // Connect to Wi-Fi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }

  Serial.println("Connected to WiFi");

  // Setup server routes
  server.on("/unlock", handleUnlock);
  server.begin();
  Serial.println("HTTP server started");
}

void handleUnlock() {
  digitalWrite(relayPin, LOW);  // Unlock the door
  delay(5000);  // Keep it unlocked for 5 seconds
  digitalWrite(relayPin, HIGH); // Lock again
  server.send(200, "text/plain", "Door unlocked");
}

void loop() {
  server.handleClient();
}

This code is designed to run on the ESP32 Devkit V1 microcontroller. It sets up a Wi-Fi connection and a web server that listens for an /unlock route. When this route is accessed, the ESP32 activates the relay connected to relayPin (GPIO 15), unlocking the door for 5 seconds before locking it again.