Arduino Mega or Uno as a HID Keyboard
Guide based on: MitchTech
1. Download the HEX Files
Arduino Mega Firmware
- HEX file:
Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex
- Download from GitHub
Arduino Keyboard Firmware
- HEX file:
Arduino-keyboard-0.3.hex
- Download from GitHub
2. Upload the Keyboard Code
/* Arduino USB Keyboard HID Demo
* Cut/Copy/Paste keys + extra bindings for A, Z, E, R
*/
#define KEY_LEFT_CTRL 0x01
#define KEY_LEFT_SHIFT 0x02
uint8_t buf[8] = { 0 }; // Keyboard report buffer
#define PIN_COPY 5
#define PIN_CUT 6
#define PIN_PASTE 7
#define PIN_A 2
#define PIN_Z 3
#define PIN_E 4
#define PIN_R 5
int state = 1;
void setup() {
Serial.begin(9600);
// Initialize pins
int pins[] = {PIN_COPY, PIN_CUT, PIN_PASTE, PIN_A, PIN_Z, PIN_E, PIN_R};
for(int i=0; i<7; i++) {
pinMode(pins[i], INPUT);
digitalWrite(pins[i], HIGH); // Enable internal pull-ups
}
delay(200);
}
void loop() {
checkKey(PIN_CUT, 27, KEY_LEFT_CTRL); // Ctrl+X
checkKey(PIN_COPY, 6, KEY_LEFT_CTRL); // Ctrl+C
checkKey(PIN_PASTE, 25, KEY_LEFT_CTRL); // Ctrl+V
checkKey(PIN_A, 4);
checkKey(PIN_Z, 29);
checkKey(PIN_E, 8);
checkKey(PIN_R, 21);
}
void checkKey(int pin, uint8_t key, uint8_t modifier = 0) {
if(digitalRead(pin) == LOW) {
buf[0] = modifier;
buf[2] = key;
Serial.write(buf, 8);
releaseKey();
}
}
void releaseKey() {
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8);
delay(500);
}
3. Enter Debug Mode
-
Connect Pin 13 → top-right for ~2 seconds (do not exceed 2 sec)
Video guide: YouTube
when you see blinking it mean it is in debug mode
-
Open Device Manager
- You should see an Unknown Device (this is your Arduino in debug mode).
- You should see an Unknown Device (this is your Arduino in debug mode).
-
Update the driver:
- Browse to
FLIP_directory/USB
and update manually.
- Browse to
-
After driver update, the device should look like this:
4. Download FLIP
Download FLIP – the tool to flash your Arduino.
5. Flash Arduino to Keyboard
- Open FLIP → Load File → select the keyboard HEX file
- Upload and test it on your Arduino.
- After flashing, your Arduino should act as a HID keyboard.
6. Restore Arduino to Normal
- Put Arduino back in Debug Mode
- Open FLIP → Load File → select the Arduino Mega HEX file
- Flash to return Arduino to standard firmware.