How to connect Magnetic Card Reader to Arduino, PS/2????


I am trying to hook up my magnetic card reader to my Arduino Uno and display the data into the serial terminal or store in a variable. The mag reader I purchased is located here
and it comes with a PS/2 male and female and a RS 232 female connectors. I have no idea which connectors I should use, but I decided to go with the female PS/2. (Please let me know if this is a bad decision)

Currently I have cut of the female PS/2 and stripped the wires back to see
I know that BLACK = gnd, RED = 5v, GREEN and WHITE must be clock and data? vice versa?

My sketch (not really mine) compiles while using the PS/2 library. The latest lib I found is PS2Keyboard (version 2.4) found here along with the example sketch I have been using found here, also seen below.

#include <PS2Keyboard.h>

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

PS2Keyboard keyboard;

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

void loop() {
  if (keyboard.available()) {
    Serial.println("WORKING");//to see if statement is runninf DEBUGING
    // read the next key
    char c =;
    // check for some of the special keys
    if (c == PS2_ENTER) {
    } else if (c == PS2_TAB) {
    } else if (c == PS2_ESC) {
    } else if (c == PS2_PAGEDOWN) {
    } else if (c == PS2_PAGEUP) {
    } else if (c == PS2_LEFTARROW) {
    } else if (c == PS2_RIGHTARROW) {
    } else if (c == PS2_UPARROW) {
    } else if (c == PS2_DOWNARROW) {
    } else if (c == PS2_DELETE) {
    } else {
      // otherwise, just print all normal characters

I just can’t seem to get any output. I have done some debugging and I don’t think the if statement keyboard.available() is even running. Therefore the sketch isn’t picking up the magnetic reader??? I really don’t know. If I had to guess, it’s probably because I used the wires from the female PS/2 and not male, but I have no clue.

Please let me know if anyone needs more information to solve this problem.

Thanks so much in advance,


The product page and datasheet for that card reader imply that the PS/2 port is only used for power, and that the actual data appears on the serial port (DB9 connector.) That explains the two connectors - you plug one end into your PC, and the other end into a regular keyboard. The card reader siphons off a bit of the power that the PC normally sends to the keyboard, but otherwise lets the keyboard communicate normally.

There's another common type of "reader" (particularly common with bar code scanners) that plugs in this way, and actually sends the data from the keyboard OR the reader, so that the PC can't tell whether the keystrokes come from the keyboard or the reader. I guess this is what you were expecting, but I don't think it's what you have.

You should be able to read from the serial port with the SoftwareSerial library (and possibly some external hardware.) You'd want to use the "inverse_logic" option for interfacing with minimal hardware.

Thanks so much, I’ll try this right away. :slight_smile: