Automate RFID Access Control with RC522 and ASI Biont AI Agent
The Problem: Manual RFID Tracking Doesn't Scale
Managing physical assets—tools, keys, samples, or inventory—with RFID tags is a proven method, but most implementations still rely on manual logbooks or basic readers that simply beep. You have to check logs, reconcile discrepancies, and manually trigger notifications. As the number of items grows, so does the human effort. What if an AI agent could automatically read every RFID tag, log it to a database, and alert your team via Slack or Telegram when something is missing or unauthorized?
With ASI Biont, you can build exactly that—without writing a single line of integration code yourself. The AI agent connects directly to your RC522 RFID module (via a microcontroller) and handles the entire data pipeline: reading tag UIDs, parsing them, storing records, and triggering actions.
What is RC522 and How Does It Connect?
The MFRC522 is a low-cost, 13.56 MHz RFID module widely used in IoT projects. It communicates over SPI or I2C, and is typically paired with an Arduino, ESP32, or Raspberry Pi. The microcontroller runs a simple sketch that reads the tag UID and sends it over a serial (UART) connection to a PC. That serial port is exactly how ASI Biont can talk to it—via the Hardware Bridge.
Why Hardware Bridge?
ASI Biont runs in the cloud, so it cannot directly access your local COM ports. The bridge.py application (downloaded from the ASI Biont dashboard) runs on your Windows, Linux, or macOS machine and creates a secure WebSocket tunnel to the AI agent. Once connected, the AI can send industrial_command calls with serial_write_and_read to request data from the RC522 or send commands to the microcontroller.
Alternative connection methods are also possible—for example, if your RC522 is connected to an ESP32 that publishes data via MQTT, the AI can use execute_python with the paho-mqtt library. But for simplicity and low latency, the serial bridge is often the fastest path.
Real Example: Office Access Log with Telegram Alerts
Let’s walk through a concrete scenario: You want to log every time an employee taps their RFID badge on a reader at the office entrance, and get a Telegram notification if an unknown card is used.
Step 1: Hardware Setup
- Arduino Uno (or Nano) with RC522 module wired via SPI.
- Connect the Arduino to your PC via USB (acts as serial port COM3 on Windows).
- Upload the following sketch that continuously reads card UIDs and prints them in hex:
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
MFRC522 mfrc522(SS_PIN, RST_PIN);
void setup() {
Serial.begin(115200);
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
if (!mfrc522.PICC_IsNewCardPresent() || !mfrc522.PICC_ReadCardSerial()) return;
String uid = "";
for (byte i = 0; i < mfrc522.uid.size; i++) {
if (mfrc522.uid.uidByte[i] < 0x10) uid += "0";
uid += String(mfrc522.uid.uidByte[i], HEX);
}
uid.toUpperCase();
Serial.println(uid);
delay(500);
}
This sketch simply prints the UID (e.g., A1B2C3D4) to the serial monitor every time a card is tapped.
Step 2: Connect ASI Biont via Hardware Bridge
- In the ASI Biont dashboard, go to Devices → Create API Key and download
bridge.py. - Run the bridge on your PC:
pip install pyserial requests websockets
python bridge.py --token=YOUR_TOKEN --ports=COM3 --baud=115200
- The bridge connects to ASI Biont via WebSocket and opens COM3.
Step 3: AI Reads the RFID UID
Now in the ASI Biont chat, you tell the AI:
"I have an RC522 connected via Arduino on COM3 at 115200 baud. I want to read the card UID every time a card is tapped, log it to a CSV file, and send a Telegram message if the card is not in my allowed list."
The AI will use industrial_command to send a serial command. Since the Arduino automatically prints UIDs, the AI can simply poll the serial buffer. It will write a command (e.g., READ\n) if needed, or just read what arrives. The AI constructs a sequence like this:
# This is what the AI generates and executes via industrial_command
import asyncio
async def read_card():
# Wait for a card to be presented
while True:
response = await asyncio.to_thread(
lambda: await industrial_command(
protocol='serial://',
command='serial_write_and_read',
params={
'port': 'COM3',
'baud': 115200,
'data': 'READ\n' # or empty to just read
}
)
)
if response and len(response) > 2: # assume UID is 8 hex chars
uid = response.strip()
print(f"Detected card: {uid}")
# Log to file
with open('rfid_log.csv', 'a') as f:
f.write(f"{datetime.now()},{uid}\n")
# Check allowed list
allowed = ['A1B2C3D4', 'E5F60708']
if uid not in allowed:
# Send Telegram alert
await telegram_send(f"⚠️ Unknown card: {uid} at {datetime.now()}")
await asyncio.sleep(0.5)
Important: The actual code runs inside
execute_pythonin the ASI Biont sandbox. The sandbox has no direct serial access—butindustrial_commandroutes the request through the bridge, so it works seamlessly.
Step 4: Automation Scenarios
Once the AI has the UID, it can do almost anything:
- Log to Google Sheets – using
requeststo a web app script. - Send a Slack message – via
slack_sdk. - Control a relay – send a command back to the Arduino to unlock a door.
- Count inventory – keep a running total of how many times each item is scanned in/out.
Advanced: Multi-Reader Inventory System
You can scale this to multiple RC522 modules, each connected to its own Arduino or multiplexed on a single ESP32. The AI can differentiate readers by port or topic (if using MQTT). For example, you could have readers at a warehouse entrance, tool cabinet, and exit—the AI tracks when an item moves between zones and updates a real-time dashboard.
MQTT Alternative
If your RC522 is on an ESP32 that publishes UIDs to an MQTT topic, the AI can subscribe using execute_python:
import paho.mqtt.client as mqtt
def on_message(client, userdata, msg):
uid = msg.payload.decode()
print(f"Received UID: {uid} from topic {msg.topic}")
# process...
client = mqtt.Client()
client.connect("broker.emqx.io", 1883, 60)
client.subscribe("rfid/warehouse/#")
client.on_message = on_message
client.loop_start()
The AI can keep the loop running (within the 30-second sandbox limit by using short intervals or offloading to a scheduled task—the AI can write a persistent script that runs on your local machine via the bridge).
Why This Matters
Traditional IoT setups require you to write all the glue code yourself—serial parsing, database integration, notification logic. With ASI Biont, you just describe what you want in natural language. The AI agent generates the Python code, handles error cases, and adapts to your exact hardware. You don't need to wait for a dashboard update or a new integration pack. If your device speaks any of the supported protocols (serial, MQTT, Modbus, etc.), it can be connected in minutes.
Key benefits:
- No manual coding – AI writes the integration.
- Instant notifications – Telegram/Slack/email alerts on any condition.
- Scalable – from one reader to hundreds, AI manages the logic.
- Data persistence – logs can be stored in a database, CSV, or cloud service.
Get Started Today
Ready to eliminate manual RFID tracking? Connect your RC522 module to ASI Biont. Just run the bridge and tell the AI what to do. Start your free trial at asibiont.com and experience true AI-driven device integration.
Comments