0

I'm trying to create a security door system that uses an RFID and fingerprint sensor (Adafruit) to allow/deny access to a door. I have the fingerprint sensor and RFID hooked up to an LED, but the code isn't working very well. I want the LED to light only and only when both fingerprints and RFID are verified. Here is my preliminary code.

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

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
  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...");
  }

}

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



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

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

  }

And this is the error 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.

I am new to this so please bear with me and explain in childish manner if possible.

  • Welcome to Arduino SE. Please take the tour at arduino.stackexchange.com/Tour. And btw, when you put in code, just make sure you have one blank line at the top then enter the code with 4 spaces at the beginning of each line. It is much more readable that way. – SDsolar May 6 '17 at 18:44
  • 1
    Looks like your switch statement is outside a function declaration. – Mazaryk May 7 '17 at 1:42
1

Can't say I have read what you posted here or what you're trying to do, however nonetheless I have fixed the errors in your post. This will compile no problem. Good luck with your project.

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
int getFingerprintIDez();
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

//HEADERFILES
#include <SPI.h> //rfid 
#include <MFRC522.h>//rfid 
#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

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

void setup() {
  //RFID setup
  finger.begin(57600);
  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)
  SPI.begin(); // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522 RFID
  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...");
  }
}

// OK success!

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

  // 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");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
}
1
default:
  Serial.println("Unknown error");
  return p;
}
} <-- Why?

Proper indentation shows that you have an extraneous closing curly brace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.