[CODE HELP] Fingerprint/RFID door

Hello guys im trying to create a security door system which uses an rfid and fingerprint sensor (adafruit) to allow/deny access to a door system. For now i have the door set as an led being that i didn't build the door yet. Im having some problems with the code. Basically i want the door to OPEN ONLY when both rfid and fingerpint is verified if not stay locked. Im having some problems with the code. When i try to compile it i get an error. Here i the preliminary sketch i have. I tried to combine the codes which came with the rfid and finger sensor to compile this code. Please help me out here.

//HEADERFILES 
#include <SPI.h> //rfid 
#include <MFRC522.h>//rfid 
#include <Adafruit_Fingerprint.h> //FINGERPRINT
#include <SoftwareSerial.h> //FINGERPRINT
#include<stdint.h> //FINGERPRINT



//rfid settings
#define RST_PIN         9          // rfid pin 9 RST_pin
#define SS_PIN          10         // rfid pin 10 SS_pin

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

String read_rfid;
String ok_rfid_1= "cbb427b2"; //white card
String ok_rfid_2="0ebb14f39"; //blue key chain

//fingerprint settings

int getFingerprintIDez();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (YELLOW wire)

SoftwareSerial mySerial(2, 3);  //activates serial communication on pin 2 & 3

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

//output garage door pin

int door = 7; //motor to door
 

 
void setup(){
//RFID setup

  Serial.begin(9600);   // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  finger.begin(57600);
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522 rfid


void dump_byte_array(byte * buffer , byte bufferSize){  //why so important
read_rfid=""; 
for (byte i=0; i< bufferSize; i++) {
    read_rfid=read_rfid + String(buffer[i], HEX);
  }
}

pinMode (door, OUTPUT);


//FINGERPRINT setup
 {
  while (!Serial);  // For Yun/Leo/Micro/Zero/...

 if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}



//DOOR/OUTPUT PIN PROPERTIES CHANGE TO REFLECT HOW FAST AND HOW LONG MOTOR PULLS DOOR USING DIGITALWRITE; BREAK..   //USING LED FOR NOW 
       
void open_door(){  
digitalWrite (door, HIGH);
delay (2000);
digitalWrite (door, LOW);
}
}

void loop() {
// RFID LOOP SETTINGS                                                   `
  if ( ! mfrc522.PICC_IsNewCardPresent()) {     // Look for new cards
    return;
  }  
  if ( ! mfrc522.PICC_ReadCardSerial()) {       // Select one of the c ards
    return;
  }
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println(read_rfid);
// FINGERPRINT LOOP SETTINGS
{
  getFingerprintID();  // start fingerprint sensor    
   delay(100);
 }
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;
  }


p = finger.fingerFastSearch();
      if (p == FINGERPRINT_OK && read_rfid == ok_rfid_1){
  Serial.println(ok_rfid_1);
   open_door();
      }
      
}

You need to tell us about the error messages you got. They contain important clues.

Also, it's better if you post your code, in tags so it looks like this:

//HEADERFILES 
#include <SPI.h> //rfid 
#include <MFRC522.h>//rfid 
#include <Adafruit_Fingerprint.h> //FINGERPRINT
#include <SoftwareSerial.h> //FINGERPRINT
#include<stdint.h> //FINGERPRINT



//rfid settings
#define RST_PIN         9          // rfid pin 9 RST_pin
#define SS_PIN          10         // rfid pin 10 SS_pin

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

String read_rfid;
String ok_rfid_1= "cbb427b2"; //white card
String ok_rfid_2="0ebb14f39"; //blue key chain

//fingerprint settings

int getFingerprintIDez();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (YELLOW wire)

SoftwareSerial mySerial(2, 3);  //activates serial communication on pin 2 & 3

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

//output garage door pin

