Arduino based Digital Lock using Smart Phone

Arduino Arduino LCD Projects

Digital code lock is one of the most popular security system used today. In this project, we are going to build a digital code lock using a simple LCD for display, Arduini, Rasperry Pi, 8051 microcontroller and further equipment. This digital lock will be controlled by smart phone. This communication between the lock and smart phone will be done by bluetooth or wireless. This project is very helpful in saving time or making the access to specific area more secure than usual. You can unlock a door or a gate on you way to it and before you physically reach there.

The equipment that will be used in this system is mentioned below.

Equipment

  • Arduino MEGA
  • Breadboard
  • Android Mobile phone
  • Connecting wires
  • USB Cable
  • HC05 Bluetooth Module
  • Bluetooth terminal App
  • 2.4 inch TFT LCD Shield with SPFD5408 controller
  • Buzzer

Circut for this digital lock system is pretty much straight forward. We are connecting Bluetooth Module HC05 and LCD shield to the Arduino.

In your android phone install an app called Bluetooth Terminal. This helps in communication from your phone to rest of the components. After installing the app you need to pair it with bluetooth controller.

The diagram above explains the working of this system.

Here four digit Password is entered by user through Android Smart Phone using Bluetooth Terminal App and sent to the Arduino via Bluetooth.  Arduino receives the data, sent by Android Phone, using Bluetooth Module HC05 and display it on SPFD5408 TFT LCD. Arduino compares the user entered Password with the Predefined password (1234), and displays the message accordingly. It displays the message “WRONG PASSWORD” if password don’t match and display the message “CORRECT PASSWORD” if password matches. A buzzer is also used for alarm indication, which beeps when password entered is wrong.

Here password is entered via your smart phone and is received by bluetooth terminal(HCo5) via android app already paired with it. After receiving the data Arduino compares it with predefined password. The results of the comparison dictates if the success message is displayed on the LCD or it shows wrong password message.

Code

#include // Core graphics library
#include // Hardware-specific library
#include
// *** SPFD5408 change — End#if defined(__SAM3X8E__)
#undef __FlashStringHelper::F(string_literal)
#define F(string_literal) string_literal
#endif
#define YP A1 // must be an analog pin, use “An” notation!
#define XM A2 // must be an analog pin, use “An” notation!
#define YM 7 // can be a digital pin
#define XP 6 // can be a digital pin// Original values
//#define TS_MINX 150
//#define TS_MINY 120
//#define TS_MAXX 920
//#define TS_MAXY 940// Calibrate values
#define TS_MINX 125
#define TS_MINY 85
#define TS_MAXX 965
#define TS_MAXY 905

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we’re using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
// optional
#define LCD_RESET A4

// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

char arr[4] = {‘1’, ‘2’, ‘3’, ‘4’};
char input[4];
char messageflagarr[4]; char result = ‘0’, flag = 0, passwordflag = 0;
int x = 40, i = 0;
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial1.begin(9600);
tft.reset();
tft.begin(0x9341);
tft.setRotation(0);
tft.fillScreen(WHITE);
tft.setCursor (40, 50);
tft.setTextSize (2);
tft.setTextColor(BLACK);
tft.println(“E N T E R* P A S S W O R D “);
delay(5000);
tft.fillScreen(WHITE);
pinMode(22,OUTPUT);
}

void loop() {
tft.setTextSize (4);
tft.setTextColor(CYAN);

// put your main code here, to run repeatedly:
if (Serial1.available() > 0)
{
flag = 1;
char c = Serial1.read();
if (flag == 1)
{
input[i] = c;
i++;
tft.println(c);
delay(2000);
if (i == 4)
{
passwordflag = 1;
}
flag = 0;
}
if (passwordflag == 1)
{
if (arr[0] == input[0] && arr[1] == input[1] && arr[2] == input[2] && arr[3] == input[3])
{
tft.setCursor (40, 50);
tft.setTextSize (2);
tft.setTextColor(BLACK);
tft.println(“CORRECT PASSWORD”);
delay(6000);
tft.fillScreen(WHITE);
i=0;
}
else
{
tft.setCursor (40, 50);
tft.setTextSize (2);
tft.setTextColor(BLACK);
tft.println(“WRONG PASSWORD”);
digitalWrite(22,HIGH);
delay(500);
digitalWrite(22,LOW);
delay(500);
digitalWrite(22,HIGH);
delay(500);
digitalWrite(22,LOW);
delay(500);
digitalWrite(22,HIGH);
delay(500);
digitalWrite(22,LOW);
delay(500);
digitalWrite(22,HIGH);
delay(500);
digitalWrite(22,LOW);
tft.fillScreen(WHITE);
digitalWrite(22,LOW);
i=0;
}
passwordflag=0;
}
}
}

Arduino based Digital Lock using Smart Phone

Leave comment for this post......