A COMPLETE CODE FOR GSM BASED ADVANCE DIGITAL LOCKER SYSTEM USING ARDUINO MEGA
SO, you are here for the ARDUINO MEGA or simply an ARDUINO project.
follow these simple steps in order to complete your project:
follow these simple steps in order to complete your project:
1) DOWNLOAD THESE BASIC ARDUINO LIBRARIES
new keypad library
download
password library
download
lcd library
download
Software Serial library
download
once you had downloaded these basic libraries you are ready for the second step i.e. coding
2) TYPE OR COPY THESE CODES:
#include <Password.h>
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(52,53);
Password password = Password( "123456" ); //This is our password
LiquidCrystal lcd( 14, 13, 12, 11, 10, 9);
char count;
char a;
unsigned long previous_millis;
unsigned long current_millis;
unsigned int total_delay;
#define door_button 19
const unsigned int dtime=2700;
const int open1=22;
const int open2=23;
const byte ROWS = 4; // 4 rows
const byte COLS = 3; // 3 columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2};// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = {8, 7, 6};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
mySerial.begin(9600); // GSM baud rate
Serial.begin(9600);
delay(500);
pinMode(door_button,INPUT);
digitalWrite(door_button,LOW);
a=LOW;
previous_millis=0;
current_millis=0;
total_delay=0;
pinMode(open1, OUTPUT);
digitalWrite(open1,HIGH);
pinMode(open2, OUTPUT);
digitalWrite(open2,HIGH);
lcd.begin(16, 2);
lcd.print(" Enter Password");
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(50);
}
void loop()
{
if(previous_millis!=0)
{
current_millis=millis();
total_delay= current_millis-previous_millis;
a= digitalRead(door_button);
if(a==HIGH||total_delay>=6000)
door_close_fn();
}
cursur_and_getkey();
}
//check the keypad events
void keypadEvent(KeypadEvent keyPress)
{
switch (keypad.getState())
{
case m_key::PRESSED:
lcd.print(keyPress); //print the keypress
switch (keyPress)
{
case '#':
checkPassword();
break;
case '*':
password.reset();
lcd.setCursor(0,1);
lcd.print(" ");
break;
default:
password.append(keyPress);
}
break;
}
}
//check the entered password
void checkPassword(){
if (password.evaluate()) //if password is correct
{
//print a message on serial monitor
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("opening door.....");
digitalWrite(open1, HIGH);
digitalWrite(open2, LOW);
delay(dtime);
previous_millis=millis();
lcd.setCursor(0,1);
lcd.print(" ");
digitalWrite(open1,LOW);
digitalWrite(open2,LOW);
count=0;
password.reset(); //reset password
}
else
{
lcd.setCursor(0,1);
lcd.print(" Wrong Password");
delay(600);
lcd.setCursor(0,1);
lcd.print(" ");
count_wrong_paswd();
password.reset(); //reset password
}
}
void count_wrong_paswd(void)
{
count=count+1;
if(count>=3)
{
lcd.clear();// delay(10);
lcd.print("password blocked");
SendTextMessage();
}
else
cursur_and_getkey();
}
void SendTextMessage()
{
mySerial.print("AT+CMGF=1\r");
delay(100);
mySerial.println("AT + CMGS = \"+977984******4\""); // your phone no.
delay(100);
mySerial.println("unauthorized person is trying to accesss your home ");
delay(100);
mySerial.println((char)26);
delay(100);
mySerial.println();
}
void cursur_and_getkey(void)
{
lcd.setCursor(0, 1);
if(count<3)
keypad.getKey();
}
void door_close_fn(void)
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("closing door.....");
digitalWrite(open2, HIGH);
digitalWrite(open1, LOW);
delay(dtime);
lcd.setCursor(0,1);
lcd.print(" ");
digitalWrite(open1,LOW);
digitalWrite(open2,LOW);
digitalWrite(door_button,LOW);
previous_millis=0;
current_millis=0;
}
No comments:
Post a Comment