Skip to main content

Rfid - 125kHz RFID tag reader board (UART) - reading example

This page contains a few simple examples along with function documentation that explains how to use the 125kHz RFID Tag Reader Board (UART).

Initialization

To start working with the RFID reader via UART, configure the serial pins and baud rate. The default baud rate is 9600, but it can be changed using the DIP switches:

// Include breakout-specific library
#include "RFID-SOLDERED.h"

// Define UART pins
#define RX_PIN 4 // Connect TXD from breakout to this pin
#define TX_PIN 5 // Connect RXD from breakout to this pin

// Initialize RFID object with pins and baud rate
Rfid rfid(RX_PIN, TX_PIN, 9600);

void setup()
{
Serial.begin(115200);
rfid.begin(); // Initialize RFID module

if (!rfid.checkHW())
{
Serial.println("No module detected! Check wiring and baud rate.");
while (1) delay(1);
}

Serial.println("Place your tag near the RFID antenna");
}
//...

rfid.begin()

Initializes UART communication with the RFID module using specified pins and baud rate.

Returns value: None


Reading RFID Tags

Read tags by checking for data availability in the loop. Supported baud rates (set via DIP switches):

Switch 1Switch 2Switch 3Baud Rate
0009600
1002400
0104800
11019200
00138400
10157600
011115200
111230400
void loop()
{
if (rfid.available())
{
Serial.print("Tag available! Tag ID: ");
Serial.print(rfid.getId());
Serial.print(" RAW RFID Data: ");
rfid.printHex64(rfid.getRaw());
Serial.println();
}
}

rfid.available()

Checks if new RFID tag data is available in the buffer.

Returns value: Returns true if data is available, false otherwise.


Serial Monitor for RFID (UART)
Serial Monitor for RFID (UART)

Full example

Complete code example for UART communication with the RFID reader:

#include "RFID-SOLDERED.h"

#define RX_PIN 4
#define TX_PIN 5

Rfid rfid(RX_PIN, TX_PIN, 9600);

void setup()
{
Serial.begin(115200);
rfid.begin();

if (!rfid.checkHW())
{
Serial.println("Connection error! Check:");
Serial.println("- Wiring");
Serial.println("- Baud rate settings");
Serial.println("- Power supply");
while (1) delay(1);
}

Serial.println("Ready to scan tags");
}

void loop()
{
if (rfid.available())
{
Serial.print("Detected Tag ID: ");
Serial.print(rfid.getId());
Serial.print(" | RAW Data: ");
rfid.printHex64(rfid.getRaw());
Serial.println();
}
}

readTagIDWithUart.ino

Basic UART example for reading RFID tags