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


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:


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);
void loop()
  analogWrite(ledA, highVar);
  analogWrite(ledB, highVar);
  analogWrite(ledA, lowVar);
  analogWrite(ledB, lowVar);

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.

  • \$\begingroup\$ The analog pins are analog inputs, not outputs. The closest you have to analog output (which is what analogWrite() uses) is PWM through the PWM pins 3, 5, 6, 9, 10 and 11. \$\endgroup\$
    – Majenko
    Dec 7, 2014 at 16:01
  • \$\begingroup\$ I see. I Actually tried doing this with pins 9 and 10 previously and it still had the same results. Then I went to trying with the analog pins... still no good \$\endgroup\$ Dec 7, 2014 at 16:05
  • \$\begingroup\$ Have you examined the real signals on an oscilloscope, and compared them to your synthesized signals? \$\endgroup\$
    – Majenko
    Dec 7, 2014 at 16:07
  • 1
    \$\begingroup\$ Oh, and there's no ground connection between your mouse and the Arduino. Well, there is, kind of, through the USB/ps2, as long as they both go into the same computer, but not a good one. You need a direct ground connection between the two. \$\endgroup\$
    – Majenko
    Dec 7, 2014 at 16:09
  • \$\begingroup\$ I don't have a oscilloscope (don't even know what it is xP, im new to electronics/arduinos). About the ground connection... how would you go about making them shair one? I would have considered it unnecessary for the reason that the PS/2 connection should have it. On the other hand, would the fact that I didn't connect anything to pinhole where 5 volts was supplied to the optical sensor make any difference? \$\endgroup\$ Dec 7, 2014 at 16:12

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.