Keyboard library not included

I am trying to use the Keyboard library to type on my laptop when I swipe an RFID tag but it says I don't have the library

C:\Users\Luke\Documents\my code\Arduino\ArduinoRFIDSystem\ArduinoRFIDSystem.ino: In function 'void setup()':
C:\Users\Luke\Documents\my code\Arduino\ArduinoRFIDSystem\ArduinoRFIDSystem.ino:45:5: error: 'Keyboard' was not declared in this scope
     Keyboard.begin();
     ^~~~~~~~
C:\Users\Luke\Documents\my code\Arduino\ArduinoRFIDSystem\ArduinoRFIDSystem.ino: In function 'void loop()':
C:\Users\Luke\Documents\my code\Arduino\ArduinoRFIDSystem\ArduinoRFIDSystem.ino:90:12: error: 'Keyboard' was not declared in this scope
            Keyboard.print("You pressed the button ");
            ^~~~~~~~

exit status 1

Compilation error: 'Keyboard' not found. Does your sketch include the line '#include <Keyboard.h>'?
/*
* Read a card using a mfrc522 reader on your SPI interface
* Pin layout should be as follows (on Arduino Uno):
* MOSI: Pin 11 / ICSP-4
* MISO: Pin 12 / ICSP-1
* SCK: Pin 13 / ISCP-3
* SS/SDA: Pin 10
* RST: Pin 9
*/

#include <SPI.h>
#include <RFID.h>
#include <Keyboard.h>

#define SS_PIN 10
#define RST_PIN 9

RFID rfid(SS_PIN,RST_PIN);


int led = 7;
int power = 8; 
int serNum[5];
int cards[][5] = {
  {108, 98, 198, 56, 240}
  
};

bool access = false;

void setup(){

    Serial.begin(9600);
    SPI.begin();
    rfid.init();
    Keyboard.begin();
    pinMode(led, OUTPUT);

    digitalWrite(led, LOW);
   
}

void loop(){
    
    if(rfid.isCard()){
    
        if(rfid.readCardSerial()){
            Serial.print(rfid.serNum[0]);
            Serial.print(" ");
            Serial.print(rfid.serNum[1]);
            Serial.print(" ");
            Serial.print(rfid.serNum[2]);
            Serial.print(" ");
            Serial.print(rfid.serNum[3]);
            Serial.print(" ");
            Serial.print(rfid.serNum[4]);
            Serial.println("");
            
            for(int x = 0; x < sizeof(cards); x++){
              for(int i = 0; i < sizeof(rfid.serNum); i++ ){
                  if(rfid.serNum[i] != cards[x][i]) {
                      access = false;
                      break;
                  } else {
                      access = true;
                  }
              }
              if(access) break;
            }
           
        }
        
       if(access){
          Serial.println("Welcome!");
           digitalWrite(led, HIGH); 
           delay(1000);
           digitalWrite(led, LOW);
           digitalWrite(power, HIGH);
           delay(1000);
           digitalWrite(power, LOW);
           Keyboard.print("You pressed the button ");
           
      } else {
           Serial.println("Not allowed!"); 
           digitalWrite(led, HIGH);
           delay(500);
           digitalWrite(led, LOW); 
           delay(500);
           digitalWrite(led, HIGH);
           delay(500);
           digitalWrite(led, LOW);         
       }        
    }
    
    
    
    rfid.halt();

}

Do you use and specify a Leonardo or Micro?

I use UNO R3

No keyboard functionality with an UNO via the Keyboard library.

Seems the documentation is not correct in this aspect.

Added: the documentation is not wrong, they have a disclaimer.

oh ok

Description

The keyboard functions enable 32u4 or SAMD micro based boards to send keystrokes to an attached computer through their micro’s native USB port.

how?

With

32u4 or SAMD micro based boards

But what libraries/functions do I use?

Use Keyboard.h with an Arduino board that has a 32u4 or SAMD micro. You’ll have to buy a different board.

Good that you have a solution. Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with your project.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.