Muhammad_Munir
Published © GPL3+

WiFi Door Lock

How to make door lock with ESP8266

IntermediateFull instructions provided5,498
WiFi Door Lock

Things used in this project

Hardware components

Car door lock actuator
×1
Arduino UNO
Arduino UNO
×1
Node MCU
×1
Motor Driver L298
×1
Jumper wires (generic)
×1

Story

Read more

Code

Code

Arduino
#define IN_1  5         // L298N in1 motors Right           GPIO15(D1)
#define IN_2  4         // L298N in2 motors Right           GPIO13(D2)
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

String command;             //String to store app command state.
int n=0;
const char* ssid = "munir123";
const char* password = "munir123456";  //Your Wifi Password
ESP8266WebServer server(80);

void setup() {


pinMode(IN_1, OUTPUT);
pinMode(IN_2, OUTPUT);

Serial.begin(115200);

// Connecting WiFi

WiFi.mode(WIFI_AP);
// WiFi.softAP(ssid);
WiFi.softAP(ssid, password, 1, 1);

IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);

// Starting WEB-server
   server.on ( "/", HTTP_handleRoot );
   server.onNotFound ( HTTP_handleRoot );
   server.begin();    
}


void doorunlock(){

    digitalWrite(IN_1,HIGH);
    delay(100);
    digitalWrite(IN_1,LOW);
    //delay(3000);
    
 }


void doorlock(){

    digitalWrite(IN_2,HIGH);
    delay(100);
    digitalWrite(IN_2,LOW);
    //delay(3000);
    
 }



void loop() {

  server.handleClient();
 
    command = server.arg("State");
    if (command == "doorunlock"){
     if(n == 1){
      doorunlock();
      n--;
     }
    }
    else if(command == "doorlock"){
      if(n == 0){
     doorlock();
     n++;}
    }
   else if(command == "taskcompleted"){
      digitalWrite(IN_1,LOW);
       digitalWrite(IN_2,LOW);
   }


}

void HTTP_handleRoot(void) {

if( server.hasArg("State") ){
     Serial.println(server.arg("State"));
}
server.send ( 200, "text/html", "" );
delay(100);
}

Credits

Muhammad_Munir

Muhammad_Munir

77 projects • 48 followers
I am Arduino programmer, also expertise in ESP32 and 8266 wifi modules.

Comments