"getID" was not declared in the scope error

Hello,

I have downloaded a code for a rfid code lock system and before making adjustments, all was fine. I changed some things, although nothing to do with the "getID process, yet I get an error with it. Check out the code after editing:

#include <Button.h>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#include <Relay.h>


#define RST_PIN   9
#define SS_PIN    10
byte readCard[4];
char* myTags[100] = {};
int tagsCount = 0;
String tagID = "";
boolean successRead = false;
boolean correctTag = false;
boolean doorOpened = false;
// Create instances
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Parameters: (rs, enable, d4, d5, d6, d7)
Relay solenoid(8,false); // Solenoid
Button lockac (12,PULLUP);
void setup() {
  // Initiating
  SPI.begin();        // SPI bus
  mfrc522.PCD_Init(); //  MFRC522
  lcd.begin(16, 2);   // LCD screen
  solenoid.begin();  // Solenoid
  pinMode(8,OUTPUT);
  // Prints the initial message
  lcd.print("-No Master Tag-");
  lcd.setCursor(0, 1);
  lcd.print("    Scan new card");
  // Waits until a master card is scanned
  while (!successRead) {
    successRead = getID();
    if ( successRead == true) {
      myTags[tagsCount] = strdup(tagID.c_str()); // Sets the master tag into position 0 in the array
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("-Master Tag Set-");
      tagsCount++;
    }
  }
  successRead = false;
  printNormalModeMessage();
}
void loop() {
  int proximitySensor = analogRead(A0);
  // If door is closed...
  if (lockac.isPressed()) {
    if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
      return;
    }
    if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
      return;
    }
    tagID = "";
    // The MIFARE PICCs that we use have 4 byte UID
    for ( uint8_t i = 0; i < 4; i++) {  //
      readCard[i] = mfrc522.uid.uidByte[i];
      tagID.concat(String(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
    }
    tagID.toUpperCase();
    mfrc522.PICC_HaltA(); // Stop reading
    correctTag = false;
    // Checks whether the scanned tag is the master tag
    if (tagID == myTags[0]) {
      lcd.clear();
      lcd.print("-Program mode-:");
      lcd.setCursor(0, 1);
      lcd.print("Add/Remove Tag");
      while (!successRead) {
        successRead = getID();
        if ( successRead == true) {
          for (int i = 0; i < 100; i++) {
            if (tagID == myTags[i]) {
              myTags[i] = "";
              lcd.clear();
              lcd.setCursor(0, 0);
              lcd.print("-Tag Removed-");
              printNormalModeMessage();
              return;
            }
          }
          myTags[tagsCount] = strdup(tagID.c_str());
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("-Tag Added-");
          printNormalModeMessage();
          tagsCount++;
          return;
        }
      }
    }
    successRead = false;
    // Checks whether the scanned tag is authorized
    for (int i = 0; i < 100; i++) {
      if (tagID == myTags[i]) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("-Access Granted-");
        solenoid.turnOn(); // Unlocks the door
        printNormalModeMessage();
        correctTag = true;
      }
    }
    if (correctTag == false) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("-Access Denied-");
      printNormalModeMessage();
    }
  }
  // If door is open...
  else {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Door Opened");
    lcd.setCursor(0, 1);
    lcd.print("Please Close");
    while (!doorOpened)
      if (lockac.isPressed) {
        doorOpened = false;
      }else doorOpened = true;
      }
    }
    doorOpened = false;
    delay(500);
    solenoid.turnOff(); // Locks the door
    printNormalModeMessage();
  }
}
uint8_t getID() {
  // Getting ready for Reading PICCs
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
    return 0;
  }
  tagID = "";
  for ( uint8_t i = 0; i < 4; i++) {  // The MIFARE PICCs that we use have 4 byte UID
    readCard[i] = mfrc522.uid.uidByte[i];
    tagID.concat(String(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
  }
  tagID.toUpperCase();
  mfrc522.PICC_HaltA(); // Stop reading
  return 1;
}
void printNormalModeMessage() {
  delay(1500);
  lcd.clear();
  lcd.print("-System Ready-");
  lcd.setCursor(0, 1);
  lcd.print("Scan Card");
}

There are two places where the "getID" code comes up, when setting up the master card and when scanning the master card. Does anybody have an idea of what's wrong? I am fairly new to IDE. Thanks a lot!

-Sam

By selecting Tools => Auto Format I can see this bit is wrong.

}
doorOpened = false;
delay(500);
solenoid.turnOff(); // Locks the door
printNormalModeMessage();
}
}
uint8_t getID() {

I think it should be:

  doorOpened = false;
  delay(500);
  solenoid.turnOff(); // Locks the door
  printNormalModeMessage();

}

set your IDE preferences to verbose to see more details. Can you copy the error message and post it here please?

Thank you for responding, Sherzaad.

Here are my error messages:

Arduino: 1.8.6 Hourly Build 2018/01/03 03:33 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\sj729\Documents\Arduino\RFID_4.0\RFID_4.0.ino: In function 'void setup()':

