RFID library and getID() help

Hi,
I am making a project with a keypad, RFID scanner, a servo and an LCD screen.
I have used the MFRC522 library and used the getID() code.
My code is attached below.
Any help appreciated.
Thanks.

PS The website I got the library from is here

#include <Arduino.h>
#include <stdint.h>
#include <Keypad.h>
#include <SPI.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <MFRC522.h>
#include <Wire.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;
int proximitySensor;
boolean doorOpened = false;

const byte ROWS = 4;
const byte COLS = 4;

MFRC522 mfrc522(SS_PIN, RST_PIN);
Servo myServo;
LiquidCrystal_I2C lcd(0x21, 16, 2);

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {8, 7, 6, s5};
byte colPins[COLS] = {4, 3, 2, 1};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  myServo.attach(0);
  myServo.write(10);

  lcd.backlight();
  lcd.init();

  lcd.setCursor(0, 0);
  lcd.print("Initiating...");
  delay(5000);

  lcd.print("-No Master Tag!-");
  lcd.setCursor(0, 1);
  lcd.print("    SCAN NOW");

  while (!successRead) {
    successRead = getID();                                      //CHECK THIS [getID()]
    if ( successRead == true) {
      myTags[tagsCount] = strdup(tagID.c_str());
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Master Tag Set!");
      tagsCount++;
    }
  }
  successRead = false;

  delay(5000);
  lcd.setCursor(0, 0);
  lcd.print("   Enter New");
  lcd.setCursor(0, 1);
  lcd.print("   Password:");

  char customKey = customKeypad.getKey();
  if (customKey) {
    Data[data_count] = customKey;
    lcd.setCursor(data_count, 1);
    lcd.print(Data[data_count]);
    data_count++;
  }

  if (data_count == Password_Length - 1) {
    lcd.clear();
  }

  lcd.setCursor(0, 0);
  lcd.print("---Initiation---");
  lcd.setCursor(0, 1);
  lcd.print("----Complete----");
  delay(5000);
  startUp();

  uint8_t getID() {
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
      return 0;
    }
    if ( ! mfrc522.PICC_ReadCardSerial()) {
      return 0;
    }
    tagID = "";
    for ( uint8_t i = 0; i < 4; i++) {
      readCard[i] = mfrc522.uid.uidByte[i];
      tagID.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    tagID.toUpperCase();
    mfrc522.PICC_HaltA();
    return 1;
  }

  int proximitySensor = analogRead(A0);
}

void loop() {
  if (!strcmp(Data, Master));
  lcd.setCursor(0, 0);
  lcd.print("Correct Keycode!");
  myServo.write(180);
  delay(5000);
  startUp();
}
else {
  lcd.clear
  lcd.setCursor(0, 0);
  lcd.print("-Incorrect Code-");
  delay(2500);
  startUp();
}

lcd.clear();
clearData();
}
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!");
          startUp();
          return;
        }
      }
      myTags[tagsCount] = strdup(tagID.c_str());
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("   Tag Added!");
      startUp();
      tagsCount++;
      return;
    }
  }
}
for (int i = 0; i < 100; i++) {
  if (tagID == myTags[i]) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Access Granted!");
    myServo.write(180);
    startUp();
    correctTag = true;
  }
}
if (correctTag == false) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Access Denied!");
  startUp();
}
}
// If door is open...
else {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Door Opened!");
  while (!doorOpened) {
    proximitySensor = analogRead(A0);
    if (proximitySensor > 200) {
      doorOpened = true;
    }
  }
  doorOpened = false;
  delay(500);
  myServo.write(10);
  startUp();
}
}

void startUp() {
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Enter Password: ");
  lcd.setCursor(0, 1);
  lcd.print("--OR SCAN TAG!--");
  myServo.write(10);
}

void clearData() {
  while (data_count != 0) {
    Data[data_count--] = 0;
  }
  return;
}

In the future, please use code tags (</> button on the toolbar) instead of quote tags (speech bubble button on the toolbar) when you post code. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn’t show the posting toolbar then you can just manually add the code tags:
[code]``[color=blue]// your code is here[/color]``[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.

What do you want help with?

Hi,
I have changed it.
I am trying to make a door locking system.
If the correct password is put in the 4x4 keypad, then it should open, and lock with the servo when the proximity sensor receives info that the door is closed. The RFID scanner should set a master tag, where it can add or remove tags that can be used. If the correct tag is used, then the door will open, but if not, then it will close.
The getID code is not working, so I am wondering if you could help me.
Thanks.

