I want it to control a solenoid with an Arduino. If the correct pass key is entered of a valid finger is used, I want it to print on a LCD access granted, and unlock the door. If not, I want the LCD to say "Access Denied" and stay locked. When their is nothing, I want it to say "Henry's Workroom", with the time displayed below. All the hardware, I'm pretty confident on, I'm using a Arduino Mega so don't worry about the abundance of pins being used.
#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include <Password.h>
#include <Keypad.h>
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
RTC_DS1307 RTC;
LiquidCrystal lcd(15, 14, 13, 12, 11, 10);
int getFingerprintIDez();
const int lockPin = 18;
const int lcdRed = 15;
const int lcdGreen = 16;
const int lcdBlue = 17;
const int buttonPin = 2;
const int [p
int buttonState = 0;
// pin #1 is IN from sensor (GREEN wire)
// pin #2 is OUT from arduino (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(1, 2);
#else
NewSoftSerial mySerial(1, 2);
#endif
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
Password password = Password( "1234" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = { 9,8,7,6 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte colPins[COLS] = { 5,4,3 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
pinMode(lockPin, OUTPUT);
pinMode(lcdRed, OUTPUT);
pinMode(lcdGreen, OUTPUT);
pinMode(lcdBlue, OUTPUT);
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
Serial.begin(9600);
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
Serial.println("fingertest");
// set the data rate for the sensor serial port
finger.begin(57600);
if (finger.verifyPassword()) {
Serial.println("Found fingerprint sensor!");
} else {
Serial.println("Did not find fingerprint sensor :(");
while (1);
}
DateTime now = RTC.now();
Serial.println("Waiting for valid finger...");
lcd.noCursor();
lcd.clear();
lcd.print("HENRYS WORK ROOM");
lcd.setCursor(5, 1);
lcd.print(now.hour(), DEC);
lcd.setCursor(7, 1);
lcd.print(":");
lcd.print(now.minute(), DEC);
digitalWrite(lcdRed, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdBlue, HIGH);
digitalWrite(lockPin, HIGH);
}
void loop() // run over and over again
{
getFingerprintIDez();
keypad.getKey();
buttonState = digitalRead(buttonPin);
}
//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");
//Add code to run if it works
DateTime now = RTC.now();
lcd.clear();
lcd.print("ACCESS GRANTED");
digitalWrite(lcdRed, LOW);
digitalWrite(lcdBlue, LOW);
digitalWrite(lcdGreen, HIGH);
digitalWrite(lockPin, LOW);
delay(10000);
lcd.clear();
digitalWrite(lockPin, HIGH);
lcd.print("HENRYS WORK ROOM");
lcd.setCursor(5, 1);
lcd.print(now.hour(), DEC);
lcd.setCursor(7, 1);
lcd.print(":");
lcd.print(now.minute(), DEC);
digitalWrite(lcdRed, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdBlue, HIGH);
}else{
DateTime now = RTC.now();
Serial.println("Wrong");
lcd.clear();
lcd.print("ACCESS DENIED");
digitalWrite(lcdBlue, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdRed, HIGH);
digitalWrite(lockPin, HIGH);
delay(10000);
lcd.clear();
lcd.print("HENRYS WORK ROOM");
lcd.setCursor(5, 1);
lcd.print(now.hour(), DEC);
lcd.setCursor(7, 1);
lcd.print(":");
lcd.print(now.minute(), DEC);
digitalWrite(lcdRed, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdBlue, HIGH);
digitalWrite(lockPin, HIGH);
}
}
uint8_t getFingerprintID() {
uint8_t p = finger.getImage();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
Serial.println("No finger detected");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK success!
p = finger.image2Tz();
switch (p) {
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}
// OK converted!
p = finger.fingerFastSearch();
if (p == FINGERPRINT_OK) {
Serial.println("Found a print match!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR) {
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_NOTFOUND) {
Serial.println("Did not find a match");
DateTime now = RTC.now();
Serial.println("Wrong");
lcd.clear();
lcd.print("ACCESS DENIED");
digitalWrite(lcdBlue, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdRed, HIGH);
digitalWrite(lockPin, HIGH);
delay(10000);
lcd.clear();
lcd.print("HENRYS WORK ROOM");
lcd.setCursor(5, 1);
lcd.print(now.hour(), DEC);
lcd.setCursor(7, 1);
lcd.print(":");
lcd.print(now.minute(), DEC);
digitalWrite(lcdRed, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdBlue, HIGH);
digitalWrite(lockPin, HIGH);
return p;
} else {
Serial.println("Unknown error");
DateTime now = RTC.now();
Serial.println("Wrong");
lcd.clear();
lcd.print("Unknown error");
digitalWrite(lcdBlue, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdRed, HIGH);
digitalWrite(lockPin, HIGH);
delay(10000);
lcd.clear();
lcd.print("HENRYS WORK ROOM");
lcd.setCursor(5, 1);
lcd.print(now.hour(), DEC);
lcd.setCursor(7, 1);
lcd.print(":");
lcd.print(now.minute(), DEC);
digitalWrite(lcdRed, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdBlue, HIGH);
digitalWrite(lockPin, HIGH);
return p;
}
// found a match!
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
}
// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
uint8_t p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
DateTime now = RTC.now();
lcd.clear();
lcd.print("ACCESS GRANTED");
digitalWrite(lcdRed, LOW);
digitalWrite(lcdBlue, LOW);
digitalWrite(lcdGreen, HIGH);
digitalWrite(lockPin, LOW);
delay(10000);
lcd.clear();
digitalWrite(lockPin, LOW);
lcd.print("HENRYS WORK ROOM");
lcd.setCursor(5, 1);
lcd.print(now.hour(), DEC);
lcd.setCursor(7, 1);
lcd.print(":");
lcd.print(now.minute(), DEC);
digitalWrite(lcdRed, LOW);
digitalWrite(lcdGreen, LOW);
digitalWrite(lcdBlue, HIGH);
digitalWrite(lockPin, HIGH);
Serial.print("Found ID #"); Serial.print(finger.fingerID);
Serial.print(" with confidence of "); Serial.println(finger.confidence);
return finger.fingerID;
}