Automatic dusk-to-dawn light
Lights switch on by themselves at dusk and off again in the morning.
Shop by category
Shop all componentsAn RC522 reader identifies a card by its unique ID number. The ESP32 compares the ID against a list in the sketch and pulses a relay for three seconds when it matches, which is enough to release an electric strike or switch a lamp. Card IDs are easy to copy, so this suits a cupboard, a hobby box or a classroom demo, not a door that protects anything valuable.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
Do not use a hobby RFID reader as the only lock on a door that protects people or valuables.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
USB phone charger. Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first.
rfid_relay.inoVerify & upload in Electrolark#include <SPI.h>
#include <MFRC522.h>
const int SS_PIN = 5, RST_PIN = 22, RELAY_PIN = 26, BUZZER = 25;
const bool ACTIVE_LOW = true;
const char* ALLOWED[] = {"04a1b2c3", "11223344"}; // replace with your card IDs
MFRC522 rfid(SS_PIN, RST_PIN);
void beep(int n) { for (int i = 0; i < n; i++) { digitalWrite(BUZZER, HIGH); delay(120); digitalWrite(BUZZER, LOW); delay(120); } }
void setup() {
Serial.begin(115200);
pinMode(RELAY_PIN, OUTPUT); pinMode(BUZZER, OUTPUT);
digitalWrite(RELAY_PIN, ACTIVE_LOW ? HIGH : LOW);
SPI.begin();
rfid.PCD_Init();
}
void loop() {
if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) return;
String uid = "";
for (byte i = 0; i < rfid.uid.size; i++) {
if (rfid.uid.uidByte[i] < 0x10) uid += "0";
uid += String(rfid.uid.uidByte[i], HEX);
}
Serial.println(uid);
bool ok = false;
for (auto id : ALLOWED) if (uid == id) ok = true;
if (ok) {
beep(1);
digitalWrite(RELAY_PIN, ACTIVE_LOW ? LOW : HIGH);
delay(3000);
digitalWrite(RELAY_PIN, ACTIVE_LOW ? HIGH : LOW);
} else {
beep(2);
}
rfid.PICC_HaltA();
delay(500);
}
Check the 3.3 V supply and all SPI wires; the RC522 is not 5 V tolerant.
Flip ACTIVE_LOW.
The sketch halts the card after reading; keep the delay at the end.
No. Basic cards can be cloned. Use it for convenience, not protection.
Yes, with a master-card mode or by storing IDs in flash.
The 13.56 MHz MIFARE cards and tags that come with RC522 kits.
6 parts: ESP32-WROOM-32 38-Pin Development Board, RC522 RFID Reader Writer SPI Module with Card & Tag, 5V Relay Module with Optocoupler, Buzzer Module 3.3–5V, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 1.5 hours. The build on this page has 6 steps.
About ₹618 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Reading an RC522 reader over SPI; Comparing card IDs with an allow-list; Pulsing a relay for a fixed time.
Anything connected to 230 V mains must be installed by a qualified electrician in a closed, earthed enclosure. Test with a low-voltage lamp first. Do not use a hobby RFID reader as the only lock on a door that protects people or valuables.
Ideas that reuse this build: ESP32 RFID attendance Google Sheet. They are listed under Take it further on this page.
Lights switch on by themselves at dusk and off again in the morning.
A precise thermostat that keeps tropical fish at a steady 25–26 °C.
Starts the pump when the tank runs low and stops it when it is full.
Tap a hidden pad to switch a lamp on or off, even through a wooden desk.
Learning project. Check every circuit and the datasheet of each part before you power it up.