Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Development Boards & SBCs

Emulating USB HID with Arduino: Keyboard and Mouse Project

Emulating USB HID with Arduino: Keyboard and Mouse Project

March 11, 2026 /Posted byJayesh Jain / 0

Emulating USB HID keyboard and mouse with Arduino is one of the most practical maker skills — it turns your microcontroller into an invisible input device for automation, accessibility tools, or creative projects. This tutorial covers the hardware requirements and complete code for keyboard, mouse, and combined HID device projects.

Table of Contents

  • Understanding USB HID
  • Compatible Hardware
  • USB Keyboard Project
  • USB Mouse Project
  • USB Gamepad
  • Indian Use Cases
  • Frequently Asked Questions

Understanding USB HID

USB HID (Human Interface Device) is a USB device class that doesn’t require drivers — every modern OS (Windows, Linux, macOS, Android) has built-in HID support. When your Arduino presents itself as an HID keyboard or mouse, the OS immediately recognises it and processes inputs as if from a real hardware keyboard or mouse. No driver installation, no custom software needed on the host.

For Indian makers, this opens up automation (pressing keyboard shortcuts, moving mouse for repetitive tasks), accessibility devices (voice control to keyboard), and custom gaming peripherals without any installed software.

Recommended: Pro Micro 5V 16M Mini Leonardo Microcontroller Development Board — Pro Micro 5V 16M — the best Arduino-compatible board for HID projects in India; uses ATmega32U4 with native USB HID support at an affordable price.

Compatible Hardware

Not all Arduino boards support USB HID. You need a board with native USB support:

  • Arduino Leonardo / Pro Micro (ATmega32U4): Native USB HID — best option in India for cost. Pro Micro available for ₹200–400
  • Arduino Due (SAM3X8E): Native USB HID — more powerful but more expensive
  • Arduino Micro: Like Leonardo in Nano form factor
  • ESP32-S3: Native USB OTG — supports HID via TinyUSB library
  • RP2040/RP2350: Native USB HID via Adafruit TinyUSB

Arduino Uno, Mega, Nano do NOT support native USB HID — they have a USB-to-UART bridge (CH340/ATmega16U2). Avoid these for HID projects.

Recommended: Arduino UNO R3 Development Board ATMEGA16U2 ATMEGA328P (DIP) — Arduino Uno R3 — note: Uno does NOT support USB HID natively. Use Pro Micro or Leonardo for HID keyboard/mouse projects.

USB Keyboard Project

#include <Keyboard.h>  // Works on Leonardo, Pro Micro, Due

const int BUTTON_PIN = 2;
bool lastButtonState = HIGH;

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

void loop() {
  bool currentState = digitalRead(BUTTON_PIN);
  
  if (currentState == LOW && lastButtonState == HIGH) {
    // Button pressed - type a macro
    Keyboard.begin();
    delay(10);
    
    // Example: Open Run dialog and type a command
    Keyboard.press(KEY_LEFT_GUI);  // Windows key
    Keyboard.press('r');
    Keyboard.releaseAll();
    delay(500);
    
    Keyboard.println("notepad");
    Keyboard.write(KEY_RETURN);
    delay(1000);
    
    // Type some text
    Keyboard.println("Automated by Arduino Made in India!");
    Keyboard.releaseAll();
  }
  
  lastButtonState = currentState;
  delay(50);
}

Available key codes: KEY_F1–KEY_F12, KEY_LEFT_CTRL, KEY_LEFT_SHIFT, KEY_LEFT_ALT, KEY_LEFT_GUI (Win/Cmd), KEY_RETURN, KEY_BACKSPACE, KEY_DELETE, KEY_TAB, KEY_INSERT, KEY_HOME, KEY_END, KEY_PAGE_UP, KEY_PAGE_DOWN, and all standard printable characters.

Recommended: Arduino Uno R3 Beginners Kit — Arduino Uno R3 Beginners Kit — start with this to learn Arduino fundamentals, then upgrade to Pro Micro for USB HID projects.

USB Mouse Project

#include <Mouse.h>

const int X_PIN = A0;  // Joystick X
const int Y_PIN = A1;  // Joystick Y
const int CLICK_PIN = 2;

