(project / Guide) RFID login
I wanted a simple way of quickly logging on to my computer without having to typing my password in and did not want to have no security either.
There are various products on the market that would solve this problem from fingerprint readers to proximity dongles but i decided to see what i could knock up with parts i mainly already had.
Looking in my micro stuff i had a RC522 RFID tag reader 3.3v :
Also an 3.3v arduino Leonardo clone aswell based on a sparkfun pro micro which also can act as a USB device such as a keyboard. This is useful as if a 5v arduino was used a level shifter would be required due to the RC522 not being 5v torrent.
How it works
When the chosen cards is presented the arduino will act as a keyboard and simply type the stored password in followed by a carriage return .
Wiring
As mentioned, both devices being the same voltage ,3.3v made wiring so easy !.
RC522 (3.3v) | Arduino pro Micro |
vcc | 3.3v |
RST | pin 5 |
GND | GND |
MISO | pin 14 |
MOSI | pin 16 |
SCK | pin 15 |
SDA | pin 10 |
IRG | NC |
Code
I used the Arduino library for MFRC522 by Miguel Balboa , so you will need to add this library to arduino.
Please note this is only a very basic example and the password is stored in plain text in your arduino document , so this is very much proof of concept and has just been thrown together. It may also be a good idea after uploading to arduino to and save your arduino document with the password blank.
UPDATE! Please also see RFID Login software Update ! for the latest software example .
// // Example By Luke (www.ls-homeprojects.co.uk) // Free to use this code how you like but please link my site // Modified example for Arduino library for MFRC522. // Credit to Miguel Balboa for provided a great library and examples ! https://github.com/miguelbalboa/rfid. // Please note this is just a proof of concept Example and should not be used for sercuity applications ! #include "Keyboard.h" #include "HID.h" // This is required for this to work with window 10 #include <SPI.h> #include <MFRC522.h> // This can be #define SS_PIN 10 #define RST_PIN 5 MFRC522 rfid(SS_PIN, RST_PIN); // Instance of the class MFRC522::MIFARE_Key key; //----------- settings ------------------------------------ #define enable_serial 0 // set this to "1" to enable serial port unsigned long my_UID = 12345; // This is the id of your card displayed in serial terminal //// // Init array that will store new NUID byte nuidPICC[3]; void setup() { if (enable_serial == 1){ // Enable serial port for getting code Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } } delay(500); Keyboard.begin(); delay(500); SPI.begin(); // Init SPI bus rfid.PCD_Init(); // Init MFRC522 } void loop() { // Look for new cards if ( ! rfid.PICC_IsNewCardPresent()) return; // Verify if the NUID has been readed if ( ! rfid.PICC_ReadCardSerial()) return; // Serial.print(F("PICC type: ")); MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); //Serial.println(rfid.PICC_GetTypeName(piccType)); if (rfid.uid.uidByte[0] != nuidPICC[0] || rfid.uid.uidByte[1] != nuidPICC[1] || rfid.uid.uidByte[2] != nuidPICC[2] || rfid.uid.uidByte[3] != nuidPICC[3] ) { // Serial.println(F("A new card has been detected.")); // Store NUID into nuidPICC array for (byte i = 0; i < 4; i++) { nuidPICC[i] = rfid.uid.uidByte[i]; } // CONVERT UID into Unsigned int as easier to match up to a saved value. unsigned long UID_unsigned; UID_unsigned = rfid.uid.uidByte[0] << 24; UID_unsigned += rfid.uid.uidByte[1] << 16; UID_unsigned += rfid.uid.uidByte[2] << 8; UID_unsigned += rfid.uid.uidByte[3]; long UID_LONG=(long)UID_unsigned; if (enable_serial == 1){ // Enable serial port for getting code Serial.println("UID as a Long int , please make a note of this and :"); Serial.println(UID_LONG); } if (UID_LONG == my_UID) { // IF Presented card = uid in settings then... type password in ! delay(100); Keyboard.write(KEY_RETURN); // modify key squence here for other logins other than windows 8/10 ! delay(1200); Keyboard.print("my_password"); //As this is plain text may be a good idea to delete after compiled . delay(400); Keyboard.write(KEY_RETURN); delay(400); nuidPICC[0] = 0; // Simple fix to allow the same card to work with this rc522 Example } } else //Serial.println(F("Card read previously.")); // Halt PICC rfid.PICC_HaltA(); // Stop encryption on PCD rfid.PCD_StopCrypto1(); }
How to use
1) First Set “#define enable_serial” = 1 to enable serial output.
2) Open a serial terminal with 9600 baud
3) Swipe a card and make a note of UIDs .
4) Add recorded card UID to line 27.
5) Add login information to the keyboard section line 113 , modify the key squence for other OS’s and applications .
Case
I designed and 3D printed the smallest case i could round the arduino and RC522. I will post this up on Thingiverse soon.
Future Improvements
1) Able to store multiple login information
2) Passwords stored encrypted
3) Add and modify data without using arduino IDE.
4) limit number of tries
5) Store the password on the Card itself
Conclusion
I have found this project really useful and use it all the time. One interesting problem that I had was when using windows 10 , I had to reconnect the USB cable every time the computer booted up but found a simple fix (add #include hid.h). The problem was due to the Arduino acting as keyboard (working ok on desktop using pro micro hid driver) but not as generic hid keyboard so not loading a hid keyboard driver .
COMMENTS