text: 1. 16x2 Lcd display. 2. Button panel to enter password. 3. Image notification through email on security breech. 4. Password to auto turn 'OFF' lights inside the house. 5. OTP (one time password) for guest. 6. Motor operated automatic door.
  The smart lock project contains a 16x2 Lcd display , Arduino Uno micro-controller board , Matrix switch panel , a SIM900 GSM** module, *Raspberry pi 3* board and ***Basler Dart camera*.
  Note:** **Connectivity between controllers are done to make efficient system and reduce the number of micro-controllers as more number of pins were needed in lock and very less number of I/O pins were needed in window/cutrain system.
  1. Smart password locking system.
  2. One time password for guests.
  3. Email notification on security breech.
  4. Turn 'OFF' lights inside the house using password.
  #include #include #include LiquidCrystal lcd(12, 11, 4, 5, 6, 7); // LCD connected on pins 12, 11, 4, 5, 6, 7 SoftwareSerial mySerial(9, 10); // pin 6 as RX and Pin 10 as TX int countwrong=0; // counter for counting the number of times the password was wrong char otp [4]= {' ',' ',' ',' '}; // variable to store otp char pass [4]; // variable to store entered password char password [4]= {'1','2','3','4'}; // stored password char light [4]= {'4','4','4','4'}; // stored password for lights OFF const byte ROWS = 4; //four rows of keypad const byte COLS = 3; //three columns of keypad char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'#','0','*'} }; byte rowPins[ROWS] = {A0, A1, 8, A5}; //connect to the row pinouts of the keypad byte colPins[COLS] = {A2, A3, A4}; //connect to the column pinouts of the keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); void setup() { mySerial.begin(9600); // Setting the baud rate of GSM Module Serial.begin(9600); // Setting the baud rate of ardunio to window controller lcd.begin(16, 2); lcd.clear(); delay(100); pinMode ( 13, OUTPUT); // Status LED pinMode ( 2, OUTPUT); // pin for raspberry pi to send email. } void loop() { lcd.setCursor(0, 1); lcd.print(" "); lcd.setCursor(0, 0); lcd.print(" Shanque's Home "); //Prints message on the screen delay(50); if ( countwrong == 4){ // checks if the password was wrong for more than 4 times digitalWrite (2, HIGH); digitalWrite (13, HIGH); delay(500); digitalWrite (2, LOW); digitalWrite (13, LOW); delay(500); digitalWrite (13, HIGH); delay(500); digitalWrite (13, LOW); // blinks led and set the pin 2 high for raspberry pi countwrong=0; } // if (mySerial.available()>0) // For GSM module { char ch = mySerial.read(); if ( ch == '#') // check for # and then store the password accordinly { for (int i=0;i<4;i++) { otp[i] = mySerial.read(); // Store OTP } digitalWrite(13, HIGH); // sets status led 'ON' when OTP received lcd.setCursor(0, 0); lcd.print(" otp received "); delay(100); SendMessage(); // Sends message to the phone on OTP received } } char key = keypad.getKey(); // keypad input if (key != NO_KEY){ lcd.setCursor(0, 0); lcd.print(" Enter Password "); for (int i =0;i<4;i++) { key = keypad.getKey(); while (key == NO_KEY) { key = keypad.getKey(); } pass[i]=key; lcd.setCursor(i, 1); lcd.print('*'); delay(200); } int count = 0; // local counters for password check int count2 = 0; int count3 = 0; for (int i =0;i<4;i++) { if ( pass[i] == password[i]) // check for password equal to stored password count++; if ( pass[i] == otp[i]) // check for password equal to stored otp count2++; if ( pass[i] == light [i]) // check for password equal to stored password for lights count3++; } if(count == 4) { lcd.setCursor(0, 0); lcd.print(" door open "); Serial.write('Y'); // sends Y to window controller to open gates delay(500); countwrong=0; } else if (count3 == 4) { lcd.setCursor(0, 0); lcd.print(" Lights OFF "); Serial.write('Z'); // sends Z to switch board controller to switch off lights delay(500); countwrong=0; // sets counter to zero } else if (count2 == 4) // if password is equal to otp, opens gates and deletes OTP { lcd.setCursor(0, 0); otp [0] = ' '; otp [1] = ' '; otp [2] = ' '; otp [3] = ' '; lcd.print(" door open "); delay(500); digitalWrite (13, LOW); Serial.write('Y'); // sends Y to window controller to open gates lcd.setCursor(0, 0); lcd.print(" otp used "); delay(500); SendMessage1(); // sends the message that guests arrived countwrong=0; } else { lcd.setCursor(0, 0); lcd.print(" wrong password "); countwrong++; // raise the password by one if the password was wrong delay(500); } } } void SendMessage() // send message when otp is received { mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(1000); // Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number delay(1000); mySerial.println("OTP Received");// The SMS text you want to send delay(100); mySerial.println((char)26);// ASCII code of CTRL+Z delay(1000); } void SendMessage1() // send message when otp is used. { mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(1000); // Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS=\"+91xxxxxxxxxx\"\r"); // Replace x with mobile number delay(1000); mySerial.println("Guest arrived");// The SMS text you want to send delay(100); mySerial.println((char)26);// ASCII code of CTRL+Z delay(1000); }
  The lock contains a matrix keypad which is used to input password which thereby is compared with the stored password and unlocks the door if the password is correct. If the PASSWORD is incorrect, then it increases the counter which is used to note the number of incorrect attempts.
  For the keypad board to work, a keypad library is needed to be installed in the arduino IDE which can be downloaded here
  The input from the keypad is stored in the character array of size 4, i.e. the password used here is of four digits only.
  Whenever the password is correct, the lock controller send a message to window/curtain controller which in turn operates the geared DC motor using L 293 ( the motor driver ).
  This features allows guests to enter inside the house when you are not present to attend them or late for some reasons, thereby reducing extra efforts.
  To initiate OTP, we need to send a four digit password from our mobile phone to the number in the GSM module. The OTP begins with '#', example : #4444, #1234, #5665 etc. When the Lock controller receives the password, It sends a message to the registered number "OTP received" and also switches 'ON' the LED connected to Pin 13** of the controller.**
  When the quest use the OTP provided , It gets deleted and also switches 'OFF' the LED connected to Pin 13 of the controller and sends the message to the registered mobile number "Guest Arrived".
  For this feature, I have used Raspberry pi 3 board with Basler Dart Camera** and wifi** connection for internet.
  Installation:
  First you need to install Raspbian on your micro sd card that you will be using in your Raspberry Pi.
  You can download the latest image of Raspbian from Raspberry Pi website at:
  You will need to use an image writing tool to install the image on your SD card. You can find the steps to do that at:...
  There are lots of methods to do this. But I would prefer using the simplest method that is available in OpenCV website at...
  Download pylon 5.0.11 Camera Software Suite Linux ARM 32 bit hardfloat from Here ,** **unzip and follow the iunstructions mentioned in text file inside.
  Use the attached Python code after editing the following lines
  gmail_user = "xxxx@gmail.com" #Sender email address
  Enter your email address in the above line using which the Photo captured will be sent
  gmail_pwd = "xxxx" #Sender email password
  Enter the password of the sender email address.
  to = "xxxx@gmail.com" #Receiver email address
  Enter the email address to which the email with the picture captured will be sent...
  import RPi.GPIO as GPIO import time import numpy as np import pypylon.pylon as py import cv2 from datetime import datetime import os import smtplib from email.MIMEMultipart import MIMEMultipart from email.MIMEBase import MIMEBase from email.MIMEText import MIMEText from email import Encoders gmail_user = "xxxx@gmail.com" #Sender email address gmail_pwd = "xxxx" #Sender email password to = "xxxx@gmail.com" #Receiver email address subject = "Security Breach" text = "Somebody is trying wrong passwords at the door. See the attached picture." sensor = 4 GPIO.setmode(GPIO.BCM) GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN) previous_state = False current_state = False icam = py.InstantCamera(py.TlFactory.GetInstance().CreateFirstDevice()) icam.PixelFormat = "RGB8" while True: previous_state = current_state current_state = GPIO.input(sensor) if current_state != previous_state: new_state = "HIGH" if current_state else "LOW" print("GPIO pin %s is %s" % (sensor, new_state)) if current_state: icam.Open() img = icam.GrabOne(4000) img = img.Array print "Saving Photo" picname = datetime.now().strftime("%y-%m-%d-%H-%M") picname = picname+'.jpg' cv2.imwrite(picname, img) print "Sending email" attach = picname() print "Email Sent" os.remove(picname)
  Now connect the Basler Dart camera and pin from arduino to the Raspberry Pi.
  Connect the output from arduino to GPIO pin 4 and also connect ground from arduino to ground of raspberry pi.
  Now you run the python code with sudo to check the setup. Whenever somebody enters password wrong more than 5 times, an image is captured and email is set the to email address you entered as the receivers email address.
  6. Raspberry Pi Auto Login and Auto Start and Run the Python Code :
  To auto run the python code at start up just by powering up the raspberry pi use the following steps.
  Auto Login:
  In Terminal:
  sudo nano /etc/inittab
  Scroll down to:
  1:2345:respawn:/sbin/getty 115200 tty1
  and change to
  Under that line add:
  1:2345:respawn:/bin/login -f pi tty1 /dev/tty1 2>&1
  Ctrl+X to exit, Y to save followed by enter twice
  Auto run the python code
  sudo nano /etc/rc.local
  Scroll to the bottom and add the following above exit 0:
  sudo python /directory/pythonfile.py
  Press Ctrl+X to exit, Y to save followed by Enter twice.
  If you face any issues in the steps, look at
  Now reboot the system and you will see that the python code has started.
  This feature allows you to switch 'OFF' the lights inside the house when you forgot to switch them 'OFF' so, you don't need to go inside the house to switch them 'OFF'. Thereby reducing extra efforts.
  This is how it works :
  When the password entered by you matches the password for the lights, say '4444'** here, the controller sends a signal to Window/Curtain controller, which in turn sends the signal to switch board controller and switches all the lights 'OFF'**.
  Report comment