void setup() {
  Mouse.begin();
  pinMode(CLICK_PIN, INPUT_PULLUP);
}

void loop() {
  int xRaw = analogRead(X_PIN); // 0-1023
  int yRaw = analogRead(Y_PIN);
  
  // Map to -10 to +10 range
  int xMove = map(xRaw, 0, 1023, -10, 10);
  int yMove = map(yRaw, 0, 1023, -10, 10);
  
  // Dead zone in centre
  if (abs(xMove) < 2) xMove = 0;
  if (abs(yMove) < 2) yMove = 0;
  
  if (xMove != 0 || yMove != 0)
    Mouse.move(xMove, yMove, 0);
  
  if (digitalRead(CLICK_PIN) == LOW) {
    Mouse.click(MOUSE_LEFT);
    delay(100);
  }
  delay(10);
}

USB Gamepad

For a custom gamepad (popular for Indian gaming cafes and game developers), use the Joystick library with ATmega32U4:

#include <Joystick.h>  // Install from Library Manager

Joystick_ Joystick(
  JOYSTICK_DEFAULT_REPORT_ID,
  JOYSTICK_TYPE_GAMEPAD,
  6,  // 6 buttons
  0,  // 0 hat switches
  true, true, false, false, false, false, false, false, false, false
);

void setup() { Joystick.begin(); }
void loop() {
  Joystick.setXAxis(analogRead(A0));
  Joystick.setYAxis(analogRead(A1));
  Joystick.setButton(0, digitalRead(2) == LOW);
  delay(10);
}

Indian Use Cases

  • Custom macro pad for Photoshop/AutoCAD shortcut keys (popular with Indian graphic designers)
  • Accessibility keyboard for physically challenged users
  • Automated testing of software UIs without mouse/keyboard
  • Custom gaming controller for Indian game developers
  • Biometric login automation (fingerprint → keyboard login sequence)

Frequently Asked Questions

Does Arduino USB HID work with Indian Android phones?

Yes, via OTG cable. Android supports USB HID keyboards and mice natively — useful for hands-free tablet control at trade shows or accessibility applications.

Can I detect if the USB HID is connected to a computer?

On Leonardo/Pro Micro, check USB_CONNECTED or use Serial for status. Direct USB plug detection is not straightforward in the Arduino HID library.

How do I type Hindi or other Indian language characters via USB HID?

Use Keyboard.write() with Unicode code points in conjunction with OS input method editors (IME). Alternatively, use keyboard shortcuts for the OS IME to switch input language.

Shop Development Boards & SBCs at Zbotic →

Tags: Arduino keyboard emulation, Arduino mouse project, Arduino USB HID, HID device Arduino, Pro Micro HID, USB keyboard Arduino India
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Development Board Pinout Refer...
blog development board pinout reference esp32 stm32 pi pico 599123
blog shelly vs sonoff smart relay module comparison for india 599125
Shelly vs Sonoff: Smart Relay ...

Related posts

Svg%3E
Read more

Battery Charger Module TP4056: LiPo and 18650 Charging Guide

April 1, 2026 0
The TP4056 battery charger module is one of the most essential components for any battery-powered electronics project. Costing under ₹30,... Continue reading
Svg%3E
Read more

Buck Converter vs Boost Converter: Voltage Regulation Guide

April 1, 2026 0
Understanding buck converters vs boost converters is essential for every electronics project involving power management. Whether you are stepping down... Continue reading
Svg%3E
Read more

Google Coral TPU: Accelerating AI Projects on Raspberry Pi

April 1, 2026 0
The Google Coral TPU (Tensor Processing Unit) transforms a Raspberry Pi from a sluggish AI hobbyist tool into a real-time... Continue reading
Svg%3E
Read more

NVIDIA Jetson Nano Projects India: Getting Started Guide

April 1, 2026 0
The NVIDIA Jetson Nano is the most accessible GPU-accelerated AI computer for developers in India. With 128 CUDA cores, a... Continue reading
Svg%3E
Read more

ATtiny85 Projects: Tiny Microcontroller for Space-Constrained Builds

April 1, 2026 0
The ATtiny85 is the Swiss Army knife of tiny microcontrollers — just 8 pins, 8 KB of flash, and a... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now