WiFi Smart Door Lock esp8266/Nodemcu

WiFi Smart Door Lock 🔐

Description: Uses a servo motor as a lock, controlled via a web page.
Components:

  • NodeMCU (ESP8266) or ESP32

  • Servo Motor (SG90)

Circuit Diagram



  • Servo Signal → D3

  • Servo VCC → 5V

  • Servo GND → GND

Code

#include <ESP8266WiFi.h> #include <ESP8266WebServer.h> #include <Servo.h> ESP8266WebServer server(80); Servo myServo; const char* ssid = "Your_SSID"; const char* password = "Your_PASSWORD"; void handleLock() { myServo.write(0); // Lock position server.send(200, "text/html", "<h1>Door Locked</h1>"); } void handleUnlock() { myServo.write(90); // Unlock position server.send(200, "text/html", "<h1>Door Unlocked</h1>"); } void setup() { myServo.attach(D3); myServo.write(0); // Start locked WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(1000); } server.on("/lock", handleLock); server.on("/unlock", handleUnlock); server.begin(); } void loop() { server.handleClient(); }

✅ Lock & unlock the door via:

  • http://your_esp_ip/lock (Locks)

  • http://your_esp_ip/unlock (Unlocks)


Post a Comment

0 Comments