Having a computer measure accurately how far something has moved can be a tricky business. For robots, things like rotary encoders can be used to track position but these come with problems of their own like not accounting for wheel slip etc.
Another option to track movement is to use an optical laser motion sensor like those used in your mouse. These sensors work by taking pictures of the surface beneath them and calculating movement by looking at how far the pixels have moved from one image to another. The ADNS-9800 is one of these sensors which can capture 12000 frames per second, more than fast enough for most robotics applications. Instead of ripping apart tons of optical mice to get your hands on this chip you can buy a ready-made breakout board with a lens included. The board communicates via SPI and Jkicklighter has provided example code for the Teensy and Arduino over on GitHub. There is also a motion detection interrupt line so you can let your main processor go to sleep and wake up whenever things start moving.