/*
|| Simple Password Entry Using Matrix Keypad
|| 4/5/2012 Updates Nathan Sobieck: Nathan@Sobisource.com
||
*/
//* is to validate password
//# is to reset password attempt
/////////////////////////////////////////////////////////////////
#include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip
Password password = Password( "1234" );
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 40, 41, 42, 43};// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 44, 45, 46, 47};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
#define ledpin1 7
#define ledpin2 6
void setup(){
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
pinMode(ledpin1,OUTPUT);
pinMode(ledpin2,OUTPUT);
}
void loop(){
keypad.getKey();
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:
Serial.print("Pressed: ");
Serial.println(eKey);
switch (eKey){
case '*': checkPassword(); break;
case '#': password.reset(); break;
default: password.append(eKey);
}
}
}
void checkPassword(){
if (password.evaluate()){
Serial.println("Success");
digitalWrite(ledpin1, HIGH);
delay(1500);
digitalWrite(ledpin1, LOW);
//Add code to run if it works
}else{
Serial.println("Wrong");
digitalWrite(ledpin2, HIGH);
delay(1000);
digitalWrite(ledpin2, LOW);
//add code to run if it did not work
}
}
/*
Made by Filip Ledoux
Versie 0.8 datum 3-3-2015
Deurslot met RFID lezer
Ingebouwd LCD display
Beldrukknop
codeklavier
* is to validate password
# is to reset password attempt
* Read a card using a mfrc522 reader on your SPI interface
* Pin layout should be as follows (on Arduino Uno):
* MOSI: Pin 11 / ICSP-4
* MISO: Pin 12 / ICSP-1
* SCK: Pin 13 / ISCP-3
* SS: Pin 10
* RST: Pin 9
*/
#include <Password.h> //http://www.arduino.cc/playground/uploads/Code/Password.zip
#include <Keypad.h> //http://www.arduino.cc/playground/uploads/Code/Keypad.zip
#include <SPI.h>
#include <RFID.h>
#include <LiquidCrystal.h>
#include "DHT.h"
DHT dht;
#define SS_PIN 48 //pin voor rfid lezer
#define RST_PIN 49 // pin voor rfid lezer
RFID rfid(SS_PIN,RST_PIN);
LiquidCrystal lcd(24, 25, 26, 27, 28, 29); // initialize the library with the numbers of the interface pins
/* aansluitpinnen voor LCD display on Arduino Mega
rs-24
e-25
d4-26
d5-27
d6-28
d7-29
r/w-gnd
*/
const int buttonPin = 39 ; // belddrukknop
const int belPin = 4; // relais 1 voor aansturen bel
int buttonState = 0; // variable for reading the pushbutton status
int poortPin = 3; //relais 2 voor aansturen poort
int ledrood = 6; // aanduiding geen toegang
int ledblauw = 5; // aanduiding call taken
int ledgroen = 7; // aanduiding toegang
Password password = Password( "1234" ); //ingesteld paswoord voor keypad
// definieren van grootte keypad 4 rijen en 4 kolomen
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap toetsenlayout
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 40, 41, 42, 43};// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 44, 45, 46, 47};// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int serNum[5];
// badgenummers met toelating
int cards[][5] = {
{81,105,47,97,118}, // losse tag
{84, 189, 141, 69, 33}, // losse tag
{113, 63, 33, 97, 14}, // losse tag
{241, 149, 60, 97, 57}, // losse tag
{194, 29, 2, 92, 129}, // badge nmbs
{44, 61, 123, 12, 102} // badge SAZ
};
bool access = false;
//************************************************************************************************************
void setup(){
Serial.begin(9600);
SPI.begin();
rfid.init();
dht.setup(32); //dht connection pin
pinMode(belPin, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(poortPin, OUTPUT);
pinMode(ledrood, OUTPUT);
pinMode(ledblauw, OUTPUT);
pinMode(ledgroen, OUTPUT);
}
//************************************************************************************************************
void loop(){
{
delay(dht.getMinimumSamplingPeriod());
float humidity = dht.getHumidity();
float temperature = dht.getTemperature();
lcd.begin(16,2);
lcd.setCursor(11,0);
lcd.print("h");
lcd.setCursor(12,0);
lcd.print(humidity,1);
lcd.setCursor(11,2);
lcd.print("t");
lcd.setCursor(12,2);
lcd.print(temperature,1);
}
{
// lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.setCursor(0,0);
lcd.print("Fam Ledoux");
}
//Inlezen status bel drukknop
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(belPin, HIGH); //indien niet ingedrukt relais 1 uit en led blauw uit
digitalWrite(ledblauw,LOW);
}
else {
digitalWrite(belPin, LOW); // indien ingedrukt relais 1 aan en led blauw aan
lcd.setCursor(0,1);
lcd.print("Call Taken");
digitalWrite(ledblauw,HIGH);
}
//Uitlezen van RFID met een lengte van 5 cijfers
if(rfid.isCard()){
if(rfid.readCardSerial()){
Serial.print(rfid.serNum[0]);
Serial.print(" ");
Serial.print(rfid.serNum[1]);
Serial.print(" ");
Serial.print(rfid.serNum[2]);
Serial.print(" ");
Serial.print(rfid.serNum[3]);
Serial.print(" ");
Serial.print(rfid.serNum[4]);
Serial.println("");
for(int x = 0; x < sizeof(cards); x++){
for(int i = 0; i < sizeof(rfid.serNum); i++ ){
if(rfid.serNum[i] != cards[x][i]) {
access = false;
break;
} else {
access = true;
}
}
if(access) break;
}
}
if(access){
lcd.setCursor(0,2);
lcd.print("Welkom");
digitalWrite(poortPin, LOW);
digitalWrite(ledgroen,HIGH);
delay(1000);
digitalWrite(poortPin, HIGH);
digitalWrite(ledgroen,LOW);
} else {
lcd.setCursor(0,2);
lcd.print("NO ENTRY");
digitalWrite(ledrood,HIGH);
delay(1000);
digitalWrite(ledrood,LOW);
}
}
rfid.halt();
}