An RFID light switch with Arduino and X10, rebuilt for 2026
Hold a tag to a reader and the lamp toggles. Built twice - once the classic way, with an Arduino Uno, a 13.56 MHz RC522 reader and an X10 lamp module, and once the 2026 way, with an ESP32, ESPHome and Home Assistant, which works with any light.
This is the project that sold a lot of people on home automation: walk in, hold a tag to a little reader by the door, and the light comes on. No app, no phone, no voice assistant mishearing you.
Below are two ways to build it in 2026. The first is the classic one, an Arduino talking X10 over the house wiring, for anyone who already has X10 modules. The second is what you would build from scratch today. It is the same idea, but it switches any light Home Assistant can control, from any brand.
One warning first, and it applies to both: a tag’s ID is not a secret. These readers identify a tag by its UID, which anyone can read from a few centimetres away, and cheap “magic” cards can copy it. That is fine for a lamp. Never use it for a door lock.
Build 1: Arduino, RC522 and X10
Parts
- An Arduino Uno (or another 5 V board: the X10 interface needs 5 V on its input).
- An RC522 reader module: the blue 13.56 MHz board that usually comes with a white card and a key fob. Any MIFARE tag works.
- A TW523 or PSC05 X10 powerline interface. They are no longer made; see X10 with Arduino in 2026 for what that means.
- An X10 lamp module (LM465), set to house A, unit 1.
Wiring
| From | To Arduino |
|---|---|
| RC522 SDA | D10 |
| RC522 SCK | D13 |
| RC522 MOSI | D11 |
| RC522 MISO | D12 |
| RC522 RST | D9 |
| RC522 3.3V | 3.3V (not 5V) |
| RC522 GND | GND |
| TW523 pin 1, black (zero crossing) | D2 |
| TW523 pin 2, red (common) | GND |
| TW523 pin 4, yellow (transmit) | D4 |
The RC522 is a 3.3 V chip, so power it from the 3.3 V pin. Its signal pins are not specified for 5 V either. Plenty of people wire them straight to an Uno and get away with it, but a cheap four-channel level shifter on SDA, SCK, MOSI and RST is the correct way. The TW523’s receive pin (3, green) is not used here.
The sketch
Install MFRC522 from the Library Manager (version 1.4.12 at the time of writing), then upload:
rfid_x10_light.ino
// rfid_x10_light.ino: hold a known RFID tag to an RC522 reader and an X10 lamp toggles on or off.
// An unknown tag is printed on the Serial Monitor (115200 baud), ready to paste into ALLOWED below.
// X10 timing follows X10's PL513/TW523 technical note. geekcowboy.net, 2026. MIT licence.
#include <SPI.h>
#include <MFRC522.h>
const uint8_t ZC_PIN = 2; // TW523/PSC05 pin 1 (black): zero crossing; pin 2 (red) to GND
const uint8_t TX_PIN = 4; // TW523/PSC05 pin 4 (yellow): transmit envelope
const uint8_t RC522_SS = 10; // RC522 SDA; SCK, MOSI, MISO on D13, D11, D12; RC522 power from 3.3 V only
const uint8_t RC522_RST = 9;
const char HOUSE = 'A'; // the lamp module's house letter
const uint8_t UNIT = 1; // and its unit number
const char *ALLOWED[] = {"DE AD BE EF"}; // tags that may switch it, as this sketch prints them
const unsigned int HALF_CYCLE_US = 8333; // 60 Hz mains; 10000 where the mains is 50 Hz
const unsigned int BURST_US = 1000;
const uint8_t CODE[16] = { // the technical note's house/unit table, in transmission order
0b0110, 0b1110, 0b0010, 0b1010, 0b0001, 0b1001, 0b0101, 0b1101,
0b0111, 0b1111, 0b0011, 0b1011, 0b0000, 0b1000, 0b0100, 0b1100
};
const uint8_t FN_ON = 0b0010, FN_OFF = 0b0011;
MFRC522 rfid(RC522_SS, RC522_RST);
int zcLevel;
bool lightOn;
char lastTag[32];
unsigned long lastTagAt;
bool waitZeroCross() {
unsigned long start = micros();
while (digitalRead(ZC_PIN) == zcLevel) {
if (micros() - start > 50000UL) return false; // no mains on the interface
}
zcLevel = digitalRead(ZC_PIN);
return true;
}
bool sendHalfCycle(bool one) {
if (!waitZeroCross()) return false;
if (!one) return true;
for (uint8_t phase = 0; phase < 3; phase++) { // one 1 ms burst per phase of a three-phase supply
if (phase) delayMicroseconds(HALF_CYCLE_US / 3 - BURST_US);
digitalWrite(TX_PIN, HIGH);
delayMicroseconds(BURST_US);
digitalWrite(TX_PIN, LOW);
}
return true;
}
bool sendPair(uint8_t house, uint8_t key) { // start code, then each bit and its complement; twice; 3 quiet cycles
uint32_t bits = 0b1110;
uint16_t data = (uint16_t)house << 5 | key;
for (int8_t i = 8; i >= 0; i--) bits = bits << 2 | ((data >> i & 1) ? 0b10 : 0b01);
for (uint8_t copy = 0; copy < 2; copy++)
for (int8_t i = 21; i >= 0; i--)
if (!sendHalfCycle(bits >> i & 1)) return false;
for (uint8_t i = 0; i < 6; i++)
if (!waitZeroCross()) return false;
return true;
}
bool switchLamp(bool on) {
uint8_t house = CODE[HOUSE - 'A'];
return sendPair(house, CODE[UNIT - 1] << 1) && sendPair(house, (on ? FN_ON : FN_OFF) << 1 | 1);
}
bool allowed(const char *tag) {
for (uint8_t i = 0; i < sizeof(ALLOWED) / sizeof(ALLOWED[0]); i++)
if (strcmp(tag, ALLOWED[i]) == 0) return true;
return false;
}
void setup() {
pinMode(ZC_PIN, INPUT_PULLUP);
pinMode(TX_PIN, OUTPUT);
digitalWrite(TX_PIN, LOW);
Serial.begin(115200);
SPI.begin();
rfid.PCD_Init();
zcLevel = digitalRead(ZC_PIN);
Serial.println(F("rfid_x10_light ready: hold a tag to the reader"));
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
char tag[32] = "";
for (byte i = 0; i < rfid.uid.size && i < 10; i++) {
char hex[4];
snprintf(hex, sizeof(hex), i ? " %02X" : "%02X", rfid.uid.uidByte[i]);
strcat(tag, hex);
}
rfid.PICC_HaltA();
rfid.PCD_StopCrypto1();
// A tag waved twice, or bouncing at the edge of the field, reads twice: act once per tag per 2 s.
if (strcmp(tag, lastTag) == 0 && millis() - lastTagAt < 2000) {
lastTagAt = millis();
return;
}
strcpy(lastTag, tag);
lastTagAt = millis();
if (!allowed(tag)) {
Serial.print(F("Unknown tag: "));
Serial.println(tag);
return;
}
if (switchLamp(!lightOn)) {
lightOn = !lightOn;
Serial.print(HOUSE);
Serial.print(UNIT);
Serial.println(lightOn ? F(" ON") : F(" OFF"));
} else {
Serial.println(F("No zero crossing: is the X10 interface plugged in?"));
}
}
The first time, hold your tag to the reader with the Serial Monitor open at 115200 baud. The sketch does not know it yet, so it prints something like:
rfid_x10_light ready: hold a tag to the reader
Unknown tag: 04 A2 1B 7A
Copy that ID into ALLOWED (replacing the placeholder DE AD BE EF), upload again, and the tag now toggles the lamp: A1 ON, then A1 OFF the next time. Several tags work too: {"04 A2 1B 7A", "93 0C 55 E1"}.
How it works
The RFID half is the MFRC522 library’s usual routine: is there a new card, read its UID, put the card to sleep. The sketch turns the UID into text and looks it up in ALLOWED. A tag read twice within two seconds counts once, so a hand that hesitates does not switch the lamp on and straight back off.
The X10 half is the transmit side of the sketch in Transmit and receive X10 commands with an Arduino, trimmed to what is needed. It waits for each zero crossing of the mains, sends a 1 ms envelope for every “1”, sends each frame twice with three quiet cycles after it, and addresses the unit before sending On or Off. That article explains each step and how it was tested.
The sketch keeps track of whether it last sent On or Off. A plain X10 lamp module cannot report its state, so if someone switches the lamp at the module, the next tag simply sends the same command again. Hold the tag once more and you are back in step.
Build 2: ESP32, ESPHome and Home Assistant
If you are not invested in X10, this is the better build. The reader reports tags to Home Assistant, and Home Assistant decides what each tag does. That can be a light on Zigbee, Z-Wave, Matter, Wi-Fi, or even X10.
Parts and wiring
An ESP32 development board (the common “ESP32 DevKit” type) and the same RC522 module. The ESP32 runs at 3.3 V, so no level shifting is needed:
| RC522 | ESP32 |
|---|---|
| SDA | GPIO5 |
| SCK | GPIO18 |
| MOSI | GPIO23 |
| MISO | GPIO19 |
| RST | not connected |
| 3.3V | 3V3 |
| GND | GND |
The configuration
ESPHome builds the firmware from a short YAML file. You write no C++. Put your Wi-Fi details and an API key in ESPHome’s secrets.yaml, then:
front-door-rfid.yaml
esphome:
name: front-door-rfid
esp32:
board: esp32dev
logger:
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
api:
encryption:
key: !secret api_encryption_key
spi:
clk_pin: GPIO18
mosi_pin: GPIO23
miso_pin: GPIO19
rc522_spi:
cs_pin: GPIO5
on_tag:
then:
- homeassistant.tag_scanned: !lambda 'return x;'
Flash it with esphome run front-door-rfid.yaml, from the ESPHome add-on in Home Assistant or from the command line, and add the device to Home Assistant when it is discovered.
Teaching it a tag
Hold the tag to the reader once. It appears in Home Assistant under Settings → Tags. Give it a name (“hall tag”), choose Create automation, and add the action you want, for example toggle the hall light. Done: every scan now runs that automation. Adding a second tag, or making a tag do something different after dark, takes a minute and no reflashing.
Which one?
If you already have X10 modules and a TW523, Build 1 costs you one RC522 module and an evening. It has no server, no network and nothing to update.
If you are starting from nothing, Build 2 is cheaper, needs no discontinued parts, works with whatever lights you have, and tells you whether the light really came on. The thing it does not have is Build 1’s independence: if Home Assistant is down, the tag does nothing.