Muhammad_Munir
Published © GPL3+

GSM Based Door Lock

How to Lock and Unlock Door with Mobile Phone

IntermediateFull instructions provided2,032
GSM Based Door Lock

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SIM800L
×1
3.7 volt battery
×1
Jumper Wire
×1
Car Door Lock Activator
×1
Motor Driver L298l
×1
Card Board
×1
Screws
×1

Story

Read more

Schematics

Diagram

Code

Code

Arduino
#include<SoftwareSerial.h> 
SoftwareSerial mySerial(10,11);  // (Rx,Tx  > Tx,Rx) 

char incomingByte; 
String inputString;
int IN1 = 2; // Output for Motor Driver IN1
int IN2 = 3; // Output for Motor Driver IN2

void setup() 
{
      pinMode(IN1, OUTPUT);
        pinMode(IN2, OUTPUT);
      digitalWrite(IN1, LOW); // Initial state of the LOW
       digitalWrite(IN2, LOW); // Initial state of the LOW
      Serial.begin(9600);
      mySerial.begin(9600); 

     while(!mySerial.available()){
        mySerial.println("AT");
        delay(1000); 
        Serial.println("Connecting...");
        }
      Serial.println("Connected!");  
      mySerial.println("AT+CMGF=1");  //Set SMS to Text Mode 
      delay(1000);  
      mySerial.println("AT+CNMI=1,2,0,0,0");  //Procedure to handle newly arrived messages(command name in text: new message indications to TE) 
      delay(1000);
      mySerial.println("AT+CMGL=\"REC UNREAD\""); // Read Unread Messages
     }

void loop()
{  
  if(mySerial.available()){
      delay(100);

      // Serial Buffer
      while(mySerial.available()){
        incomingByte = mySerial.read();
        inputString += incomingByte; 
        }

        delay(10);      

        Serial.println(inputString);
        inputString.toUpperCase(); // Uppercase the Received Message

        //turn RELAY ON or OFF
        if (inputString.indexOf("DOOR LOCK") > -1){      // Send sms for door lock
          digitalWrite(IN1, HIGH);
          delay(500);
          digitalWrite(IN1, LOW);
          }
            
           if (inputString.indexOf("DOOR UNLOCK") > -1){     //send sms for door unlock
          digitalWrite(IN2, HIGH);
          delay(500);
          digitalWrite(IN2, LOW);
          }
        
        delay(50);

        //Delete Messages & Save Memory
        if (inputString.indexOf("OK") == -1){
        mySerial.println("AT+CMGDA=\"DEL ALL\"");

        delay(1000);}

        inputString = "";
  }
}

Credits

Muhammad_Munir

Muhammad_Munir

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

Comments