RFID,NFC Module(RC522) JP: 두 판 사이의 차이

아두위키 : Arduwiki
(새 문서: {{#seo:|title=アルドゥウィキ:アルドゥイーノ RFID、NFC モジュール(RC522)ガイド|title_mode=append|keywords=アルドゥイーノ, 情報科学, メーカー学習, パフォーマンス評価, RFID, NFC モジュール(RC522), アルドゥイーノプロジェクト, キャップストーンプロジェクト, アルドゥイーノサンプルコード|description=アルドゥイーノで RFID、NFC モジュール(RC522)を制御する方法...)
 
(차이 없음)

2025년 3월 21일 (금) 17:00 기준 최신판

RC522はNFC通信方式を使用するRFIDリーダーです。

アルドゥイーノやラズベリーパイボードで使用可能です。


仕様

  • 動作電圧:3.3V
  • 動作電流:13mA ~ 26mA
  • インターフェース:SPI
  • 動作周波数:13.56MHz


ハードウェア


接続

RC522 Arduino
3.3V 3.3V
RST 9
GND GND
MISO 12
MOSI 11
SCK 13
SDA 10


Libraries

  • MFRC522 (by GithubCommunity)
  • SPI (default included library)

Arduino Libraries

サンプルコード

タグ付けされたID値をシリアルモニターに出力します。

#include <SPI.h>
#include <MFRC522.h>
 
#define RST_PIN   9                            // Reset pin is set to pin 9
#define SS_PIN    10                           // SS pin is set to pin 10
                                               // SS pin is the pin responsible for data exchange (SS = Slave Selector)
 
MFRC522 mfrc(SS_PIN, RST_PIN);                 // Creating the mfrc object to utilize the MFR522
 
void setup() {
  Serial.begin(9600);                          // Serial communication, baud rate is set to 9600
  SPI.begin();                                 // Initializing SPI
                                               // (SPI: Communication method between one master and multiple slaves)
  mfrc.PCD_Init();                             // Initializing MFRC522
}
 
void loop() {
  if (!mfrc.PICC_IsNewCardPresent() || !mfrc.PICC_ReadCardSerial()) {   
                                               // When no tag is detected or ID is not read
    delay(500);                                // 0.5 second delay
    return;                                    // Return
  } 
    
  Serial.print("Card UID:");                   // Printing the tag's ID
  
  for (byte i = 0; i < 4; i++) {               // Loop to print the tag's ID, up to the tag's ID size (4)
    Serial.print(mfrc.uid.uidByte[i]);        // Printing from mfrc.uid.uidByte[0] to mfrc.uid.uidByte[3]
    Serial.print(" ");                         // Printing space between IDs
  }
  Serial.println(); 
}


実行結果