Arduino as Keyboard

Hey all,

I've built a custom input device, similar to a one-handed keyboard, around the arduino. Now I'm trying to figure out how can I get the PC to recognize the arduino as a keyboard, and communicate keystrokes.

Right now I'm sending data over serial to an application on the PC, when then generates keyboard events. This approach is obviously not optimal, plus it doesn't work when DirectInput apps, etc, are running.

Any ideas?


One idea that comes to mind is to hack an actual keyboard. Some use matrices where it scans all the buttons row by row and senses if any of the columns are connected. Maybe you could have the arduino put voltage to the columns when it senses voltage from the right row?

To the best of my knowledge, because of the hardware, the computer will only recognize the usb connection on the arduino as a serial link, not as a HID.

I have hacked a keyboard before using transistors to toggle multiple key presses (such as Ctrl + anykey) which worked remarkably well. Unfortunately I don't have any of that project documented but there is some good information about that technique on this page

I think it would not be difficult for an Arduino to emulate a PS/2 keyboard output. If I recall correctly, this is a 0 - 5VDC serial interface.

You could then cut up a PS/2 keyboard cable (you should be able to find an extension cable) to get a cable with a male PS/2 (actually a DIN-style) plug.

That connector would plug into a PS/2 to USB converter available for about $US5. Here's an example:


Now I'm trying to figure out how can I get the PC to recognize the arduino as a keyboard, and communicate keystrokes.

If you haven't seen it yet, has a link to a library at the very bottom of the page. Scroll down until you get to "Emulating a PS2 device".

The library can be used to make an Arduino act as a PS2 mouse or a PS2 keyboard.

Thanks for the responses.

I have previously used the hacked keyboard approach for other input devices, mainly arcade controllers which have only a few buttons/switches. The problem with that is that representing a standard 101 key keyboard requires a lot of pins (you'd have to control a 10x11 matrix at least). I'm sure there are clever ways to reduce the pin count, but I'm looking for a more direct approach.

Emulating a PS2 device looks interesting. I'll play around with the ps2dev library linked earlier.

Thanks again.

I haven't seen any example of using an Arduino as a keyboard, but have seen several projects that use the various Atmel chips plugged into the USB port acting as a keyboard etc.

Do a search in Google for "AVR HID" (HID = Human Interface Device, which is the category keyboards belong to). It should return a number of examples, and you might be able to adapt the code from one of these, or turn your design into a standalone device rather than being an arduino.

OlJanx, did you get the ps2dev to work? Because I can't figure out what to do with it.. I would appreciate some help.

For the record includes code and a shield design for the Arduino acting as an USB keyboard. :)