I am trying to get a response from the arduino when I press a key, but when I try to upload the code it says that it could not find 'Keyboard' with 'Keyboard.write'. Here is my code. Ignore the bits with servo stuff, that is for the project later on. I am using the arduino mega 2560.

  #include <Servo.h>
  #include <Keyboard.h>

Servo myservo;  
Servo myservo2;

int pos = 0;    
int pos2 = 0;
String comdata = "";
int lastLength = 0;

void setup() {
pinMode(2, INPUT_PULLUP);

void loop() {
if (Serial.available() > 0) {
 // read incoming serial data:
 char inChar = Serial.read();
 Keyboard.write(inChar + 1);

  • I don't know if this problem has been solved, but I am having the same issue, however I am using one of the pure USB boards; the Due. I tried writing my own sketch and it failed to compile stating: > 'Keyboard' not found. Does your sketch include the line '#include > Keyboard.h'? Side note: I realise that the Keyboard.h is meant to be enclosed by the greater than and less than signs, but for some reason this fails to show in the post. These signs were in the IDE error. I then thought I'd try one of the standard examples to compare it to, and this also failed with the same error. I have i – user27321 Oct 11 '16 at 14:06

The Mega2560 can't be a keyboard. It lacks the required hardware.

Instead you need to use one of the pure USB boards, like the Leonardo.

| improve this answer | |

To use USB communication (such as mouse or keyboard) you must have a arduino that uses an ATMEGA32U4. These are so far, the only boards that can work as a USB device.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.