int door = 7; //motor to door
 

 
void setup(){
//RFID setup

  Serial.begin(9600);   // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  finger.begin(57600);
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522 rfid


void dump_byte_array(byte * buffer , byte bufferSize){  //why so important
read_rfid=""; 
for (byte i=0; i< bufferSize; i++) {
    read_rfid=read_rfid + String(buffer[i], HEX);
  }
}

pinMode (door, OUTPUT);


//FINGERPRINT setup
 {
  while (!Serial);  // For Yun/Leo/Micro/Zero/...

 if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}



//DOOR/OUTPUT PIN PROPERTIES CHANGE TO REFLECT HOW FAST AND HOW LONG MOTOR PULLS DOOR USING DIGITALWRITE; BREAK..   //USING LED FOR NOW 
       
void open_door(){  
digitalWrite (door, HIGH);
delay (2000);
digitalWrite (door, LOW);
}
}

void loop() {
// RFID LOOP SETTINGS                                                   `
  if ( ! mfrc522.PICC_IsNewCardPresent()) {     // Look for new cards
    return;
  }  
  if ( ! mfrc522.PICC_ReadCardSerial()) {       // Select one of the c ards
    return;
  }
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println(read_rfid);
// FINGERPRINT LOOP SETTINGS
{
  getFingerprintID();  // start fingerprint sensor    
   delay(100);
 }
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;
  }


p = finger.fingerFastSearch();
      if (p == FINGERPRINT_OK && read_rfid == ok_rfid_1){
  Serial.println(ok_rfid_1);
   open_door();
      }
      
}

This is the error which i am getting.

Arduino: 1.8.1 (Windows 10), Board: "Arduino/Genuino Uno"

fingerprint:127: error: expected unqualified-id before '{' token

 {

 ^

exit status 1
expected unqualified-id before '{' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Where does getFingerprintID() end? Why do you have code after that?

the code after that is the default which came with the libraries thats pasted from there. The only portion of that which is mine is towards the end which is the way of saying if the led and fingerprint are good to turn led on. is there things i dont need in the code ?

p = finger.fingerFastSearch();
      if (p == FINGERPRINT_OK && read_rfid == ok_rfid_1){
  Serial.println(ok_rfid_1);
   open_door();
      }

is there things i dont need in the code ?

No. But, if you are going to add information to a book, you don't write on the desk that the book is laying on, and expect the information to be in the book when you put it away, do you?

No. You write IN the book. You add code IN the function, not after the end of the function.

I'm not very familiar with coding my friend I'm in need of some learning I know.
So what your indicating is that all those functions belong in the setup not loop?
Please guide me . I've read and tried a lot nothing seems to compile without an error

PaulS:
No. But, if you are going to add information to a book, you don't write on the desk that the book is laying on, and expect the information to be in the book when you put it away, do you?

No. You write IN the book. You add code IN the function, not after the end of the function.

So add it in the Setup ?

So add it in the Setup ?

Or loop() or some other function. Wherever it is appropriate to put the code.

Ok so i pretty much got everything to work out the way i want it to but now the led only turns on when the rfid card is directly on the scanner. The fingerprint sensor is only active when the card is directly infront. My intent was to Scan the card and than scan in the fingerprint directly after. Here's is the code so far and note that i put in the functions for open and close door so its is n longer an led.

//HEADERFILES 
#include <SPI.h> //rfid 
#include <MFRC522.h>//rfid 
#include <Adafruit_Fingerprint.h> //FINGERPRINT
#include <SoftwareSerial.h> //FINGERPRINT
#include<stdint.h> //FINGERPRINT



//rfid settings
#define RST_PIN         9          // rfid pin 9 RST_pin
#define SS_PIN          10         // rfid pin 10 SS_pin

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

String read_rfid;
String ok_rfid_1= "cbb427b2"; //white card
String ok_rfid_2="0ebb14f39"; //blue key chain

//fingerprint settings

int getFingerprintIDez();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (YELLOW wire)

SoftwareSerial mySerial(2, 3);  //activates serial communication on pin 2 & 3

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial); 

//output garage door pin

int door = 7; //motor to door
 

void dump_byte_array(byte * buffer , byte bufferSize){  //why so important
read_rfid=""; 
for (byte i=0; i< bufferSize; i++) {
    read_rfid=read_rfid + String(buffer[i], HEX);
}
}
 

//RFID setup

void setup(){


  Serial.begin(9600);   // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  finger.begin(57600);
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522 rfid
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
pinMode (door, OUTPUT);
}
//FINGERPRINT setup
void setup1()
{
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  
  Serial.begin(9600);
  Serial.println("Adafruit finger detect test");

  // 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);
  }
  Serial.println("Waiting for valid finger...");
}



