Arduino RFID lock using new Uno and MFRC522

Hi!

I am new :)

I am starting microelectronics at uni next year and decided to get a head start. I have had an arduino for a while and never really done much with it.

I want to make a lock-box for a friend that opens with RFID. I have all needed components (afaik)

I have the RFID.h library for the MFRC522 (https://github.com/miguelbalboa/rfid/blob/master/RFID.h) but can not make sense of it to change this:

https://github.com/TKJElectronics/ArduinoRFIDDoorLock

to use my RFID reader, this code is for a Parallax RFID Reader.

I have a servo, have tested it and there are no problems. But assuming the card reader is even being activated by the TKJElectronics code, the Monitor prints nothing :~

I'd really appreciate some help.

I have also changed the master card in the TKJElectronics code to my own master.

Thank you.

hello,

Not sure if this is what your asking for or not?

The first link works(assuming you downloaded/installed the whole library and you actually have a MFRC522 reader), it only tells you what the serial number is on the card. You should be getting a 16 digit number or so. You will have to download the whole library though and unzip it and move it to “my documents/arduino/libraries” then when you open up the arduino IDE you can find it with the rest of your sketches in the “libraries” where you just installed it.

You can also look at this sketch which I believe is the same thing but not in a library form?

and when you get to the loop:

void loop()
{
  	uchar i,tmp;
	uchar status;
        uchar str[MAX_LEN];
        uchar RC_size;
        uchar blockAddr;	//????????0?63
        String mynum = "";


		//????????	
		status = MFRC522_Request(PICC_REQIDL, str);	
		if (status == MI_OK)
		{
                        //Serial.println("Card detected"); 
			//Serial.print(str[0],BIN);
                        //Serial.print(" , ");
			//Serial.print(str[1],BIN);
                        //Serial.println(" ");
		}

		//??????????? 4??
		status = MFRC522_Anticoll(str);
		memcpy(serNum, str, 5);
		if (status == MI_OK)
		{

                        //Serial.println("The card's number is  : ");
			//Serial.print(serNum[0]);
                        //Serial.print(" , ");
			//Serial.print(serNum[1],BIN);
                        //Serial.print(" , ");
			//Serial.print(serNum[2],BIN);
                        //Serial.print(" , ");
			//Serial.print(serNum[3],BIN);
                        //Serial.print(" , ");
			//Serial.print(serNum[4],BIN);
                        //Serial.println(" ");
                        
                        // Should really check all pairs, but for now we'll just use the first
                     
                        if(serNum[0] == 88) {
                          Serial.println("Hello Grant");
                        } else if(serNum[0] == 173) {
                          Serial.println("Hello David");
                        }
                        delay(1000);
		}
                //Serial.println(" ");
		MFRC522_Halt();			//??????????              
          
}

you can unblock the serial.prints, read your card and replace his “SerNum” digits to the first set of digits that are on one of your cards. Then add the rest of your code to finish off your task.

The library in the first link is nice and clean so a better idea would be to combine the above starting at the “if(serNum[0] == YOUR FIRST DIGITS FROM YOUR CARD) {” onto the nice and clean one and go from there. This might help you with understanding the door lock sketch.

have fun!

Hi,

Thanks. It is sort of what I was asking.

I have seen the Grant Gibson page (done plenty of googling before posting!) and I have the library I linked (RFID.h) to up and running. The problem is, I’m not sure how to implement it (i.e. what to change) in the project (door lock) I linked too, to get it working with my RFID reader rather then the Parallax one.

  • I don’t know what code to change
  • I also don’t know much a out the arduino in general, can anyone recommend a good tutorial video series - I don’t get on well with books!

Thanks :slight_smile:

hello,

maybe it would be easier (and better learning) if you worked with a sketch that was made for your piece and build onto that instead of changing something that was created for something else?

you can start with and try to understand something like this:

/***example code adapted from Grant Gibson & miguelbalboa:
https://github.com/miguelbalboa/rfid
http://www.grantgibson.co.uk/blog/2012/04/how-to-get-started-with-the-mifare-mf522-an-and-arduino/

 ******PINS FOR ARDUINO*********
 *** Reset = Pin 5 ***
 *** SDA = Pin 10 ***
 *** MOSI = Pin 11 ***
 *** MISO = Pin 12 ***
 *** SCK = Pin 13 ***
 *** GND = GROUND ***
 *** 3.3 = 3.3v ***
 
 ******************************************/

#include <SPI.h>
#include <RFID.h>

RFID rfid(10,5); 

int ledPin1 = 3; //access accepted LED
int ledPin2 = 4; //access denied LED
int buzzer = 6;



void setup()
{ 
  Serial.begin(9600);
  SPI.begin(); 
  rfid.init();
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(buzzer, OUTPUT);
  
  
   }


void loop() {
  
   if (rfid.isCard()) {
    
          if (rfid.readCardSerial()) { //this will show the 16 digits of the card
            
                       // Serial.println(" ");
                       // Serial.println("the serial number of the card is: ");
			//Serial.print(rfid.serNum[0],DEC);
                      //  Serial.print(" , ");
			//Serial.print(rfid.serNum[1],DEC);
                      //  Serial.print(" , ");
			//Serial.print(rfid.serNum[2],DEC);
                      //  Serial.print(" , ");
			//Serial.print(rfid.serNum[3],DEC);
                      //  Serial.print(" , ");
			//Serial.print(rfid.serNum[4],DEC);
                      //  Serial.println(" ");
                        
                        if(rfid.serNum[0] == 29){  //"29" is the first part of the 5 sets of digits from the card
                          Serial.println("hey dude!");
                          digitalWrite(ledPin1, HIGH); //turns on green "access granted" LED
                           delay(250);
                           digitalWrite(ledPin1, LOW);
                        }
                         
                        else{ 
                          Serial.println("sorry wrong key!"); //serial print for the COM on the PC
                          digitalWrite(ledPin2, HIGH); //turns on red "access denied" LED
                          
                          digitalWrite(buzzer, HIGH); //buzzer buzzes while LED is on
                          delay(30);
                          digitalWrite(buzzer, LOW);
                          delay(30);
                          digitalWrite(buzzer, HIGH);
                          delay(30);
                          digitalWrite(buzzer, LOW);
                          
                          delay(500);
                          digitalWrite(ledPin2, LOW); //LED turns off
                         }
                      }
                  }
                       rfid.halt();
                    }

then build a lock mechanism separately from other tutorials you find then once it’s up and running you can combine it into the mix!
Some good info and tutorials to start with could be found in the arduino IDE under “examples”, you can try google, youtube and adafruit makes some pretty clear lessons as well.
http://learn.adafruit.com/category/learn-arduino
and
http://arduino-info.wikispaces.com/HOME

have fun!

Hey!

Thank you! that sketch is great, I have taken out the LEDs and buzzer, then added my servo code :grin:

The problem is it accepts ALL my RFID cards. I assume this is the part (below) that needs to be changed. The first digit of my card is A9. When I put it in, I get an error - though that is not my main concern.

if(rfid.serNum[0] == '29'); {  //"29" is the first part of the 5 sets of digits from the card
                          Serial.println("hey dude!");
                          digitalWrite(ledPin1, HIGH); //turns on green "access granted" LED
                           delay(1000);
                           digitalWrite(ledPin1, LOW);
                        }

I can’t figure out why it is accepting ALL rfid cards!?

Thank you.

Hi!

First of all the number you check for should not be in quotes, so '29' shoud be 29. If you want to check for a hexadecimal number like A9 - then you need to specify it as a hexadecimal number like this: 0xA9 - again without the quotes. Hope this helps.

For excellent Arduino tutorials, check out Jeremy Blum's tutorial series on YouTube. He has also just released a book "Exploring Arduino", which might be worth a look! You can find the tutorials here: http://www.youtube.com/playlist?list=PLA567CE235D39FA84

I have the exact same RFID reader myself, but haven't yet come around to trying it out. So I'm very interested in what you find out!

Best of luck with your projects.

Hey, I just got an RFID module and I'm looking for the RFID.h library, but the original link is dead. Would you be kind enough to upload the library? I hope you still have it. Thank you.

enjoy!

rfid_master.rar (6.5 KB)

Hello!

I just ordered a Mifare RC522 RFID Reader/writer, i didn't realize how poorly the documentation/libraries on this were. I have found some github pages that have the entire library, like the one here. But it makes no sense to me (it is long and hard to read, and also in chinese partly.

Is the RFID_master.zip library the same as this one? Or is it different? And does it work properly on the RC522?

I was wondering if you managed to get this reader to work and if so would you be kind enough to give me a simple tutorial on the basics of reading/writing RFID tags?

Thanks a ton!

Hello i am trying to put a new project here, which is using to RFID to unlock door. Check it out.

http://forum.arduino.cc/index.php?topic=256260.0