Access control: RFID card opens a stepper door, on an Arduino Uno
An RC522 reader (SS 10, RST 9) checks each card against the one it knows; the right card turns a 28BYJ-48 stepper on pins 2 to 5 a quarter turn to open the door, and an I2C LCD says who may pass. The whole build, an Arduino Uno and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Advanced Runs in your browser. Free, and no account needed.
The parts retail for about $40. On Mokxi they're free.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// An access control system: the right card opens the door.
//
// RC522 SDA (SS) -> pin 10 SCK -> 13 MOSI -> 11 MISO -> 12 RST -> 9
// RC522 3.3V -> 3.3V GND -> GND
// stepper driver IN1..IN4 -> pins 2, 3, 4, 5 + -> 5V - -> GND
// I2C LCD GND -> GND VCC -> 5V SDA -> A4 SCL -> A5
//
// The door knows one card, the first one on the reader's list. A known card
// turns the stepper a quarter turn (512 of its 2048 steps), waits, and turns
// it back; any other card is refused. Stepper.h steps the motor's four coils
// in order; the Stepper wants its pins as IN1, IN3, IN2, IN4.
//
// Click the reader and hold a card to it.
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Stepper.h>
const int SS_PIN = 10;
const int RST_PIN = 9;
const int STEPS_PER_TURN = 2048;
const int DOOR_STEPS = 512;
const byte KNOWN[4] = {0xC3, 0x5A, 0x1E, 0x94};
MFRC522 reader(SS_PIN, RST_PIN);
LiquidCrystal_I2C lcd(0x27, 16, 2);
Stepper door(STEPS_PER_TURN, 2, 4, 3, 5);
void prompt() {
lcd.clear();
lcd.print("Scan your card");
}
bool known(const byte *uid, byte size) {
if (size != 4) return false;
for (byte i = 0; i < 4; i++) {
if (uid[i] != KNOWN[i]) return false;
}
return true;
}
void setup() {
Serial.begin(9600);
SPI.begin();
reader.PCD_Init();
door.setSpeed(10);
lcd.init();
lcd.backlight();
prompt();
Serial.println("Mokxi Uno: access control. Card C3 5A 1E 94 opens the door.");
}
void loop() {
if (!reader.PICC_IsNewCardPresent() || !reader.PICC_ReadCardSerial()) return;
lcd.clear();
if (known(reader.uid.uidByte, reader.uid.size)) {
lcd.print("Access granted");
Serial.println("access granted: opening");
door.step(DOOR_STEPS);
delay(2000);
door.step(-DOOR_STEPS);
} else {
lcd.print("Access denied");
Serial.println("access denied");
delay(2000);
}
reader.PICC_HaltA();
reader.PCD_StopCrypto1();
prompt();
}
Parts list
5 parts, plus the jumper wires. They retail for about $40; on Mokxi they're free.
How it is wired
15 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Ground: Arduino Uno R3 pin GND; RFID reader, MFRC522 pin GND
- Arduino Uno R3 pin 13; RFID reader, MFRC522 pin SCK
- Arduino Uno R3 pin 12; RFID reader, MFRC522 pin MISO
- Arduino Uno R3 pin 11; RFID reader, MFRC522 pin MOSI
- Arduino Uno R3 pin 10; RFID reader, MFRC522 pin SDA
- Arduino Uno R3 pin 9; RFID reader, MFRC522 pin RST
- Arduino Uno R3 pin 5; Stepper motor, 28BYJ-48 with ULN2003 pin IN4
- Arduino Uno R3 pin 4; Stepper motor, 28BYJ-48 with ULN2003 pin IN3
- Arduino Uno R3 pin 3; Stepper motor, 28BYJ-48 with ULN2003 pin IN2
- Arduino Uno R3 pin 2; Stepper motor, 28BYJ-48 with ULN2003 pin IN1
- Arduino Uno R3 pin 3V3; RFID reader, MFRC522 pin 3.3V
- Arduino Uno R3 pin 5V; Stepper motor, 28BYJ-48 with ULN2003 pin VCC; Character LCD with I2C backpack pin VCC
- Ground: Arduino Uno R3 pin GND; Stepper motor, 28BYJ-48 with ULN2003 pin GND; Character LCD with I2C backpack pin GND
- Arduino Uno R3 pin A4; Character LCD with I2C backpack pin SDA
- Arduino Uno R3 pin A5; Character LCD with I2C backpack pin SCL
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.