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

Wi-Fi Controlled ESP32-Based Solenoid Door Lock

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled ESP32-Based Solenoid Door Lock

Circuit Documentation

Summary

The circuit described in the provided information is designed to control a 12V solenoid lock using an ESP32 Devkit V1 microcontroller. The ESP32 is programmed to connect to a Wi-Fi network and host a web server that listens for an unlock command. Upon receiving the command, the ESP32 triggers a relay module to switch the solenoid lock from a locked to an unlocked state for a duration of 5 seconds before returning it to the locked state. The relay module is powered by the 3.3V output from the ESP32 and controls the higher voltage required by the solenoid lock using a separate 12V battery.

Component List

12V Solenoid Lock

Battery 12V

Relay Module 5V-30V

ESP32 Devkit V1

Wiring Details

12V Solenoid Lock

Battery 12V

Relay Module 5V-30V

ESP32 Devkit V1

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();
}

Filename: sketch.ino

Description: This code sets up the ESP32 to connect to a Wi-Fi network and start a web server. It listens for an /unlock route to trigger the relay and unlock the solenoid lock for 5 seconds. The relay is controlled by the GPIO pin D15 on the ESP32.