RFID_4.0:36: error: 'getID' was not declared in this scope

successRead = getID();

^

RFID_4.0:46: error: 'printNormalModeMessage' was not declared in this scope

printNormalModeMessage();

^

C:\Users\sj729\Documents\Arduino\RFID_4.0\RFID_4.0.ino: In function 'void loop()':

RFID_4.0:74: error: 'getID' was not declared in this scope

successRead = getID();

^

C:\Users\sj729\Documents\Arduino\RFID_4.0\RFID_4.0.ino:78:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myTags = "";

  • ^*
    RFID_4.0:82: error: 'printNormalModeMessage' was not declared in this scope
  • printNormalModeMessage();*
  • ^*
    RFID_4.0:90: error: 'printNormalModeMessage' was not declared in this scope
  • printNormalModeMessage();*
  • ^*
    RFID_4.0:104: error: 'printNormalModeMessage' was not declared in this scope
  • printNormalModeMessage();*
  • ^*
    RFID_4.0:112: error: 'printNormalModeMessage' was not declared in this scope
  • printNormalModeMessage();*
  • ^*
    RFID_4.0:123: error: cannot convert 'Button::isPressed' from type 'bool (Button::)()' to type 'bool'
  • if (lockac.isPressed) {*
  • ^*
    C:\Users\sj729\Documents\Arduino\RFID_4.0\RFID_4.0.ino: At global scope:
    RFID_4.0:128: error: 'doorOpened' does not name a type
  • doorOpened = false;*
  • ^*
    RFID_4.0:129: error: expected constructor, destructor, or type conversion before '(' token
  • delay(500);*
  • ^*
    RFID_4.0:130: error: 'solenoid' does not name a type
  • solenoid.turnOff(); // Locks the door*
  • ^*
    RFID_4.0:131: error: expected constructor, destructor, or type conversion before ';' token
  • printNormalModeMessage();*
  • ^*
    RFID_4.0:132: error: expected declaration before '}' token
  • }*
  • ^*
    Multiple libraries were found for "MFRC522.h"
    Used: C:\Users\sj729\Documents\Arduino\libraries\MFRC522
    Not used: C:\Users\sj729\Downloads\arduino-nightly\libraries\MFRC522
    Multiple libraries were found for "LiquidCrystal.h"
    Used: C:\Users\sj729\Downloads\arduino-nightly\libraries\LiquidCrystal
    Not used: C:\Users\sj729\Downloads\arduino-nightly\libraries\LiquidCrystal_I2C
    Multiple libraries were found for "Relay.h"
    Used: C:\Users\sj729\Documents\Arduino\libraries\Relay
    Not used: C:\Users\sj729\Downloads\arduino-nightly\libraries\Relay
    exit status 1
    'getID' was not declared in this scope
    Invalid library found in C:\Users\sj729\Documents\Arduino\libraries\Relay-1.0.0: C:\Users\sj729\Documents\Arduino\libraries\Relay-1.0.0
    Invalid library found in C:\Users\sj729\Documents\Arduino\libraries\Relay-1.0.0: C:\Users\sj729\Documents\Arduino\libraries\Relay-1.0.0
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    Thank you again!
    -Sam

Your curly braces are messed up - I think you have one function closed before you should and another function is not closed at all.

not declared in this scope errors for functions that you've declared are almost always problems with the curly braces somewhere above the function declaration, such that the function is not declared in a place where it is valid to do so.

looks like indeed you have one or more curly brackets in the wrong place as suggested by 'Blue Eyes'

