RFID Access Control with AI: Integrating RC522 and ASI Biont for Smarter Automation

Introduction

Radio-frequency identification (RFID) is everywhere — from warehouse logistics and library checkouts to secure door entry and hospital patient tracking. The MFRC522 is one of the most popular low-cost RFID reader modules, operating at 13.56 MHz and supporting MIFARE-compatible tags. It’s a staple for hobbyists and industrial tinkerers alike, typically connected to an Arduino or ESP32 via SPI.

But here’s the problem most tutorials don’t address: once you’ve read a tag, what do you do with that data? You can blink an LED, unlock a servo, or log to an SD card — but true automation requires a brain that can decide, act, and learn. That’s where ASI Biont enters the picture. Instead of writing rigid C++ logic that hard-codes authorized tags, you connect the RC522 to an AI agent that understands context, integrates with external services, and adapts its behavior without firmware updates.

In this guide, you’ll learn how to integrate an RC522-based RFID reader with ASI Biont using Hardware Bridge over a COM port. We’ll cover the wiring, the Python code that runs on your microcontroller, and the AI-side logic that turns a simple tag scan into a powerful automation trigger.

Why Connect an RC522 to an AI Agent?

Most RC522 projects follow a pattern: read a tag UID, compare it against a hardcoded list, and toggle a relay. That works for a single door in a single room, but it scales poorly. If you need to add a new user, you must reflash the microcontroller. If you want to log access events to a cloud database, you need additional network code. If you want to send a Slack message when an unknown tag is scanned, you’re writing a whole new integration layer.

By connecting the RC522 to ASI Biont, you transform a simple RFID reader into a context-aware access point:

  • Dynamic authorization — tag UIDs are managed by the AI, not burned into firmware. Add or revoke users via chat.
  • Multi-channel alerts — email, SMS, Telegram, or webhook notifications on any event.
  • Data logging and analytics — every scan is timestamped, stored, and available for dashboards or anomaly detection.
  • Integration with other devices — a valid tag can trigger a Modbus write to a PLC, turn on a camera via HTTP API, or open a virtual private network tunnel.

The AI agent (ASI Biont) handles all the orchestration. You only need to provide the raw tag data.

Choosing the Connection Method

ASI Biont supports multiple industrial and IoT protocols (see introduction). For the RC522, the most practical approach is Hardware Bridge via COM port.

Aspect Recommendation
Microcontroller Arduino Uno / Nano (or ESP32 with serial pass-through)
AI connection Hardware Bridge (bridge.py on PC) → WebSocket → ASI Biont cloud
Data format Plain text over serial (e.g., TAG: 0xABCD1234\n)
Why COM port? RC522 is SPI, not network-capable. Bridge relays serial data to AI.

An alternative is to use an ESP32 with built-in Wi-Fi and MQTT. That’s covered in a separate guide; here we focus on the simplest and most reliable setup — a wired serial connection.

Wiring the RC522 to an Arduino

Before any AI integration, you must physically connect the RC522 to your microcontroller. The module uses SPI, so wiring is straightforward:

RC522 Pin Arduino Pin
SDA (SS) Digital 10
SCK Digital 13
MOSI Digital 11
MISO Digital 12
IRQ Not connected (unused)
GND GND
RST Digital 9
3.3V 3.3V (NOT 5V!)

Warning: The RC522 is a 3.3V device. Connecting VCC to 5V will damage it. Use the 3.3V output from your Arduino.

Here’s a simple Fritzing-style diagram (ASCII):

Arduino Uno          RC522
┌────────────┐      ┌──────┐
│ 3.3V       ├──────┤ VCC  │
│ GND        ├──────┤ GND  │
│ D10 (SS)   ├──────┤ SDA  │
│ D11 (MOSI) ├──────┤ MOSI │
│ D12 (MISO) ├──────┤ MISO │
│ D13 (SCK)  ├──────┤ SCK  │
│ D9 (RST)   ├──────┤ RST  │
└────────────┘      └──────┘

Microcontroller Firmware (Arduino Sketch)

The Arduino code reads the RC522 and sends tag UIDs over serial. It does not make any access decisions — that’s the AI’s job.

#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();
  Serial.println("READY");
}

