Tap a card to unlock a servo latch, get a beep and a green light, and log every tap with the time.
Guide
8 parts · about ₹1,232
What you need
Step 1 of 4
The MFRC522 runs on 3.3 V. Powering it from 5 V can damage it.
Install the MFRC522 library (by GithubCommunity) from the Library Manager.
Milestone
Reader wired
Step 2 of 4
Upload the main sketch below as it is and open the Serial Monitor. Tap your card and key tag: each prints a line like 12,04 A1 2B 3C,denied. Copy those IDs into the ALLOWED list and upload again.
| 1 | #include <SPI.h> |
| 2 | #include <MFRC522.h> |
| 3 | #include <Servo.h> |
| 4 | |
| 5 | const byte SS_PIN = 10, RST_PIN = 9, SERVO_PIN = 6, GREEN = 4, RED = 5, BUZZER = 7; |
| 6 | MFRC522 rfid(SS_PIN, RST_PIN); |
| 7 | Servo latch; |
| 8 | |
| 9 | // Paste the IDs your cards print in the Serial Monitor |
| 10 | const char* ALLOWED[] = { "DE AD BE EF", "04 A1 2B 3C" }; |
| 11 | |
| 12 | String uidText() { |
| 13 | String s; |
| 14 | for (byte i = 0; i < rfid.uid.size; i++) { |
| 15 | if (i) s += ' '; |
| 16 | if (rfid.uid.uidByte[i] < 0x10) s += '0'; |
| 17 | s += String(rfid.uid.uidByte[i], HEX); |
| 18 | } |
Milestone
Your card opens the latch
An unknown card gives the red light and a low beep.
Step 3 of 4
Every tap is printed as a CSV line. In the Arduino IDE Serial Monitor you can copy it into a spreadsheet; for a permanent log, add an SD card module, or send each line to a computer with the MQTT guide.
Step 4 of 4
PICC_HaltA() is called at the end of loop().Labs
All labs