Montag, 26. Mai 2014

RFID sensor (Funduino RFID-RC522)

Recently I bought a set of Arduino-compatible components including RFID sensor (RC522).

After short search I've found good tutorial telling how to use this sensor, downloaded a library and connected sensor to my Arduino (be careful there is a typo in original blog post):
  • MOSI: Pin 11
  • MISO: Pin 12
  • SCK: Pin 13
  • SS: Pin 10
  • RST: Pin 5
  • GND: Gnd
  • VCC: 3V3



I used following sketch to test the sensor:

 /*  
 * Read a card using a mfrc522 reader on your SPI interface  
  * Pin layout should be as follows (on Arduino Uno):  
  * MOSI: Pin 11 / ICSP-4  
  * MISO: Pin 12 / ICSP-1  
  * SCK: Pin 13 / ISCP-3  
  * SS: Pin 10  
  * RST: Pin 5  
  */  
 #include <SPI.h>  
 #include <RFID.h>  
 #define SS_PIN 10  
 #define RST_PIN 5  
 RFID rfid(SS_PIN,RST_PIN);  
 int serNum[5];  
 void setup(){  
  Serial.begin(9600);  
  SPI.begin();  
  rfid.init();  
 }  
 void loop(){  
  if(rfid.isCard()){  
   if(rfid.readCardSerial()) {  
    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("");  
   }  
  }  
  rfid.halt();  
 }  

P.S.: I have just now successfully tried to connect it to Arduino Mega. In this case according to reference you have to switch appropriate pins to:

  • MOSI: 51
  • MISO: 50
  • SCK: 52
  • SS: 53
UPD: library used in the code above is not available on Gethib anymore. You can download it here.

Keine Kommentare:

Kommentar veröffentlichen