element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum I was wondering if someone could look over this code?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 2 replies
  • Subscribers 416 subscribers
  • Views 343 views
  • Users 0 members are here
  • arduino
Related

I was wondering if someone could look over this code?

e14 Contributor
e14 Contributor over 12 years ago

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; 
}

  • Sign in to reply
  • Cancel
Parents
  • e14 Contributor
    0 e14 Contributor over 12 years ago

    PLEASE DISREGARD

    const int [p


    that can be deleted

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • e14 Contributor
    0 e14 Contributor over 12 years ago

    PLEASE DISREGARD

    const int [p


    that can be deleted

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • e14 Contributor
    0 e14 Contributor over 12 years ago in reply to e14 Contributor

    same with pinMode(buttonPin, INPUT); ,  const int buttonPin = 2;   and any thing else regarding a button

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube