Introduction: Connect PS/2 Keyboard to Arduino

Picture of Connect PS/2 Keyboard to Arduino

Hi everyone, this is also an Interesting project that brings 106 Inputs to your Arduino. Can't believe? Follow the project and see how this happens with a PS/2 Keyboard.

OK First of all you need

  • Arduino (UNO)
  • PS/2 Keyboard
  • PS/2 Keyboard connector

Step 1: Keyboard Conection

Picture of Keyboard Conection

Following is the pin-out of the Connector. There are 4 wires coming from the keyboard and their connections to arduino Digital pins are as follows.

  • 5V :- Arduino 5V out
  • Ground :- Arduino GND
  • Clock :- Arduino Pin 3
  • Data :- Arduino Pin 8

Step 2: Code

First include this library to Arduino Software.

#include < PS2Keyboard.h>

const int DataPin = 8; const int IRQpin = 3;

PS2Keyboard keyboard;

void setup() { delay(1000); keyboard.begin(DataPin, IRQpin); Serial.begin(9600); Serial.println("Keyboard Test:"); }

void loop() { if (keyboard.available()) { // read the next key char c =; // check for some of the special keys if (c == PS2_ENTER) { Serial.println(); } else if (c == PS2_TAB) { Serial.print("[Tab]"); } else if (c == PS2_ESC) { Serial.print("[ESC]"); } else if (c == PS2_PAGEDOWN) { Serial.print("[PgDn]"); } else if (c == PS2_PAGEUP) { Serial.print("[PgUp]"); } else if (c == PS2_LEFTARROW) { Serial.print("[Left]"); } else if (c == PS2_RIGHTARROW) { Serial.print("[Right]"); } else if (c == PS2_UPARROW) { Serial.print("[Up]"); } else if (c == PS2_DOWNARROW) { Serial.print("[Down]"); } else if (c == PS2_DELETE) { Serial.print("[Del]"); } else { // otherwise, just print all normal characters Serial.print(c); } } }

Step 3: Testing

So we have finished our coding, Upload it to arduino and keep the Arduino connected to PC.Then open the Serial Monitor on Arduino Software and Press some keys on the Keyboard connected to Arduino and you will see It prints what you type on that keyboard.Comment your ideas.


AliK140 (author)2018-01-05

Hi sir,

I have pannel look like keyboard ..can you help to interface with it..Thank you

simone.mastroianni.04 (author)2017-06-17

Please help me! I followed all the steps and did not succeed! I attach you to the pictures

And The keyboard sometimes blink when is connected to arduino

Did you get a solution? I have the same problem.

susyrobl. (author)2017-07-03

excelente!, muchas gracias, funciona perfecto!, pero no con adaptador USB a PS/2.

jmacias2 (author)2016-11-30

It works nicely, thanks

thereminhero made it! (author)2016-11-20

Works perfectly! And with a USB keyboard using a converter. If you need the key presses including the "keyup" information, I'd recommend this library instead:

Gabrielin (author)2016-10-22

My Keyboard doesn't seem to turn on when connecting the 5V and GND, but it's an RJ12 keyboard, so I'm not really sure if it's the same pinout (I looked up the pinout of a PS/2 to RJ12 adaptor and it seemed pretty straightforward)

VarghaH made it! (author)2016-01-01

I made it right now. Thanks to djsadeepa it took just a minute and it's working perfectly fine.

KarínS5 (author)2015-11-05

hi, I have done this proyect and it doesn´t work :c

About This Instructable




Bio: My life is Not only Writing Lines of Codes, But gaining something good. I'm simple in physical world but Very complex in ICT word.
More by djsadeepa:Control Arduino With Facebook - The Easy wayArduino + PS/2 Keyboard controlled LED FlasherConnect PS/2 Keyboard to Arduino
Add instructable to: