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

Wi-Fi Controlled ESP32 Smart Lock with 12V Solenoid and Relay

View and Edit Project In Cirkit DesignerImage of Wi-Fi Controlled ESP32 Smart Lock with 12V Solenoid and Relay

Circuit Documentation

Summary

This circuit is designed to control a 12V solenoid lock using an ESP32 Devkit V1 microcontroller and a 1 Channel Relay 5V. The ESP32 connects to a Wi-Fi network and hosts a web server that allows remote control of the solenoid lock. The relay acts as an intermediary to switch the high voltage required by the solenoid lock.

Component List

  1. 12V Solenoid Lock

    • Description: An electromechanical lock that operates on 12V.
    • Pins: +, -
    • Purpose: To lock and unlock a door.
  2. ESP32 Devkit V1

    • Description: A microcontroller with Wi-Fi and Bluetooth capabilities.
    • Pins: 3V3, GND, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, VIN
    • Purpose: To control the relay and host the web server for remote control.
  3. Battery 12V

    • Description: A 12V power source.
    • Pins: +, -
    • Purpose: To provide power to the solenoid lock.
  4. 1 Channel Relay 5V

    • Description: A relay module that operates on 5V and can switch higher voltages.
    • Pins: VCC, GND, IN, NC, COM, NO
    • Purpose: To switch the 12V power to the solenoid lock based on the control signal from the ESP32.

Wiring Details

12V Solenoid Lock

ESP32 Devkit V1

Battery 12V

1 Channel Relay 5V

Code Documentation

Code for ESP32 Devkit V1

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

Code Explanation