RFID Simplified

Hello. I'm new to Arduino and need some assistance with understanding the code for the MFRC522 RFID board. The project that I would like to do is to have a user swipe their RFID card and on a monitor have their picture appear with pertinent information for a "security checkpoint". This is a project for kids, so security is not actually my concern. My thought is that the picture and other information would be on separate webpages that get invoked somehow by the unique ID of the RFID card.

After assembling the MFRC522 I became stumped by the code examples that are written. I have the MFRC522 running and I can get the card ID to display on the serial monitor, but nothing more than that. I'm not even sure how to write to the card.

Can anyone point me in the right direction for how to go about learning the code for this RFID board? Are there any other good examples out there?

Thanks!

Just doing an Advanced search on MFRC522 yielded 3 pages of results. Regrets for not digging any deeper on the quality of results, but some responses may be helpful.

Googling mfrc522 arduino also retrieved numerous off-forum locations.

Ray

Im not sure whay you are trying to do.
Write to the card , why.

Access control would normally just use the uid and look it up in a table.
Programme the table for each user to lookup which webpage to access.
You would need some way of interfacing with the internet though, pc or wireless module

I do not think you need to do anything with the reader.
Read the serial output with a pc and use it to link to a jpeg photo of the child or a web page if you want.
You need to know how to programme a pc though.

Okay, I have spent some significant time researching, reading, re-reading, and re-researching this and am ready to ask again for additional assistance.

My RC522 is connected to the Arduino and is able to read my MiFare Classic and Ultralight cards. I was able to do this using the DumpInfo sketch provided at: GitHub - miguelbalboa/rfid: Arduino RFID Library for MFRC522

Here is an example of the output to serial monitor from the DumpInfo:

Card UID: 04 00 41 82 1F 23 81
PICC type: MIFARE Ultralight or Ultralight C
Page  0  1  2  3
  0   04 00 41 CD
  1   82 1F 23 81
  2   3F 48 00 00
  3   00 00 00 00
  4   FF FF FF FF
  5   00 00 00 00
  6   00 00 00 00
  7   00 00 00 00
  8   00 00 00 00
  9   00 00 00 00
 10   00 00 00 00
 11   00 00 00 00
 12   00 00 00 00
 13   00 00 00 00
 14   00 00 00 00
 15   00 00 00 00

Now that I have the Card UID, my thought was to put it into an array. Then, I could write an if statement which compares the scanned card to the array and outputs the necessary response. Unfortunately, I'm not sure how to do this, or if this is even a feasible idea. I did find this site which would seem to do exactly what I want, however I am not understanding how this one functions either.: http://pacelg.com/rfid-bar-application/

  1. How can I store the ID multiple (25+) cards?
  2. How do I compare the card swipe against the stored IDs?

Thank you!

  1. How do I compare the card swipe against the stored IDs?

Use a simple if statement.
I assume that the I'd is in a char array. Put that into a unsigned long variable to turn it into a number and then use an if statement to test the number.

You can store 250 cards in EEPROM memory, the arduino will not forget them. You store each byte of the number in one EEPROM byte.

I’m very new to coding, so please bear with me as I learn. I have added two character strings, each one containing the Card UID that is outputted from the last line. When I verify the code, those char str do not throw any errors. However, when I try to use the commented out code to convert the str into an unsigned long, it says that it is an invalid conversion. I assume that my syntax is wrong because I can’t just make a string with letters equal to an integer which is only numbers.

#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9

char str1[ ] = "04 00 41 82 1F 23 81";
char str2[ ] = "04 26 A5 82 1F 23 80";
 // unsigned long card1 = str1; 
// unsigned long card2 = str2; 

MFRC522 mfrc522(SS_PIN, RST_PIN);	// Create MFRC522 instance.

void setup() {
	Serial.begin(9600);	// Initialize serial communications with the PC
	SPI.begin();			// Init SPI bus
	mfrc522.PCD_Init();	// Init MFRC522 card
	Serial.println("Scan Card to see UID and type...");
}

void loop() {
	// Look for new cards
	if ( ! mfrc522.PICC_IsNewCardPresent()) {
		return;
	}

	// Select one of the cards
	if ( ! mfrc522.PICC_ReadCardSerial()) {
		return;
	}

	// Dump debug info about the card. PICC_HaltA() is automatically called.
	mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
if 
}

The code you posted before showed the ID as a 4 byte code. Now you are showing it as a 7 byte code, which is right?
Assuming it is 7 bytes then this code will transfer the char string str1 into a long long type number. Note you do it one byte at a time, the best way to do this is with a for loop:-

char str1[ ] = "04 00 41 82 1F 23 81";
 // unsigned long card1 = str1; 
// first define the variable to use
unsigned long long card1;
// now transfer the char array into the variable
for(int i=0; i<8; i<7) {
card1 = (card1 << 8 )  +  str1[i]);

// of course you could just define the number like this:-
unsigned long long card1 = 0x040041821F2381;
}

The original code I posted shows the full output of the Dumpinfo sketch. It starts with a 7 byte UID (the unique identifier on the RFID card, I assume) and then I believe it outputs the full value of the card's memory, which seems to be 4 bytes. At the moment, all I care about is having the serial monitor respond to the UID, so 7 byte should be the way to go.

Thank you for the code recommendation. This is the first I've seen of the long long and I'm excited to give it a try. I'll let you know how it comes out!