Let's Make Robots!

optical mouse as a sensor

I need help in using an optical mouse as a sensor for my mini-sumo. i read from some place that it could be used to let the robot know that it is slowing down and will react to it. Does anyone know how i could use a mouse to do this?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

could some one explain using the optical mice with leds cause i dont have a mouse with the ball + its complicated

 pjnai123!

BaseOverApex's picture

I can't quite see how this could work, but thinking outsde the box, I suppose one could point such a mouse at the ground and collect the serial data. It would certainly tell you what direction and how fast your robot was going. If ground clearance is a problem, I suppose one could be pointed at each wheel and that would give you the speed of the wheel.

In fact, I'm going to try this sometime. I would recommend a PS/2 version NOT a USB one. The interface is serial.

How much of a "kid" are you? Could you cope with a serial input to an MCU?

BaseOverApex's picture

Let's look at a definition of "optical". A serial or PS/2 mouse with a ball is an optical mouse. Yeah, it doesn't shine a red light out the bottom, and it has a ball, but it's still optical.

You can buy them for $4. They have two wheels inside. Each wheel has an odd number of slots. (Not "odd" as in "bizzarre" but "Odd" as in "does not divide evenly by two."). These two wheels are perpendicular to one another so one rotates when the mouse moves up and down and the other when it moves left and right.

Each wheel has two light sensors arranged 180 degrees apart. The speed of the wheel is given by the rate at which the slots pass one of the sensors. The direction is given by which of the pair of sensors is passed first. (That's why there's an odd number. Two slots can't pass the 180 degree apart sensors at the same time.)

You can hook the two sensors up to a microcontroller and measure the number of slots per microsecond for each sensor and which sensor "sees" a slot first (method 1). But get this: the mouse contains a clever chip which already does this. It outputs a serial (as in RS-232) stream which indicates which wheel is turning, which direction and how fast. Just hook it up to a MCU (method 2). BONUS FEATURE: you get three extra digital inputs (the buttons) this way.

So, there you are. Two speed/direction sensors and 3 digital inputs all on what is effectively a 1-wire device.

For $4 you can afford to buy one and take a hobby knife to it.

2008-06-25 Update

I accidentally found this very good description. The mouse things I was describing is called a "quadrature encoder". Have a look at the section titled "Incrmental Rotary Encoder."

fritsl's picture
Nice. Walkthrough? Already a mini walkthrough. Must look into this one day, cool!
wow! too much info for a kid like me i think i will just stay with my normal sensors pjnai123!
jka's picture
Try putting Optical mouse as a sensor in google and see if it comes up with something. If it's doable, it's likely that someone has posted something about it somewhere.