13.56 MHz RFID Reader-Writer Documentation
The 13.56 MHz RFID Reader-Writer is a compact, high-frequency RFID module capable of reading and writing to ISO/IEC 14443A and ISO/IEC 14443B compliant tags. This module is ideal for applications requiring high-speed data transfer, security, and reliability.
Operating Frequency: 13.56 MHz
Communication Protocol: ISO/IEC 14443A and ISO/IEC 14443B
Reading Distance: Up to 10 cm (3.9 in)
Antenna Type: Internal
Interface: UART, SPI, I2C
Power Supply: 3.3V - 5V
Dimensions: 40mm x 30mm x 10mm (1.57 in x 1.18 in x 0.39 in)
### Example 1: Reading a Tag using UART Interface (Arduino)
This example demonstrates how to use the 13.56 MHz RFID Reader-Writer with an Arduino board to read a tag's unique identifier (UID).
```c
#include <SoftwareSerial.h>
#define RFID_RX 2 // UART RX pin
#define RFID_TX 3 // UART TX pin
SoftwareSerial RFID(RFID_RX, RFID_TX);
void setup() {
Serial.begin(9600);
RFID.begin(9600);
}
void loop() {
char buffer[20];
int bytesRead;
// Request tag presence
RFID.print("T");
bytesRead = RFID.readBytes(buffer, 20);
if (bytesRead > 0) {
// Tag detected, read UID
RFID.print("R");
bytesRead = RFID.readBytes(buffer, 20);
if (bytesRead > 0) {
Serial.print("Tag UID: ");
Serial.println(buffer);
} else {
Serial.println("Failed to read tag UID");
}
} else {
Serial.println("No tag detected");
}
### Example 2: Writing to a Tag using SPI Interface (Raspberry Pi)
This example demonstrates how to use the 13.56 MHz RFID Reader-Writer with a Raspberry Pi to write a string to a tag.
```python
import spidev
import time
# Initialize SPI
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1000000
# Define SPI commands
CMD_WRITE = 0x02
CMD_TAG_PRESENT = 0x04
def write_tag(data):
# Request tag presence
spi.xfer([CMD_TAG_PRESENT])
response = spi.xfer([0x00])
if response[0] == 0x01:
# Tag detected, write data
spi.xfer([CMD_WRITE, len(data)] + list(data))
response = spi.xfer([0x00])
if response[0] == 0x01:
print("Data written successfully")
else:
print("Failed to write data")
else:
print("No tag detected")
# Write a string to the tag
write_tag(b"Hello, RFID!")
### Example 3: Authenticating a Tag using I2C Interface (ESP32)
This example demonstrates how to use the 13.56 MHz RFID Reader-Writer with an ESP32 board to authenticate a tag using a password.
#define RFID_I2C_ADDRESS 0x28
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
byte password[] = {0x01, 0x02, 0x03, 0x04};
byte response[5];
// Authenticate tag
Wire.beginTransmission(RFID_I2C_ADDRESS);
Wire.write(0x01); // Authenticate command
Wire.write(password, 4);
Wire.endTransmission();
Wire.requestFrom(RFID_I2C_ADDRESS, 5);
for (int i = 0; i < 5; i++) {
response[i] = Wire.read();
}
if (response[0] == 0x01) {
Serial.println("Tag authenticated successfully");
} else {
Serial.println("Authentication failed");
}
Note: These examples are for illustrative purposes only and may require modifications to work with your specific setup. Please consult the datasheet and documentation provided with your RFID Reader-Writer module for more information.