#include <Wire.h>
#include <FastIO.h>
#include <I2CIO.h>
#include <LCD.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal_SR.h>
#include <LiquidCrystal_SR2W.h>
#include <LiquidCrystal_SR3W.h>
//Code by Reyfus
//Original Code by: ironicDeveloper 12/18/2011
//Help & parts of code from arduino forum
// //variables de los componentes
int a;
int calibrationTime = 10;
//El tiempo cuando el sensor emite un impulso de baja
long unsigned int lowIn;
//La cantidad de milisegundos el sensor tiene que ser bajo
//Antes de que asuma todo el movimiento se ha detenido
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 10; //pin digital conectado a la salida del sensor PIR
int ledPin = 13;
int alarma = 11;
#include <Keypad.h> //Includes keypad library
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
const byte ROWS = 4; //Set Leypad Pins
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = { 9,8,7,6};
byte colPins[COLS] = { 5,4,3,2};
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); //Creates the keypad
char inputArray[4]; //Creates the input array
char Main[4] = {'4','6','2','7'}; //creates arra for correct password first door
char Guest[4] = {'1','2','3','4'}; //creates arra for correct Password Second door
#define registerPin 10 //First door open pin
#define secondPin 9 //Second door open pin
int i = 0; //variable to count number of key pressed
long tempo = 0; //variable that counts inactive time for display reset
void setup()
{ pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(alarma, OUTPUT);
digitalWrite(pirPin, LOW);
lcd.begin(20,4); //start the lcd
pinMode(registerPin, OUTPUT); //set First door open pin
pinMode(secondPin, OUTPUT); //set Second door open pin
lcd.print("Enter password"); //Print Message
lcd.setCursor(0, 1); //put cursor on second line
}
void loop()
{
char key = kpd.getKey(); //read ley press
if(key)
{
inputArray = key; //record key press in input array
tempo=0; // zero inactive time variable
i++; // increase key pressed variable
lcd.print(key); //print key pressed to LCD
if(digitalRead(pirPin) == HIGH){ lcd.print("Enter password"); //write message
-
lcd.setCursor(0, 1);*
-
delay(10000);*
-
digitalWrite(alarma,HIGH);*
}else { digitalRead( a== Guest[4]) ;
digitalWrite(alarma, LOW);
digitalWrite(pirPin,LOW);//put cursor on second line -
(i == 4); //If 4 keys have been pressed*
}
if (inputArray[0] == Main[0] && //compare input password to door 1 password
inputArray[1] == Main[1] && //compare input password to door 1 password
inputArray[2] == Main[2] && //compare input password to door 1 password
inputArray[3] == Main[3]) ;}//compare input password to door 1 password -
else {*
-
digitalWrite(registerPin, HIGH); //Activate door 1 relay*
-
delay(500); // wait half a second*
-
digitalWrite(registerPin, LOW); //deactivate relay*
-
lcd.clear(); //clears lcd*
-
lcd.print("Correct Password"); // write message*
-
delay(1500); // Wat 1.5 sec*
-
memset(inputArray,'\0',4); //clears the input array*
-
lcd.clear(); //clear lcd*
-
lcd.print("Enter password"); //write message*
-
lcd.setCursor(0, 1); //put cursor on second line*
-
} else {*
-
if (inputArray[0] == Guest[0] && //compare input password to door 2 password*
inputArray[1] == Guest[1] && //compare input password to door 2 password
inputArray[2] == Guest[2] && //compare input password to door 2 password
inputArray[3] == Guest[3]) //compare input password to door 2 password -
{*
-
digitalWrite(secondPin, HIGH); //Activate door 2 relay*
-
delay(500); // wait half a second*
-
digitalWrite(secondPin, LOW); //deactivate relay*
-
lcd.clear(); //clears lcd*
-
lcd.print("Correct Password"); // write message*
-
delay(1500); // Wat 1.5 sec*
-
memset(inputArray,'\0',4); //clears the input array*
-
lcd.clear(); //clear lcd*
-
lcd.print("Enter password"); //write message*
-
lcd.setCursor(0, 1); //put cursor on second line*
-
}*
-
else // in case of wrong password*
-
{*
-
memset(inputArray,'\0',4); //clears the input array*
-
delay(1000); //wait 1 sec*
-
lcd.clear(); //clear lcd*
-
lcd.print("Wrong Password"); // write message*
-
delay(1500); // Wat 1.5 sec*
-
lcd.clear(); //clear lcd*
-
lcd.print("Enter password"); //write message*
-
lcd.setCursor(0, 1); //put cursor on second line*
-
}*
-
}*
-
i=0; //Zero number of keys pressed*
} -
}*
-
tempo++; //increase inactive time varieable*
-
if (tempo > 4500000) //if inactive time variable reaches near 45sec*
-
{*
-
i=0; //zero key presses*
-
memset(inputArray,'\0',4); //clears the input array*
-
lcd.clear(); //clear lcd*
-
lcd.print("Enter password:"); //write message*
-
lcd.setCursor(0, 1); //put cursor on second line*
-
tempo=0; // zero inactive time variable*
-
}*
};