Hacking a ball mouse with Arduino

arduinohackingmicrocontrollermouse

You can view the image in greater detail on the following link:

http://i.imgur.com/z18qD56.jpg

I have been trying to hack a ball mouse (mechancial mouse) with my arduino. The objective
is to cut off the signals being given to the optical rotary sensor, and replace them
with signals sent by the arduino. This in theory would control the "x" and "y" movements
of the mouse.

Currently I de-soldered the optical sensor responsible for the "y" motion (picture 5 shows the detached optical sensor). This sensor would usually get signals from an infrared led on the other side of the rotating wheel and passes signals to the following mouse parts using "Quadrature Encoding", which is explained well in the following site:

http://www.eehomepage.com/report.php?report=20080225

So I figured that If I send the right voltage signals through my Arduino Uno R3 using the
analog pins (A0, A1), I should be able to manipulate the vertical movement of the mouse on the screen.

The results weren't great. The courser of the mouse would sometimes move upwards a bit,
and then stop for a few seconds. The intervals of this happening were very inconsistent
and slow, and I had coded it in the Arduino to preform a smooth straight line.

Here is the Arduino Code:

int ledA = A0;
int ledB = A1;
int highVar = 255;//equivalent to 5 volts in the analogWrite() function
int lowVar = 0;//equivalent to 0 volts in the analogWrite() function
int varDelay = 20;//20 milli seconds
void setup()
{
  pinMode(ledA, OUTPUT);
  pinMode(ledB, OUTPUT);
  analogWrite(ledA, 0);
  analogWrite(ledB, 0);
  delay(1000);
}
void loop()
{
  analogWrite(ledA, highVar);
  delay(varDelay);
  analogWrite(ledB, highVar);
  delay(varDelay);
  analogWrite(ledA, lowVar);
  delay(varDelay);
  analogWrite(ledB, lowVar);
  delay(varDelay);
}

Having a varDelay of 25 milliseconds seemed to produce the best results, since anything over 100 milliseconds would produce almost no movement.

My understanding is that the optical sensor has 3 pins, 1 for the voltage that comes from the device, and 2 pins that send voltage back to the device. The 2 pins that send voltage back would have the voltage lowered when the infrared light hits them. For that reason, I soldered two jumper wires to the respective pins that send voltage back to the mouse.

I am not sure if pins A0 and A1 manipulate there voltage through Pulse Width Modulation, and even if they do I am not sure if this would be the reason I am getting bad results. Would any of you know what I am doing wrong?


Edited: I was told that A0 and A1 were outputs hence would not work, thanks for the correction. However I had previously used the pints 9 and 10 (which have PWM), and when that failed went to try it with pins A0 and A1, so I still don't have a solution to my problem.

Best Answer

The output of the optical sensor in a mouse like this is a digital signal. It should swing between the mouse GND and the voltage equal to the VCC pin of the optical sensor.

To have your Arduino take the place of the optical sensor the Arduino should be driving the signals to the mouse's controller chip with digital output pins. The voltage swing between a '0' level and the '1' level should closely match that which the optical sensor was producing.