RFID 카드를 사용해봤다.
![](https://t1.daumcdn.net/cfile/tistory/242B2235585CD6CE0A)
RFID는 코일에 전류를 흘려보내
앙패르 법칙에 의해 자기장을 형성하고
다시 페러데이의 법칙에 의해 Card 내부의 코일에서 유도전류가 생겨
Card 내부의 칩에 전원을 공급하여 칩내부의 데이터를 다시 RFID 모듈로 전송한다.
![](https://t1.daumcdn.net/cfile/tistory/220E3535585CD6BE29)
위에 있는것이 RFID RC522모듈이다
보다시피 3.3v를 이용한다.
#include <AddicoreRFID.h>
#include <SPI.h>
#define uchar unsigned char
#define uint unsigned int
uchar serNumA[5];
uchar fifobytes;
uchar fifoValue;
AddicoreRFID myRFID;
const int chipSelectPin = 10;
const int NRSTPD = 5;
const int speakerPin = 8;
#define MAX_LEN 16
void setup() {
Serial.begin(9600);
SPI.begin();
pinMode(chipSelectPin, OUTPUT);
digitalWrite(chipSelectPin, LOW);
pinMode(NRSTPD, OUTPUT);
digitalWrite(NRSTPD, HIGH);
myRFID.AddicoreRFID_Init();
}
unsigned int count = 0;
void loop() {
uchar i, tmp, checksum1;
uchar status;
uchar str[MAX_LEN];
uchar RC_size;
uchar blockAddr;
String mynum = "";
str[1] = 0x4400;
status = myRFID.AddicoreRFID_Request(PICC_REQIDL, str);
if (status == MI_OK) {
Serial.println("RIFD tag detected");
Serial.print(str[0], BIN);
Serial.print(",");
Serial.print(str[1], BIN);
Serial.println("");
}
status = myRFID.AddicoreRFID_Anticoll(str);
if (status == MI_OK) {
checksum1 = str[0] ^ str[1] ^ str[2] ^ str[3];
Serial.println("The tag's number is : ");
Serial.print(str[0]);
Serial.print(" , ");
Serial.print(str[1], BIN);
Serial.print(" , ");
Serial.print(str[2], BIN);
Serial.print(" , ");
Serial.print(str[3], BIN);
Serial.print(" , ");
Serial.print(str[4], BIN);
Serial.println(checksum1, BIN);
Serial.println();
switch (str[0]) {
case 239:
Serial.println("Card"); count++;
break;
case 252:
Serial.println("white card"); count++;
break;
} if (count == 1) {
tone(speakerPin, 2000, 100);
delay(100);
noTone(speakerPin);
}
delay(1000);
}
else count = 0;
myRFID.AddicoreRFID_Halt();
}
![](https://t1.daumcdn.net/cfile/tistory/262F9433585CD6A50C)
위의 처럼 연결후 위의 코드를 다운로드 해보자
흰색 카드가 태그되면 삐소리가 나며
시리얼 모니터 창으로 카드의 ID를 확인 할 수도 있다.