RFID KeyPad Keyboard

Posted on 13/12/2018 by Adam

I made a thing – it’s useful for me but probably not for you 🙂

[code]/* RFID and keypad based keyboard for making my job easier. This is a mashup of examples supplied with the * MFRC522 library by Miguel Balboa ( https://github.com/miguelbalboa/rfid ) and the Matrix Keyboard how-to * ( https://playground.arduino.cc/Main/KeypadTutorial ) * * Connect your arduino pro micro to the keypad using the pin numbers listed below in rowPins[] and colPins[]. * If you want to use different pins then you can change the numbers below to match your setup. * * MFRC522 pin connection Information: * ————————————– * Arduino Arduino * Leonardo/Micro Pro Micro * Signal Pin Pin * ————————————– * RST/Reset RESET/ICSP-5 RST * SPI SS 10 10 * SPI MOSI ICSP-4 16 * SPI MISO ICSP-1 14 * SPI SCK ICSP-3 15 */ #include <deprecated.h> #include <SPI.h> #include <MFRC522.h> #include <MFRC522Extended.h> #include <Keypad.h> #include <Keyboard.h> const byte ROWS = 4; // Number of rows on Keypad const byte COLS = 3; // Number of columns on Keypad // Define the Keymap char keys[ROWS][COLS] = { {‘1′,’2′,’3’}, {‘4′,’5′,’6’}, {‘7′,’8′,’9’}, {‘*’,’0′,’#’} }; // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins. byte rowPins[ROWS] = { 3, 8, 7, 5 }; // Connect keypad COL0, COL1 and COL2 to these Arduino pins. byte colPins[COLS] = { 4, 2, 6 }; // Create the Keypad Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); #define ledpin 13 #define RST_PIN 11 // Configurable, see typical pin layout above #define SS_PIN 10 // Configurable, see typical pin layout above MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance void setup() { SPI.begin(); // Init SPI bus mfrc522.PCD_Init(); // Init MFRC522 pinMode(ledpin,OUTPUT); digitalWrite(ledpin, HIGH); } void loop() { char key = kpd.getKey(); if(key) // Check for a valid key. { switch (key) { case ‘1’: Keyboard.write(34); //ASCII " (which is @ on a UK Keyboard. Use 64 for US Keyboard) Keyboard.print("adamwelch.co.uk"); break; case ‘2’: Keyboard.println("2"); //Print line break; case ‘3’: Keyboard.press(KEY_LEFT_GUI); // Press Windows Key Keyboard.press(‘e’); // Windows + E opens My Computer Keyboard.releaseAll(); break; case ‘4’: Keyboard.press(KEY_LEFT_GUI); Keyboard.press(‘r’); // Windows + R opens run command Keyboard.releaseAll(); delay(50); // Small delay to allow the PC to open the run command. Keyboard.print("cmd"); // This will open command prompt Keyboard.press(KEY_RETURN); Keyboard.release(KEY_RETURN); break; case ‘5’: Keyboard.press(KEY_LEFT_GUI); Keyboard.press(‘l’); // Windows + L locks Computer Keyboard.releaseAll(); break; case ‘6’: Keyboard.press(KEY_LEFT_GUI); Keyboard.press(‘r’); // Windows + R opens run command Keyboard.releaseAll(); delay(50); // Small delay to allow the PC to open the run command. Keyboard.print("https://www.youtube.com/AdamWelchUK"); // This will open the URL in the machines default browser Keyboard.press(KEY_RETURN); Keyboard.release(KEY_RETURN); break; case ‘7’: Keyboard.press(KEY_LEFT_CTRL); Keyboard.press(KEY_LEFT_SHIFT); Keyboard.press(‘M’); // Control+Shift+M opens the serial monitor in Arduino IDE Keyboard.releaseAll(); break; case ‘8’: UIDHEX(); break; case ‘9’: UIDDEC(); break; case ‘*’: Keyboard.press(KEY_LEFT_CTRL); Keyboard.press(‘Z’); // Ctrl + Z undoes last action Keyboard.releaseAll(); break; case ‘0’: Keyboard.press(KEY_LEFT_CTRL); Keyboard.press(‘C’); // Ctrl + C copies the selected item Keyboard.releaseAll(); break; case ‘#’: Keyboard.press(KEY_LEFT_CTRL); Keyboard.press(‘V’); // Ctrl + V pastes the clipboard Keyboard.releaseAll(); break; } } } void UIDHEX(){ // Is there to find an RFID card? if ( ! mfrc522.PICC_IsNewCardPresent()){ return; } if ( ! mfrc522.PICC_ReadCardSerial()){ return; } // If an RFID card has been scanned, then the id will be assembled String RFID = ""; for (byte i = 0; i < mfrc522.uid.size; i++) { RFID.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); RFID.concat(String(mfrc522.uid.uidByte[i], HEX)); } RFID.toUpperCase(); RFID.replace(" ",""); Keyboard.print(RFID); Keyboard.print("\n"); } void UIDDEC(){ // Is there to find an RFID card? if ( ! mfrc522.PICC_IsNewCardPresent()){ return; } if ( ! mfrc522.PICC_ReadCardSerial()){ return; } // If an RFID card has been scanned, then the id will be assembled String RFID = ""; for (byte i = 0; i < mfrc522.uid.size; i++) { RFID.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); RFID.concat(String(mfrc522.uid.uidByte[i], HEX)); } RFID.toUpperCase(); RFID.replace(" ",""); unsigned long decimal = strtoul(RFID.c_str(),NULL,16); Keyboard.print(decimal); Keyboard.print("\n"); } [/code]