RFID MFRC522 Door Lock Problem. Help!

Hello im having problem getting the RFID MFRC522 Working.

I got the project tutorial from:

and i follow all the steps.

When iam trying to upload the last code, i got the following error messages:

Users/users/Documents/Arduino/RFID_PROXIMITY_LCD/RFID_PROXIMITY_LCD.ino: In function 'void loop()':
/Users/users/Documents/Arduino/RFID_PROXIMITY_LCD/RFID_PROXIMITY_LCD.ino:89:25: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
myTags = "";

It is a warning, not an error message. Warnings do not cause compilation to fail so that is not your problem. As for why the display is blank, have you initialized it? Have you tested it with other sample programs to make sure your contrast adjustment makes characters visible?

iam going to test the LCD later. I have to go to school for some reason :smiley:

hello i have test the LCD and its working for sure. Iam having the problem that the LCD lights up, but blank! please help

This is the code i use:

/*

#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#include <Servo.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;

// Create instances
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Parameters: (rs, enable, d4, d5, d6, d7)
Servo myServo; // Servo motor

void setup() {
// Initiating
SPI.begin(); // SPI bus
mfrc522.PCD_Init(); // MFRC522
lcd.begin(16, 2); // LCD screen
myServo.attach(8); // Servo motor

myServo.write(10); // Initial lock position of the servo motor
// Prints the initial message
lcd.print("-No Master Tag!-");
lcd.setCursor(0, 1);
lcd.print(" SCAN NOW");
// 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 (proximitySensor > 200) {
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 = mfrc522.uid.uidByte*;*
_ tagID.concat(String(mfrc522.uid.uidByte*, 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*) {
myTags = "";
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) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Access Granted!");
myServo.write(170); // 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!");
while (!doorOpened) {
proximitySensor = analogRead(A0);
if (proximitySensor > 200) {
doorOpened = true;
}
}
doorOpened = false;
delay(500);
myServo.write(10); // 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 = mfrc522.uid.uidByte*;*
_ tagID.concat(String(mfrc522.uid.uidByte*, 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("-Access Control-");*
* lcd.setCursor(0, 1);*
* lcd.print(" Scan Your Tag!");*
}

Look at number 7 of this post:

http://forum.arduino.cc/index.php/topic,148850.0.html

The reason your code is not compiling is because you didn't copy it properly. Select the option "toggle raw mode" before copying it from that website.

Thanks for replying.

I do as what you said. Use the Raw Code. But it is still not working :frowning:
The LCD Blank.

Heres the code:

/*
* Arduino Door Lock Access Control Project
*                
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: MFRC522, https://github.com/miguelbalboa/rfid
*/

#include <SPI.h>
#include <MFRC522.h>
#include <LiquidCrystal.h>
#include <Servo.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;

// Create instances
MFRC522 mfrc522(SS_PIN, RST_PIN);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Parameters: (rs, enable, d4, d5, d6, d7)
Servo myServo; // Servo motor

void setup() {
  // Initiating
  SPI.begin();        // SPI bus
  mfrc522.PCD_Init(); //  MFRC522
  lcd.begin(16, 2);   // LCD screen
  myServo.attach(8);  // Servo motor

  myServo.write(10); // Initial lock position of the servo motor
  // Prints the initial message
  lcd.print("-No Master Tag!-");
  lcd.setCursor(0, 1);
  lcd.print("    SCAN NOW");
  // 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 (proximitySensor > 200) {
    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!");
        myServo.write(170); // 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!");
    while (!doorOpened) {
      proximitySensor = analogRead(A0);
      if (proximitySensor > 200) {
        doorOpened = true;
      }
    }
    doorOpened = false;
    delay(500);
    myServo.write(10); // 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("-Access Control-");
  lcd.setCursor(0, 1);
  lcd.print(" Scan Your Tag!");
}

Reply #3 makes it sound like you assume the LCD is working because the backlight is on, but just because the backlight is on does not mean you will be able to write characters to it. You need to follow the advice in reply #1 and try a known working program to test the LCD.

Open the test program at File=>Examples=>LiquidCrystal=>HelloWorld. Note that you might have to change the parameters used to initialize the library.

If it does not work check your wiring (and as suggested in reply #1 the contrast pot) and follow the LCD tutorial on the Arduino web site.

If you cannot get the LiquidCrystal examples to work then you're wasting your time trying to get the lock program working.

After a day, i solved it! I could make it work with adding 220 resistor too the 5V!
I combined it with the "Hello World" LCD Project

But i got 1 problem

So let s say i came home from school, i bring my tag, i scan it, granted, i go inside my room and sleep. (HAHA).
And now, How can i go outside of my room because the the servo status is locked.
So what i want is, how to get out of my room when im inside of my room (because i set the MFRC522 outside of the door) ?

(+)

My Project drains 9v battery so fast! How can i prevent that. I can tell that is drain battery fast because the LCD getting darker and darker untill all the text gone. Help me :slight_smile:

Add a button for activation from the inside.

Stop using worthless 9v batteries. Use rechargeables like lithium or NiMH.

Can you explain how to add button from inside to open the door?

And what lithium battery should i use?

Any idea why the LCD is so dim? Is that because of the battery power? Any way to fix this? even with USB Cable sometimes the lcd is really dim