void loop() {
  if (!mfrc522.PICC_IsNewCardPresent()) return;
  if (!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.print("TAG: ");
  Serial.println(uid);

  mfrc522.PICC_HaltA();
  delay(1000);
}

Upload this sketch to your Arduino. Open the Serial Monitor (115200 baud) — you should see READY followed by TAG: ABCD1234 each time you tap a card.

Setting Up the Hardware Bridge

ASI Biont communicates with COM ports through a local application called bridge.py. You download it from the ASI Biont dashboard (Devices → Create API Key → Download bridge).

Prerequisites:
- Python 3.8+ installed on your PC
- pyserial, requests, websockets libraries (pip install pyserial requests websockets)
- Your ASI Biont API token (generated in the dashboard)

Launch the bridge:

python bridge.py --token=YOUR_API_TOKEN --ports=COM3 --baud=115200

Replace COM3 with your actual port (on Linux it might be /dev/ttyUSB0, on macOS /dev/cu.usbmodem*). The bridge connects to ASI Biont via WebSocket and opens the COM port. You should see a log message: Connected to ASI Biont.

How the AI Agent Connects to the RC522

Once the bridge is running, the AI agent (ASI Biont) can send commands to the Arduino. It uses the industrial_command tool with the serial_write_and_read operation.

Workflow:
1. User asks in chat: “Read the latest RFID tag from the reader on COM3.”
2. AI calls industrial_command(protocol='serial://', command='serial_write_and_read', data='TAG?\n').
3. The bridge sends “TAG?\n” over serial, the Arduino replies with the last scanned tag (e.g., “TAG: ABCD1234”).
4. AI receives the response and acts on it.

But you don’t need to manually type commands each time. The AI can set up an event-driven loop using execute_python — a sandbox on the ASI Biont server that runs Python scripts with pyserial, paho-mqtt, paramiko, and many other libraries.

Real-World Scenario: Automated Door Access with Logging

Let’s build a complete integration: an RFID reader at a workshop door. When a valid tag is scanned, the AI unlocks an electric strike (via a relay on the Arduino) and logs the event to a PostgreSQL database. If an unknown tag is scanned, the AI sends a Telegram alert.

Step 1: User Describes the Task in Chat

“Connect to the Arduino on COM3 at 115200 baud. The Arduino sends tag UIDs as ‘TAG: UID’. Authorized tags are stored in a PostgreSQL table called ‘authorized_tags’. When a valid tag is scanned, send ‘UNLOCK’ over serial to the Arduino (which controls a relay on pin 7). When an invalid tag is scanned, send a Telegram message to chat ID 987654321. Log every scan to a table ‘access_log’ with timestamp, tag, and status.”

Step 2: AI Generates the Integration Code

ASI Biont writes a Python script and runs it in the sandbox. Here’s the generated code (simplified):

import pyserial
import psycopg2
import requests
import time

# Database connection
db = psycopg2.connect(
    host="your-db-host",
    dbname="access_control",
    user="admin",
    password="secret"
)
cursor = db.cursor()

# Telegram bot config
TELEGRAM_BOT_TOKEN = "123456:ABC-DEF"
TELEGRAM_CHAT_ID = "987654321"

# Serial port (note: this runs in sandbox, so we use bridge's serial_write_and_read)
# But the sandbox doesn't have direct COM access — we use industrial_command.
# We'll write a script that polls via the bridge.

# Wait for bridge to be ready
time.sleep(2)

while True:
    # This loop would normally be replaced by an event-driven approach.
    # For demonstration, we show the logic.
    pass

Important: The sandbox does not have direct COM port access. Instead, the AI uses industrial_command or writes a script that calls the bridge via WebSocket. For simplicity, the AI can set up a polling loop using execute_python that periodically calls industrial_command to read the latest tag.

Step 3: AI Interprets the Tag

When a tag is scanned, the AI:
1. Queries PostgreSQL: SELECT COUNT(*) FROM authorized_tags WHERE uid = 'ABCD1234';
2. If count > 0:
- Sends UNLOCK\n via serial to the Arduino (which energizes a relay on pin 7 for 5 seconds).
- Logs to access_log: INSERT INTO access_log (uid, status, timestamp) VALUES ('ABCD1234', 'granted', NOW());
3. If count == 0:
- Sends Telegram message: ⚠️ Unknown tag ABCD1234 scanned at front door.
- Logs to access_log: INSERT INTO access_log (uid, status, timestamp) VALUES ('ABCD1234', 'denied', NOW());

All of this happens in seconds, with zero manual coding by the user.

Expanding the Arduino’s Capabilities

To control a relay (electric strike), add this to the Arduino sketch:

const int RELAY_PIN = 7;

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
  digitalWrite(RELAY_PIN, LOW);
  Serial.begin(115200);
  // ... rest of setup
}

void loop() {
  if (Serial.available()) {
    String cmd = Serial.readStringUntil('\n');
    cmd.trim();
    if (cmd == "UNLOCK") {
      digitalWrite(RELAY_PIN, HIGH);
      delay(5000);
      digitalWrite(RELAY_PIN, LOW);
      Serial.println("UNLOCKED");
    }
  }
  // ... RFID reading code
}

Now the AI can physically unlock a door by simply sending the right serial command.

Why This Approach Beats Traditional Firmware

Aspect Traditional Firmware ASI Biont + RC522
Adding users Reflash Arduino Update database row via chat
Notifications Impossible without GSM module Telegram, email, Slack
Audit log Local SD card (manual retrieval) Cloud database, queryable by AI
Integration with other systems Custom code for each protocol AI writes glue code on the fly
Adaptability Rigid, requires new firmware AI can change behavior instantly

Another Use Case: Inventory Management

A warehouse uses RC522 readers at each shelf. Workers scan items when placing or removing them. The AI:
1. Reads the tag UID.
2. Looks up the item in an inventory database (e.g., MongoDB).
3. Updates stock count.
4. If stock drops below a threshold, sends an email to the purchasing manager.

The microcontroller firmware is identical — it just sends TAG: UID. All intelligence lives in the AI agent.

Troubleshooting Common Issues

  • No serial data: Check baud rate match (115200 in both sketch and bridge). Verify COM port number.
  • Bridge can’t open port: Close other programs (Arduino IDE Serial Monitor). On Windows, run bridge as administrator.
  • AI gets no response: The serial_write_and_read command sends data and waits for a reply. If the Arduino doesn’t respond within the timeout, the AI receives an empty string. Add a Serial.println() in your Arduino to confirm the command was received.
  • SPI wiring errors: Double-check connections. The RC522 is sensitive to loose wires.

Conclusion

Integrating an RC522 RFID reader with ASI Biont transforms a simple sensor into a smart, adaptive system. Instead of hardcoding logic into a microcontroller, you let an AI agent handle decision-making, logging, and multi-channel communication. The result is a system that’s easier to maintain, more flexible, and infinitely more capable.

With Hardware Bridge, connecting any serial device — including RC522-equipped Arduinos — takes minutes. You don’t need to write API endpoints, design dashboards, or learn complex protocols. Just describe your requirements in plain English, and the AI generates the integration code.

Ready to give your RFID projects a brain? Start at asibiont.com — create an API key, download bridge.py, and connect your RC522 to the most intelligent automation agent available.

← All posts

Comments