Friday, September 12, 2025
HomeElectronicsDigital Lock Utilizing Net Serial

Digital Lock Utilizing Net Serial


Remark errors or corrections discovered for this circuit, and get the prospect to win huge!

A digital lock utilizing WebSerial leverages trendy microcontroller know-how to create a safe and handy entry management system. This setup usually entails an ESP32 microcontroller, which hosts an internet interface accessible through an area Wi-Fi community. Customers can connect with this community and enter a pre-set password by the WebSerial interface. The microcontroller processes the enter and controls a relay that prompts the lock mechanism. If the right password is entered, the relay is triggered, unlocking the door for a specified interval earlier than mechanically re-locking. This technique enhances safety by permitting real-time, distant entry management and monitoring by a easy net interface, making it an progressive resolution for contemporary entry management wants.

Purposes of the Digital Lock utilizing Webserial

  • Enhances the safety of residential properties by offering distant entry management and real-time monitoring of entry factors.
  • Utilized in workplace buildings to handle worker entry, guaranteeing that solely licensed personnel can enter sure areas.
  • Utilized in sensible locker techniques for parcel supply and storage, enabling customers to securely entry their parcels utilizing an internet interface.
  • Permits resort employees to remotely management and monitor room entry, enhancing visitor safety and operational effectivity and plenty of extra.

Invoice of Supplies (BoM)

Elements Description Amount
Indus Board 3cm sized dev board 1
LED 5mm LED 1
Breadboard 3.5 cm x 4.5 cm breadboard 1
Wires Jumper wires 4
Battery 3V Battery 1

Coding

#embrace 
#if outlined(ESP8266)
  #embrace 
  #embrace 
#elif outlined(ESP32)
  #embrace 
  #embrace 
#endif
#embrace 
#embrace 

AsyncWebServer server(80);

const char* ssid = "ESP Wifi"; // Your WiFi AP SSID
const char* password = "12345678"; // Your WiFi Password

// Password
String presetPassword = "1234"; // Pre-set password
String inputPassword = ""; // Consumer enter password

bool accessGranted = false;
unsigned lengthy unlockTime = 0;
const unsigned lengthy unlockDuration = 5000; // 5 seconds

/* Message callback of WebSerial */
void recvMsg(uint8_t *knowledge, size_t len){
  WebSerial.println("Acquired Knowledge...");
  String d = "";
  for(int i=0; i < len; i++){
    d += char(knowledge[i]);
  }
  WebSerial.println(d);

  // Append the obtained knowledge to the enter password
  inputPassword += d;

  // If 4 digits have been entered
  if (inputPassword.size() == 4) {
    // Verify if the enter password matches the pre-set password
    if (inputPassword == presetPassword) {
      WebSerial.println("Entry Granted");
      // Unlock the door (activate the relay)
      digitalWrite(5, HIGH);
      accessGranted = true;
      unlockTime = millis();
    } else {
      WebSerial.println("Entry Denied");
    }

    // Clear the enter password for the following try
    inputPassword = "";

    // digitalWrite(5, LOW);

    // Immediate the consumer to enter the password once more
    WebSerial.println("Enter the 4-digit password:");
  }
}

void setup() {
  Serial.start(115200);


  // Set relay pin as output
  pinMode(5, OUTPUT);  // Use GPIO 5 for instance, change if wanted
 
  // Initially flip off the relay (lock the door)
  digitalWrite(5, LOW);

  WiFi.softAP(ssid, password);

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

  // WebSerial is accessible at "/webserial" in browser
  WebSerial.start(&server);
  /* Connect Message Callback */
  WebSerial.msgCallback(recvMsg);
  server.start();

  // Immediate the consumer to enter the password
  WebSerial.println("Enter the 4-digit password utilizing the net interface:");
}

void loop() {
   if (accessGranted && (millis() - unlockTime >= unlockDuration)) {
    // Flip off the relay (lock the door) after 5 seconds
    digitalWrite(5, LOW);
    accessGranted = false;
   }
  // Do nothing right here as WebSerial handles the incoming knowledge
  WebSerial.print(F("IP handle: "));
    WebSerial.println(WiFi.localIP());
    WebSerial.printf("Millis=%lun", millis());
    WebSerial.printf("Free heap=[%u]n", ESP.getFreeHeap());
    delay(1000);
}

Connection

Testing

Now we join the board with the USB and add the code within the indus board and examine output after giving command on net serial. To attach indus board with net serial sort (192.168.4.1/webserial) in net browser. Then we may give command 1234 which is password for the entry. If the password is appropriate then it reveals “Entry Granted” and open the door additionally LED begins glowing. Then if the password is wrong then it reveals “Entry Denied” and the door is not going to open.


Writer(s): Manjeet Vishwakarma,  Abhay Verma and Satywanti Kundu are B.Tech ECE college students at GJUS&T HISAR

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments