I wanted to use either Arduino Mega or Uno as a form of an interface between me and the computer. I want to apply it to the following scenario; if I press a button on a circuit board I want it to trigger an action on my computer, like scroll down.

How can I achieve this? How would the code look like and what programs would I need to translate from Arduino to Windows?

  • You need to clarify what OS you're working with. Linux or Windows? What versions, too, since this may require more than just Arduino code.
    – sachleen
    Apr 11 '14 at 23:44

For the sake of completeness, on the more traditional boards where the USB interface is not implemented from the main "sketch" processor, there are three other potential possibilities:

  • Use the (USB) serial data interface, and have software on the host computer which accepts commands over that. Obviously, the downside is requiring installation of something on the host system - installation which may require admin privileges or even disabling code signing requirements in some cases (especially if it is to inject the data into the host operating system as if it came from a keyaboard)

  • On boards such as the Uno and comparable-generation Mega which use a secondary ATmega "u" series part as a USB-serial converter, this chip can be reprogrammed to act instead as a keyboard. That could make loading sketches tricky - though it might be possible to come up with a dual-mode firmware that could switch roles under control of an external hardware or software signal.

  • The main ATmega "sketch" processor can generally implement a "not quite compliant, but workable" approximation of a low-speed USB interface in software on arbitrary I/O pins with some external matching/protection componenets. A USB keyboard is a common demo application of that.

  • For the second one, you don't need a dual firmware. IIRC you just need to flash the standard USB firmware, upload, and reflash the keyboard/mouse one again. No where near ideal, but workable. Apr 12 '14 at 19:13

Arduino Yun, Leonardo, Esplora and Due have the ability to appear as a native Mouse and/or Keyboard to a connected computer by use of the Mouse and Keyboard libraries.

Here's an example of how you would use SWITCH3 on the Esplora to active PAGE UP on your keyboard.

if (!Esplora.readButton(SWITCH_3)) {

Here's an example of using the Esplora to control the Keyboard and Mouse to control the Flight Simulator option of Google Earth.

If you want to use the Uno it's more difficult but it can be done by sending data from the Uno to a Python program running on the PC. The Python program uses the pywin library to control windows.

Here's a fully worked out Instructable on how to do it.


You can do that easily with a few of the Arduino boards that have built-in USB communications support.

You find that feature on Leonardo, Micro, Esplora and Due boards. You also find that on some Arduino compatible boards like the Adafruit Flora.

Simply plug the Arduino USB port to your computer and the Arduino will behave like a keyboard. Then you can program your sketch to perform what you want with your buttons. Check the Arduino mouse and keyboard library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.