had I look at you code again and I think this should fix it (sorry me can't compile it since I done have all the libraries you using! )

#include <Button.h>
#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#include <Relay.h>


#define RST_PIN   9
#define SS_PIN    10
byte readCard[4];
char* myTags[100] = {};
int tagsCount = 0;
String tagID = "";
boolean successRead = false;
boolean correctTag = false;
boolean doorOpened = false;
// Create instances
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Parameters: (rs, enable, d4, d5, d6, d7)
Relay solenoid(8, false); // Solenoid
Button lockac (12, PULLUP);
void setup() {
  // Initiating
  SPI.begin();        // SPI bus
  mfrc522.PCD_Init(); //  MFRC522
  lcd.begin(16, 2);   // LCD screen
  solenoid.begin();  // Solenoid
  pinMode(8, OUTPUT);
  // Prints the initial message
  lcd.print("-No Master Tag-");
  lcd.setCursor(0, 1);
  lcd.print("    Scan new card");
  // Waits until a master card is scanned
  while (!successRead) {
    successRead = getID();
    if ( successRead == true) {
      myTags[tagsCount] = strdup(tagID.c_str()); // Sets the master tag into position 0 in the array
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("-Master Tag Set-");
      tagsCount++;
    }
  }
  successRead = false;
  printNormalModeMessage();
}
void loop() {
  int proximitySensor = analogRead(A0);
  // If door is closed...
  if (lockac.isPressed()) {
    if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
      return;
    }
    if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
      return;
    }
    tagID = "";
    // The MIFARE PICCs that we use have 4 byte UID
    for ( uint8_t i = 0; i < 4; i++) {  //
      readCard[i] = mfrc522.uid.uidByte[i];
      tagID.concat(String(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
    }
    tagID.toUpperCase();
    mfrc522.PICC_HaltA(); // Stop reading
    correctTag = false;
    // Checks whether the scanned tag is the master tag
    if (tagID == myTags[0]) {
      lcd.clear();
      lcd.print("-Program mode-:");
      lcd.setCursor(0, 1);
      lcd.print("Add/Remove Tag");
      while (!successRead) {
        successRead = getID();
        if ( successRead == true) {
          for (int i = 0; i < 100; i++) {
            if (tagID == myTags[i]) {
              myTags[i] = "";
              lcd.clear();
              lcd.setCursor(0, 0);
              lcd.print("-Tag Removed-");
              printNormalModeMessage();
              return;
            }
          }
          myTags[tagsCount] = strdup(tagID.c_str());
          lcd.clear();
          lcd.setCursor(0, 0);
          lcd.print("-Tag Added-");
          printNormalModeMessage();
          tagsCount++;
          return;
        }
      }
    }
    successRead = false;
    // Checks whether the scanned tag is authorized
    for (int i = 0; i < 100; i++) {
      if (tagID == myTags[i]) {
        lcd.clear();
        lcd.setCursor(0, 0);
        lcd.print("-Access Granted-");
        solenoid.turnOn(); // Unlocks the door
        printNormalModeMessage();
        correctTag = true;
      }
    }
    if (correctTag == false) {
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("-Access Denied-");
      printNormalModeMessage();
    }
  }
  // If door is open...
  else {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Door Opened");
    lcd.setCursor(0, 1);
    lcd.print("Please Close");
    while (!doorOpened) { //<---- added a curly bracket here
      if (lockac.isPressed) {
        doorOpened = false;
      } else doorOpened = true;
      //} <---- removed a curly bracket here
    }
    doorOpened = false;
    delay(500);
    solenoid.turnOff(); // Locks the door
    printNormalModeMessage();
  }
}
uint8_t getID() {
  // Getting ready for Reading PICCs
  if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
    return 0;
  }
  if ( ! mfrc522.PICC_ReadCardSerial()) {   //Since a PICC placed get Serial and continue
    return 0;
  }
  tagID = "";
  for ( uint8_t i = 0; i < 4; i++) {  // The MIFARE PICCs that we use have 4 byte UID
    readCard[i] = mfrc522.uid.uidByte[i];
    tagID.concat(String(mfrc522.uid.uidByte[i], HEX)); // Adds the 4 bytes in a single String variable
  }
  tagID.toUpperCase();
  mfrc522.PICC_HaltA(); // Stop reading
  return 1;
}
void printNormalModeMessage() {
  delay(1500);
  lcd.clear();
  lcd.print("-System Ready-");
  lcd.setCursor(0, 1);
  lcd.print("Scan Card");
}

Thank you guys so much for all your help! Sherzaad- I tried your code and it fixed the original error! However, now I have a problem with my button (nicknamed lockac). The button, when pressed, is supposed to lock the door. Here are my current problems:

Arduino: 1.8.6 Hourly Build 2018/01/03 03:33 (Windows 10), Board: "Arduino/Genuino Uno"

C:\Users\sj729\Documents\Arduino\RFID_4.0_Revised\RFID_4.0_Revised.ino: In function 'void loop()':

C:\Users\sj729\Documents\Arduino\RFID_4.0_Revised\RFID_4.0_Revised.ino:77:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]

myTags = "";

  • ^*
    RFID_4.0_Revised:122: error: cannot convert 'Button::isPressed' from type 'bool (Button::)()' to type 'bool'
  • if (lockac.isPressed) {*
  • ^*
    Multiple libraries were found for "MFRC522.h"
    Used: C:\Users\sj729\Documents\Arduino\libraries\MFRC522
    Not used: C:\Users\sj729\Downloads\arduino-nightly\libraries\MFRC522
    Multiple libraries were found for "LiquidCrystal.h"
    Used: C:\Users\sj729\Downloads\arduino-nightly\libraries\LiquidCrystal
    Not used: C:\Users\sj729\Documents\Arduino\libraries\Newliquidcrystal_1.3.5
    Not used: C:\Users\sj729\Downloads\arduino-nightly\libraries\LiquidCrystal_I2C
    Multiple libraries were found for "Relay.h"
    Used: C:\Users\sj729\Documents\Arduino\libraries\Relay
    Not used: C:\Users\sj729\Downloads\arduino-nightly\libraries\Relay
    exit status 1
    cannot convert 'Button::isPressed' from type 'bool (Button::)()' to type 'bool'
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    Thanks again for helping me our at this late hour.
    -Sam

I think "lockac.isPressed" should be written as "lockac.isPressed()"

Thank you all so much! It worked without error! I appreciate the time you all took to help.

-Sam