Using Arduino as a USB HID

I have the following hardware :-

Arduino Uno
Reed Switch

I am wanting to create a foot pedal as my push to talk button for Discord etc.

Basically I want to assign a Keypress when the Reed Switch is closed.

I’m not sure how to wire the reed switch to the arduino (I assume I simple choose two ports, ie 3 and 4)

Then the next question is the code itself, how do I tell it if 3+4 are closed then send ‘character’

Any suggestions very welcome :slight_smile:

The Uno is not a good choice for HID. It is possible to "hack" that type of board into working as an HID device but it makes your project much more complex. It's much more simple to use an Arduino Pro Micro or Leonardo, which is intended specifically for this usage.

I assume a nano is no good either?

I assume my code below could be on the right track?

void loop() {
  // put your main code here, to run repeatedly:

if    ??????????        //check the signal is open or closed
{
Keyboard.press(0xCA); //F9
}
  else  
  {
   Keyboard.release(0xCA);   //F9
  }
}

Yes, the Nano uses the same ATmega328P microcontroller as the Uno, which does not have native support for HID. Some Unos do have an ATmega16U2 on the board which normally only acts as the USB-serial converter but can be adapted to offer HID functionality through a complex process. The Nanos use different chips so they are actually less suitable for this usage.

The Pro Micro is a very nice little board that is compatible with the Keyboard functions in your code. The Pro Micro was originally designed by SparkFun but the clones are also available from the usual places. There is a similar official Arduino board named the Micro that is a little bigger than the Pro Micro but looks pretty nice. The Leonardo is much larger but can be used with shields. My HID projects have been pretty simple so my only requirement was for the smallest possible board, thus my preference for the Pro Micro.

Cheers

On testing with the Uno (I know it won’t work later)

https://www.arduino.cc/reference/en/language/functions/usb/keyboard/keyboardpress/

Do I need anything running on the computer side to recognize the device/ keyboard.press() command?

Thanks again.

The great thing about HID is you don't need any special driver or application. The Arduino just acts as a generic keyboard or mouse. So anything you can do manually with your keyboard or mouse the Arduino can do.

I programmed one to automatically bid pennies on tens of thousands of eBay auctions in order to increase my feedback score. You'd be amazed at how many auctions you can win doing that!

I gave one of those to a friend and he ended up adapting it to automatically like/comment/follow on Instagram pictures to automate the use of that platform for promoting his business. Pretty spammy but at least he did learn some programming and electronics instead of just buying a software solution.

Now I have repurposed my bidding machine as a print button for my computer. The printer is in a different room than the keyboard. I need to load adhesive paper into the printer before printing shipping labels so this button saves me a trip back and forth to the keyboard.

The PJRC Teensy 2.0 and Teensy++ 2.0 also have AVR/USB chips. They were first, the support code for Micro and Leo came from PJRC.

A Teensy 2.0 with pins installed fits right in a breadboad, price is $20. A knockoff Micro will cost less but does not support the work that made them possible.

Thanks All,

Now I shall sit and wait for the arrival or said hardware :) May as well 3D print a foot pedal while I wait