🛠 Type with your board: HID keyboard over USB-C

Arduino UNO R4 Minima · intermediaire · Schéma : IMG-uno-r4-minima-intermediaire-1-hid-clavier-usb.svg — UNO R4 Minima par USB-C sur un PC, bouton poussoir sur pin 2 vers GND, fenêtre de traitement de texte affichant « Hello UNO R4! », badge HID.

Goal

Use the RA4M1 USB peripheral and the core's HID support to enumerate as a USB keyboard: pressing a button types text into whatever app has focus.

Wiring

Momentary button between pin 2 and GND (the internal pull-up does the rest).

Code

#include <Keyboard.h>
const uint8_t BTN = 2;
bool last = HIGH;

void setup {
  pinMode(BTN, INPUT_PULLUP);
  Keyboard.begin;
}

void loop {
  bool b = digitalRead(BTN);
  if (last == HIGH && b == LOW) {   // falling edge
    delay(30);                      // crude debounce
    Keyboard.print("Hello UNO R4!");
  }
  last = b;
}

Open Notepad, press the button: the board types. You can also send Keyboard.press/release combos for shortcuts (Ctrl+..., arrows, F-keys).

Expected result

One phrase per press, no driver needed - the PC sees a standard HID keyboard.

Common mistakes

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials