RFID system

Hi!

I am very new to this programming and so far very confused. Have been programming alot but have no idea of what language it is with arduino so far.

But my problem is this;

I have a software, see below, for an access with RFID card.
Every time I start this arduino it is asking for master ID even if I have set it once. Why is that?

I want to have a permanent card that always is master without the arduino “forgetting” what it was when power goes off. There are times when the powerlines fail so it must remember the master card but how to set that?

Also when I run the “Serial monitor” no data shows.
I want to be able to see what ID number each RFID card has so I manually can set it as master.

But right now after a few hours a day trying to learn more I am only getting more and more confused.
I am used to program in Visual Basic and before that in other languages but not this strange language, whatever it is. This text coding is killing me.

Can someone please help me?

Here is the entire code of the software I use;

// * Arduino Door Lock Access Control Project
#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() {
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();

Serial.println(“Access test via RFID tag”);
Serial.println();
}
// 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!");*
* }*

Needs more code tag

Shortest reply ever.

What are you meaning?

Seb76:
Shortest reply ever.

Not even close.

Use code tags, or stop including italics in your code.

Well the code is working fine. No problems.

But the question two questions are, to make it simple;

How do I get SERIAL MONITOR active?

How do I permanently set a RFID tag as Master?

Seb76:
How do I get SERIAL MONITOR active?

How do I permanently set a RFID tag as Master?

  1. open it
  2. what does that even mean?

And code tags

Use them

  1. open it
    Yes and when I do it does not show anything, just a blank screen.

  2. what does that even mean?
    In the code, when you startup the system first time, you will be asked to scan a master tag. But if power fails and the system restarts it will not remember the master tag it has registered.
    So I will need to set the master tag manually by watching the serial output but as I said, there is no output.

Hope that someone can help me with the code what might be the problem.

Hope that you can post the code without the italics and smileys 8)

Without italics; I will not edit everything again.

Without smileys, well I have no smileys, it is THIS SITE that makes it to a smiley.
Sorry for that

And yet, there the italics and smileys are.

Good luck with the attitude.

Your code is broken.
If you are new. Learn small, Learn slow. Start with the examples what come with the IDE.
Then workout the RFID component first.
Then add the LCD component.

//    * Arduino Door Lock Access Control Project
    #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() {
{
  Serial.begin(9600);
  SPI.begin();
  mfrc522.PCD_Init();

  Serial.println("Access test via RFID tag");
  Serial.println();
}
      // 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!");
    }

Use the code tags button, </> on the menu, then copy/paste your code from the IDE into the box.

Okay, I was looking for code in Arduino IDE not here so I did not understand anything until now.
Well the code is the same now. The italics will stay and I do not know why some of you do not like that. But it is my method of seeing what things do.


// * Arduino Door Lock Access Control Project
#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() {
{
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();

Serial.println(“Access test via RFID tag”);
Serial.println();
}
// 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!");*
* }*

Now I have added the </> and still there are smileys in the code. Can someone disable those smileys instead for this forum, they are NOT needed at all!!!

Put the code tags in the right place.

You can do it.

Sure I canbut in this case it has nothing to do with the smiley icon in my code. Where that is, it is just the servo motor and it works great = no problems.

The problems ar:

1: how to set a permanent master RFID tag to be present in the code?

2: how to monitor serial output from the RFID?

It is just not to open the serial monitor for question number 2. Because it does not display anything.

Regarding the coding, I am very new at it so I have no idea where to put all markers as you claim </> or similar, I have no idea what they are used for and, as I said, the code itself works fine as it is when I rn it.

The problem is that when I set a master RFID tag, the arduino does not store it in its memory. As soon as power goes off everything goes back to basic again and that is a problem. I will use this code, if it is possible with arduino, for a permanent alarm system. Therefor it must work flawless.

But I am soon about to give up arduino since the programming language is very strange.

Anyone that can give me some advise without picking on the smiley icon thart is not in the code, just on this site?

if ( successRead == true) {
              for (int i = 0; i < 100; i++) {
                if (tagID == myTags) {

tagID is a String object.
myTags is a pointer.
You are comparing a String object to a pointer which does not make sense. So this code is broken.

Ok, forget about the smiley.
Fix the italics.