The last line of getID():

daniel_dim_15:

  int proximitySensor = analogRead(A0);

Creates a local variable named proximitySensor. That variable is discarded as soon as the function returns. If you instead wanted to change the value of the global variable proximitySensor you would instead do this:

  proximitySensor = analogRead(A0);

Yes,
But it comes up with the result:

'getID' was not declared in this scope

You have some extra closing braces in your loop(). Take a close look at how the Arduino IDE's auto-format has indented your code. This will lead you to where the problems are.

Thanks!

I have fixed it up,
but the problem is still occurring.
My new code is below.
Thanks.

#include <Arduino.h>
#include <stdint.h>
#include <Keypad.h>
#include <SPI.h>
#include <Servo.h>
#include <LiquidCrystal_I2C.h>
#include <MFRC522.h>
#include <Wire.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;
int proximitySensor;
boolean doorOpened = false;

const byte ROWS = 4;
const byte COLS = 4;

MFRC522 mfrc522(SS_PIN, RST_PIN);
Servo myServo;
LiquidCrystal_I2C lcd(0x21, 16, 2);

char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {8, 7, 6, 5};
byte colPins[COLS] = {4, 3, 2, 1};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup() {
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();
  myServo.attach(0);
  myServo.write(10);

  lcd.backlight();
  lcd.init();

  lcd.setCursor(0, 0);
  lcd.print("Initiating...");
  delay(5000);

  lcd.print("-No Master Tag!-");
  lcd.setCursor(0, 1);
  lcd.print("    SCAN NOW");

  while (!successRead) {
    successRead = getID();                                      //CHECK THIS [getID()]
    if ( successRead == true) {
      myTags[tagsCount] = strdup(tagID.c_str());
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("Master Tag Set!");
      tagsCount++;
    }
  }
  successRead = false;

  delay(5000);
  lcd.setCursor(0, 0);
  lcd.print("   Enter New");
  lcd.setCursor(0, 1);
  lcd.print("   Password:");

  char customKey = customKeypad.getKey();
  if (customKey) {
    Data[data_count] = customKey;
    lcd.setCursor(data_count, 1);
    lcd.print(Data[data_count]);
    data_count++;
  }

  if (data_count == Password_Length - 1) {
    lcd.clear();
  }

  lcd.setCursor(0, 0);
  lcd.print("---Initiation---");
  lcd.setCursor(0, 1);
  lcd.print("----Complete----");
  delay(5000);
  startUp();

  uint8_t getID() {
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
      return 0;
    }
    if ( ! mfrc522.PICC_ReadCardSerial()) {
      return 0;
    }
    tagID = "";
    for ( uint8_t i = 0; i < 4; i++) {
      readCard[i] = mfrc522.uid.uidByte[i];
      tagID.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    tagID.toUpperCase();
    mfrc522.PICC_HaltA();
    return 1;
  }

  proximitySensor = analogRead(A0);
}

void loop() {
  if (!strcmp(Data, Master));
  lcd.setCursor(0, 0);
  lcd.print("Correct Keycode!");
  myServo.write(180);
  delay(5000);
  startUp();

else {
  lcd.clear
  lcd.setCursor(0, 0);
  lcd.print("-Incorrect Code-");
  delay(2500);
  startUp();
}

lcd.clear();
clearData();

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!");
          startUp();
          return;
        }
      }
      myTags[tagsCount] = strdup(tagID.c_str());
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("   Tag Added!");
      startUp();
      tagsCount++;
      return;
    }
  }
}
for (int i = 0; i < 100; i++) {
  if (tagID == myTags[i]) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(" Access Granted!");
    myServo.write(180);
    startUp();
    correctTag = true;
  }
}
if (correctTag == false) {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Access Denied!");
  startUp();
}
// If door is open...
else {
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" Door Opened!");
  while (!doorOpened) {
    proximitySensor = analogRead(A0);
    if (proximitySensor > 200) {
      doorOpened = true;
    }
  }
  doorOpened = false;
  delay(500);
  myServo.write(10);
  startUp();
}
}

void startUp() {
  delay(2000);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Enter Password: ");
  lcd.setCursor(0, 1);
  lcd.print("--OR SCAN TAG!--");
  myServo.write(10);
}

void clearData() {
  while (data_count != 0) {
    Data[data_count--] = 0;
  }
  return;
}

You are missing a closing brace in your setup(). This causes getID() to be defined inside of setup(). Do a Tools > Auto Format and then check the indentation to see where the problem is.