interfacing ps2 mouse with arduino

hello everyone,
i am doing a project on interfacing of ps2 mouse with arduino.
i want to take reading of x and y coordinate. i used these codes Arduino Playground - Ps2mouse .
but my problem is:

  1. as soon as mouse stops x and y reading resets to 0,0.
  2. its maximum count is 127 in both x and y directions.

please help me..

Hey navneet123,
as far as I can see, your second problem is caused by the data type the x- and y-positions are stored in. They’re stored in variables of char-type. This type holds 8 bit, which gives you a range of 0 to 28-1=255. If you also assume negative x- and y-movement you get a maximum of 127 in each direction.

On one hand the reset is caused by the, which returns the absolute mouse movement inbetween the period of time in which the clk-signal is on high-level. The x- and y-positions are then set to this absolute amount. That would not be a problem if you moved your mouse only once. So, the second cause ist the actual setting of the x- and y-positions als shown below:

mx =;
my =;

You see, you always get the x- and y-movement from within the last clk-high-level. If you change the code to

mx = mx +;
my = my +;

you would get a position relative to the point at when you first startet the programm/your Arduino. But keep in mind, that the char-type limits your overall movment area to a field of 256 x 256. So if you want a bigger area you should change the type to int. That would give you 16bit to store movement in.

Thanks for the help. The code is working perfectly now and giving 400 counts per cm. 8)