//DOOR/OUTPUT PIN PROPERTIES CHANGE TO REFLECT HOW FAST AND HOW LONG MOTOR PULLS DOOR USING DIGITALWRITE; BREAK..   //USING LED FOR NOW 
       
void open_door(){  
digitalWrite (door, HIGH);
delay (2000);
digitalWrite (door, LOW);
}


void loop(){
// RFID LOOP SETTINGS                                                   `
    // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  // Dump debug info about the card; PICC_HaltA() is automatically called
  mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
void loop1()

{
  getFingerprintIDez();  // start fingerprint sensor    
 delay(100);
}
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;
  }
      
      {
 p = finger.fingerFastSearch();
      if (p == FINGERPRINT_OK && read_rfid == ok_rfid_1 || ok_rfid_2 ){
  Serial.println("access granted");
   open_door(); 
      }
      }
}

I tried separating the line

 p = finger.fingerFastSearch();
      if (p == FINGERPRINT_OK && read_rfid == ok_rfid_1 || ok_rfid_2 ){
  Serial.println("access granted");
   open_door();

with two if statements one for rfid and one for fingerprint to no success any help plz?

My intent was to Scan the card and than scan in the fingerprint directly after.

Then, why didn't you write the code that way?

That example you started from is garbage. Complete garbage.

The loop() function should NOT be bypassed just because there is no card present. Only a complete moron would have written the code so the Arduino could no NOTHING unless a card was present.

You'll need to rewrite that code, so that loop() CAN do something if there is a card present AND if there is not a card present.

You need to separate reading the RFID card from reading the fingerprint scanner.

You need to create a boolean, cardScanned, initialized to false. When a card is presented, and is valid, set cardScanned to true.

Only bother reading the fingerprint scanner when cardScanned is true.

You'll need to figure out when to set cardScanned to false. Likely times are after a fingerprint is scanned or after it has been true for a reasonable period of time.

Like i said buddy im not great at this so can you please help me with the reformatting and basics of the boolean and state. Ill takie it from there

PaulS:
Then, why didn't you write the code that way?

That example you started from is garbage. Complete garbage.

The loop() function should NOT be bypassed just because there is no card present. Only a complete moron would have written the code so the Arduino could no NOTHING unless a card was present.

You'll need to rewrite that code, so that loop() CAN do something if there is a card present AND if there is not a card present.

You need to separate reading the RFID card from reading the fingerprint scanner.

You need to create a boolean, cardScanned, initialized to false. When a card is presented, and is valid, set cardScanned to true.

Only bother reading the fingerprint scanner when cardScanned is true.

You'll need to figure out when to set cardScanned to false. Likely times are after a fingerprint is scanned or after it has been true for a reasonable period of time.

I followed your advice as best as i can, Yet the fingerprint sesnor is still lighting olny one brief second the not staying on.

 if (read_rfid == ok_rfid_1 || read_rfid==ok_rfid_2)
 CardScanned= true;
  while (CardScanned= true);
  {
    p = finger.fingerFastSearch();
    
      if (p == FINGERPRINT_OK)
      {
          open_door(); 
         delay (4000); 
         close_door();
       
      }
  else if
  (p == FINGERPRINT_NOTFOUND) 
        {
          CardScanned=false;
          return p;
        }
      else
        {    return p;   } 
        }

PS: understand im learning here no need to call me a moron. No one is born with talent like you.

OK thanks for the advice buddy. I fixed that little issue up. Heres the code now. It gives me no errrs when compiling but i wont be able to test it until tomorrow. any issues you can see? syntax wise

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include<stdint.h>
#include <SPI.h>
#include <MFRC522.h>


boolean CardScanned = false;
int timer = 4000;
//-----bluetooth-settings//
SoftwareSerial bluetooth(4, 8);

int getFingerprintIDez();

//---------RFID ------------------------------------------------------------------------------------------------------//
#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

String read_rfid;
String ok_rfid_1 = "cbb427b2"; //card
String ok_rfid_2 = "0ebb14f39"; //key chain
//--------Fingerprint-------------------------------------------------------------------------//

// pin #2(A5)is IN from sensor (GREEN wire)
// pin #3(A4) is OUT from arduino  (YELLOW wire)

SoftwareSerial mySerial(A5, A4 );  //activates serial communication on pin A5 & A4

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()
{
  pinMode( 6, OUTPUT); // Using pin 6 for the 'enable' on the H bridge IC.
  pinMode( 3, OUTPUT); // Using pin 3 for the 'input 1' on the H bridge IC.
  pinMode( 5, OUTPUT); // Using pin 5 for the 'input 2' on the H bridge IC.

  Serial.begin(9600);      // initialize the serial communications:

  finger.begin(57600);      // set the data rate for the sensor serial port

  while (!Serial);    // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init

  //-----Bluetooth-----//
  Serial.println("Welcome. This a system designed to use a two step verification to allow enetry to a door/garage. It will utilize an RFID (white card/blue chip) as means to verfiy the user. If both ways are verified the door will open otherwise it wewill not");

  pinMode(4, INPUT);
  pinMode(5, OUTPUT);

  bluetooth.begin(9600);
  bluetooth.println("Bluetooth is activated.");

}

void dump_byte_array(byte * buffer , byte bufferSize) { ///why so important
  read_rfid = "";
  for (byte i = 0; i < bufferSize; i++) {
    read_rfid = read_rfid + String(buffer[i], HEX);
  }
}

//-----------DOOR Properties-----------------//
// The motor will rotate in the right direction.
void open_door() {
  digitalWrite( 6, HIGH); // Command stating that the enable will always be on. When enable is on, commands can be processed to input 1 & 2.
  digitalWrite( 3, LOW); // Command that input 1 is given no current
  digitalWrite( 5, HIGH); // Command that input 2 has current.
  analogWrite( 6, 225); // motor will rotate at a speed with a duty cycle of 80.
  delay(30000); // Commands will be continious for three seconds.

  // Commands will cause the motor to break for three seconds

  digitalWrite( 6, HIGH);
  digitalWrite( 3, HIGH); // Current is provided to input 1.
  digitalWrite( 5, HIGH); // Current is provided to input 2.
  delay(3000);

}

void close_door()
{
  // The motor will rotate in the left direction.
  digitalWrite( 6, HIGH);
  digitalWrite( 3, HIGH); // Command that input 1 has current
  digitalWrite( 5, LOW); // Command that input 2 is given no current.
  analogWrite( 6, 225); // motor will rotate at a speed with a duty cycle of 200.
  delay(3000);

  digitalWrite( 6, HIGH);
  digitalWrite( 3, HIGH); // Current is provided to input 1.
  digitalWrite( 5, HIGH); // Current is provided to input 2.

  digitalWrite( 6, LOW); // Enable is off.
  delay(10000); // No current will be provided to the circuit for ten seconds.
}

void loop()
{
  // Look for new cards`
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);

  getFingerprintID();
  delay(100);

}

uint8_t getFingerprintID()
{
  uint8_t p = finger.getImage();

  switch (p)
  {
    case FINGERPRINT_OK:
      break;
    case FINGERPRINT_NOFINGER:
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      return p;
    case FINGERPRINT_IMAGEFAIL:
      return p;
    default:
      return p;
  }

  // OK success!
  p = finger.image2Tz();
  switch (p)
  {
    case FINGERPRINT_OK:
      break;
    case FINGERPRINT_IMAGEMESS:
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      return p;
    case FINGERPRINT_FEATUREFAIL:
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      return p;
    default:
      return p;
  }

  // OK converted!

  if (read_rfid == ok_rfid_1 || read_rfid == ok_rfid_2) {
    CardScanned = true;
    while (CardScanned == true)
    {
      p = finger.fingerFastSearch();

      if (p == FINGERPRINT_OK)
      {
        open_door();
        delay (4000);
        close_door();

      }
      else if
      (p == FINGERPRINT_NOTFOUND)
      {
        CardScanned = false;
        return p;
      }
      else
      {
        return p;
      }
    }
  }
  else
  {
    Serial.println("wrong card");
  }

}

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

}