Simple ps/2 keyboard Arduino interface

I am getting frustrated with this sample code for connecting a PS/2 keyboard with an Arduino. I can’t get it to output any characters to the serial monitor at all! I’m not sure on the pin layout of how to connect the outputs but I have the following connections:

5v – 5v on Arduino
Clock – pin 3
Data – pin 2
Ground – ground on Arduino

This sample code seems relatively straight forward but its just not working for me. (also the keyboard lights only illuminate once initially plugged in then turn off)

/*  PS2Keyboard library example
  
  PS2Keyboard now requries both pins specified for begin()

  keyboard.begin(data_pin, irq_pin);
  
  Valid irq pins:
     Arduino Uno:  2, 3
     Arduino Due:  All pins, except 13 (LED)
     Arduino Mega: 2, 3, 18, 19, 20, 21
     Teensy 2.0:   All pins, except 13 (LED)
     Teensy 2.0:   5, 6, 7, 8
     Teensy 1.0:   0, 1, 2, 3, 4, 6, 7, 16
     Teensy++ 2.0: 0, 1, 2, 3, 18, 19, 36, 37
     Teensy++ 1.0: 0, 1, 2, 3, 18, 19, 36, 37
     Sanguino:     2, 10, 11
  
  for more information you can read the original wiki in arduino.cc
  at http://www.arduino.cc/playground/Main/PS2Keyboard
  or http://www.pjrc.com/teensy/td_libs_PS2Keyboard.html
  
  Like the Original library and example this is under LGPL license.
  
  Modified by Cuninganreset@gmail.com on 2010-03-22
  Modified by Paul Stoffregen <paul@pjrc.com> June 2010
*/
   
#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  5;

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 = keyboard.read();
    Serial.println("Keyboard waitin");
    // 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);
    }
  }
}

Roble: I have the following connections: 5v -- 5v on Arduino, Clock -- pin 3, Data -- pin 2, Ground -- ground on Arduino This sample code seems relatively straight forward but its just not working for me.

The Comments state: "Valid irq pins: Arduino Uno: 2, 3" but your sketch declares IRQpin = 5. and DataPin = 8. "keyboard.begin(data_pin, irq_pin);" vs keyboard.begin(DataPin, IRQpin); Doesn't matter, the former is inside comments { /* ... */ } ? ?

Roble: That's why I am confused, I'm not sure the configuration to use!

Supposing you're using a Uno, you haven't said. Run the the keyboard data to pin 8. Change const int IRQpin = 5; to const int IRQpin = 2;

With that library only the clock pin needs to be an interrupt pin, the data pin does not, it can be most any IO pin but avoid using pins 0, 1, and 13. If your sketch uses SPI (for like SD card) or I2C or PWM or analog reads you have freedom to set the Data Line to an unused pin.

Also I had a quick look and found cheap ($1 + shipping) USB to PS2 adapters: http://www.cablewholesale.com/products/usb-firewire/usb-adapters/product-30u2-26300.php?utm_source=GoogleShopping&utm_medium=cpc&utm_term=30U2-26300&utm_campaign=USB%20to%20PS%2F2%20Keyboard%2FMouse%20Adapter%2C%20Green%2C%20USB%20Type%20A%20Female%20to%20PS%2F2%20%28MiniDin6%29%20Male&gclid=Cj0KEQiA88TFBRDYrOPKuvfY2pIBEiQA97Z8MX-sHejijKFmwVYp9L3AJo76pHCZEfnPKiRfZ0JOFn0aAiGM8P8HAQ

http://www.cablewholesale.com/

USB to PS/2 Keyboard/Mouse Adapter, Green, USB Type A Female to PS/2 (MiniDin6) Male

You can also look at https://github.com/WestfW/ps2keypolled, which allows any two pins to be used. Warning: code from 2009; may need adjusting for modern versions of Arduino.