LoginSignup
4
6

More than 5 years have passed since last update.

ArduinoにRFID無線モジュール(MFRC522)を繋いでRFIDタグ認識する

Posted at

目的

MFRC522 RFID IC カード リーダーを使用して何かを制御するための前準備です。

準備

Arduino nano 互換品
MFRC522 RFID IC カード リーダー

回路図

MFRC522 Reader/PCD <---> Arduino Nano v3
下記の通り接続します。
RST <---> D9
SDA(SS) <---> D10
MOSI <---> D11
MISO <---> D12
SCK <---> D13

コード

MFRC522 RFID IC カード リーダーのライブラリを入手し、
DumpInfoサンプルコードをビルドして使用します。

#include <SPI.h>
#include <MFRC522.h>

#define RST_PIN         9          // Configurable, see typical pin layout above
#define SS_PIN          10         // Configurable, see typical pin layout above

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

void setup() {
    Serial.begin(115200);       // Initialize serial communications with the PC
    while (!Serial);        // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
    SPI.begin();            // Init SPI bus
    mfrc522.PCD_Init();     // Init MFRC522
    mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
    Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}

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));
}

テスト

MFRC522 RFID IC カード リーダーにタグを近づけた際にIDなどを読み取ることができればOKです。

参考

組み込みエンジニアでなくても週末にArduinoを使って遊ぶ

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6