The Hid protocol is used for physical interaction devices such as the mouse, keyboard and much more. Many Arduino-compatible development boards support HID (but not all), allowing the microcontroller to behave just like a regular mouse, keyboard or gamepad. These examples are intended for ESP32 boards, such as the ESP32-S3 Thing Plus from Sparkfun.
Warning! You may have a hard time re-programming your Arduino if it’s constantly taking over your mouse or keyboard! You can build in a work around with a little logic and a jumper wire or button. Start your code with something similar to this, which would block the HID behaviour, unless pin 10 is connected to GND. GND already needs to be connected before powering up the Arduino in this example.
#define HIDdisablePin 10 void setup() { pinMode(HIDdisablePin, INPUT_PULLUP); } void loop() { // Disable the mouse unless HIDdisablePin is connected to ground // This would need to be at the start of your loop() function. if(digitalRead(HIDdisablePin) == HIGH) { while(1) { /* infinite loop */ } } // The rest of your code after this line }
HID Mouse
This example gets the Arduino to act like a mouse, based on two analog Inputs. Don’t forget to connect pin 10 to GND!
HID Keyboard