GSM Based Door Lock
How to Lock and Unlock Door with Mobile Phone
Components and supplies
1
SIM800L
1
3.7 volt battery
1
Jumper Wire
1
Card Board
1
Car Door Lock Activator
1
Motor Driver L298l
1
Arduino Nano R3
1
Screws
Project description
Code
Code
arduino
1 2#include<SoftwareSerial.h> 3SoftwareSerial mySerial(10,11); // (Rx,Tx > Tx,Rx) 4 5char incomingByte; 6String inputString; 7int IN1 = 2; // Output for Motor Driver IN1 8int IN2 = 3; // Output for Motor Driver IN2 9 10void setup() 11{ 12 pinMode(IN1, OUTPUT); 13 pinMode(IN2, OUTPUT); 14 digitalWrite(IN1, LOW); // Initial state of the LOW 15 digitalWrite(IN2, LOW); // Initial state of the LOW 16 Serial.begin(9600); 17 mySerial.begin(9600); 18 19 while(!mySerial.available()){ 20 mySerial.println("AT"); 21 delay(1000); 22 Serial.println("Connecting..."); 23 } 24 Serial.println("Connected!"); 25 mySerial.println("AT+CMGF=1"); //Set SMS to Text Mode 26 delay(1000); 27 mySerial.println("AT+CNMI=1,2,0,0,0"); //Procedure to handle newly arrived messages(command name in text: new message indications to TE) 28 delay(1000); 29 mySerial.println("AT+CMGL=\\"REC UNREAD\\""); // Read Unread Messages 30 } 31 32void loop() 33{ 34 if(mySerial.available()){ 35 delay(100); 36 37 // Serial Buffer 38 while(mySerial.available()){ 39 incomingByte = mySerial.read(); 40 inputString += incomingByte; 41 } 42 43 delay(10); 44 45 Serial.println(inputString); 46 inputString.toUpperCase(); // Uppercase the Received Message 47 48 //turn RELAY ON or OFF 49 if (inputString.indexOf("DOOR LOCK") > -1){ // Send sms for door lock 50 digitalWrite(IN1, HIGH); 51 delay(500); 52 digitalWrite(IN1, LOW); 53 } 54 55 if (inputString.indexOf("DOOR UNLOCK") > -1){ //send sms for door unlock 56 digitalWrite(IN2, HIGH); 57 delay(500); 58 digitalWrite(IN2, LOW); 59 } 60 61 delay(50); 62 63 //Delete Messages & Save Memory 64 if (inputString.indexOf("OK") == -1){ 65 mySerial.println("AT+CMGDA=\\"DEL ALL\\""); 66 67 delay(1000);} 68 69 inputString = ""; 70 } 71} 72
Code
arduino
1 2#include<SoftwareSerial.h> 3SoftwareSerial mySerial(10,11); // 4 (Rx,Tx > Tx,Rx) 5 6char incomingByte; 7String inputString; 8int IN1 = 9 2; // Output for Motor Driver IN1 10int IN2 = 3; // Output for Motor Driver IN2 11 12void 13 setup() 14{ 15 pinMode(IN1, OUTPUT); 16 pinMode(IN2, OUTPUT); 17 18 digitalWrite(IN1, LOW); // Initial state of the LOW 19 digitalWrite(IN2, 20 LOW); // Initial state of the LOW 21 Serial.begin(9600); 22 mySerial.begin(9600); 23 24 25 while(!mySerial.available()){ 26 mySerial.println("AT"); 27 28 delay(1000); 29 Serial.println("Connecting..."); 30 } 31 32 Serial.println("Connected!"); 33 mySerial.println("AT+CMGF=1"); 34 //Set SMS to Text Mode 35 delay(1000); 36 mySerial.println("AT+CNMI=1,2,0,0,0"); 37 //Procedure to handle newly arrived messages(command name in text: new message 38 indications to TE) 39 delay(1000); 40 mySerial.println("AT+CMGL=\\"REC 41 UNREAD\\""); // Read Unread Messages 42 } 43 44void loop() 45{ 46 if(mySerial.available()){ 47 48 delay(100); 49 50 // Serial Buffer 51 while(mySerial.available()){ 52 53 incomingByte = mySerial.read(); 54 inputString += incomingByte; 55 56 } 57 58 delay(10); 59 60 Serial.println(inputString); 61 62 inputString.toUpperCase(); // Uppercase the Received Message 63 64 //turn 65 RELAY ON or OFF 66 if (inputString.indexOf("DOOR LOCK") > -1){ // 67 Send sms for door lock 68 digitalWrite(IN1, HIGH); 69 delay(500); 70 71 digitalWrite(IN1, LOW); 72 } 73 74 if 75 (inputString.indexOf("DOOR UNLOCK") > -1){ //send sms for door unlock 76 77 digitalWrite(IN2, HIGH); 78 delay(500); 79 digitalWrite(IN2, 80 LOW); 81 } 82 83 delay(50); 84 85 //Delete Messages 86 & Save Memory 87 if (inputString.indexOf("OK") == -1){ 88 mySerial.println("AT+CMGDA=\\"DEL 89 ALL\\""); 90 91 delay(1000);} 92 93 inputString = ""; 94 95 } 96} 97
Downloadable files
Diagram
Diagram

Comments
Only logged in users can leave comments