My idea seems easy:

I connect a button with arduino, then write some code and upload it to arduino. Then I open the notepad(or any other editor) on my computer. When I press the button, there will be a character "A" displayed in the notepad.

I have tried with my Arduino uno, and use Serial.write/print function to send an A to serial port 9600, but it seems the character A only shows in the serial monitor GUI.

My question is:

  1. Is "Arduino uno" is OK to implement this?
  2. If not, what other board should I use?
  3. Is Serial.write/print the correct function?
  4. Or shall I use the Keyboard.??? function?
  5. Do I have to write an application which runs on the computer and listens the serial port, and emit a real key event? (that's sad)

The Uno is not the best board for this. You may be able to get somewhere with the Virtual USB project but there are a couple of boards that are better suited for this.

Those are the Arduino Leonardo, Micro, and Due. In those, you can use the Keyboard Library just like you are using the Serial library now. This page has an example very similar to your project:

void setup() {
  // make pin 2 an input and turn on the 
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);

void loop() {
  //if the button is pressed
    //Send the message

There is a micro designed more specifically for keyboard emulation, I haven't done any experimenting with it (yet), but it's very popular in the flight simulator world where these micro's are rigged up with buttons and switches and rotary encoders to simulate a cockpit. These inputs are converted to keyboard inputs (as far as I can see).

There are some general projects here: https://www.pjrc.com/teensy/projects.html

Some more keyboard specific stuff: https://www.pjrc.com/teensy/usb_keyboard.html

More info on the teensy in the arduino environment: https://www.pjrc.com/teensy/teensyduino.html

More specifically about what you're looking for, this could be quite useful: https://www.pjrc.com/teensy/td_keyboard.html

I'm not steering you away from Arduino, it's just something else to look into

  • 1
    Go for Teensy indeed. They're small, cheap and can be used just like 'official' Arduinos. You can keep using Arduino's editor, so aside from the board nothing will change. You do not only get keyboard emulation, you can also pretend you're a mouse, a MIDI interface and many other things. – Tom Jun 16 '14 at 9:12

Your example describes collecting text - does that meet your goal or do you need to generate any kind of key-event? If you don't need to generate system events, any terminal emulator (not just the Arduino IDE) should be able listen to that same port and to log whatever it receives to a file.

  • I need it to be some kind of key-events. My final goal is to make a custom keyboard by arduino – Freewind Jun 15 '14 at 14:37

Check this video, Arduino UNO as a USB keyboard (HID device) [Anything Arduino] (ep 6), as I think this is what you are looking for.

From the youtube video you can get links to the library site and schematics.

You do need to build a small interface to connect your Arduino to a PC. I got it for Uno and Micro, but other Arduinos with latest firmware would be OK.

  • 1
    When you link to an outside source it helps if you summarize what the link (the video in this case) is about or how it helps to solve the problem. This is especially useful if the link "rots." We're trying to build a durable resource here, try to think for the long term in your answers. – dlu Jan 4 '16 at 15:08
  • If you could edit your answer to provide the links in your answer that would be a good idea, as well as a copy of the schematics, quoting the source, if copyright allows that, in case the video is deleted. – Greenonline Jan 6 '16 at 15:14

I think you also need to install processing.

See this link

It enables you to program the computer-side of the application.

  • Do you mean I have to use some programming languages to write a program running on the computer-side? Do I have to use the "processing" language? I found it's interesting, but I'm sure why it's special with Arduino? – Freewind Jun 15 '14 at 14:42
  • 3
    Processing, while a valuable addition to your arsenal when using Arduino, is not needed for your purposes. Instead, it will make things overly complex, if not impossible. – Tom Jun 16 '14 at 9:13

I have same problem I have build 12 buttons keypad with Arduino and it working with USB very well now I need to use bluetooth module instead of USB, but I can't find some code which will enable me to send press from Arduino to my PC.

here is my code which I need change for my bluetooth module CH-6 thank you for help.

#include <Keyboard.h>
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

unsigned long loopCount;
unsigned long startTime;

void setup() {
    loopCount = 0;
    startTime = millis();


void loop() {

    if ( (millis()-startTime)>5000 ) {
        startTime = millis();
        loopCount = 0;

    // Fills kpd.key[ ] array with up-to 10 active keys.
    // Returns true if there are ANY active keys.
    if (kpd.getKeys())
        for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
            if ( kpd.key[i].stateChanged )   // Only find keys that have changed state.
                switch (kpd.key[i].kstate) {  // Report active key state : IDLE, PRESSED, HOLD, or RELEASED
                    case PRESSED:

                    //Serial.print(kpd.key[i].kchar); //active keys number
}  // End loop
  • 2
    @MichelKeijzers This answer should have been voted to delete, not edited and removed from the LQP queue. – gre_gor Mar 13 '18 at 2:29
  • @gre_gor You are absolutely right, I edited it, and afterwards put it to delete (again). – Michel Keijzers Mar 13 '18 at 9:30

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.