Give your gizmo the gift of sight
I get this question a lot: Why is it that an optical mouse works fine on a desk, but when you lift it up and move it around it does not pick up anything. This question typically gets asked by experimenters trying to make a visual odometer using an optical mouse. A related question is about our smaller sensors- "How far can they see?" The answer is pretty simple to explain using image formation principles in elementary optics. There is a good Wikipedia page on lenses that goes into detail, but I'll touch on the very basics here, which can be explained with one equation.
Referring to the figure above, the focal length "f" of a lens is essentially how far from a lens rays of light converge when incoming light is parallel, e.g. from an infinitely distant object. The convergent point is essentially where an image of the infinitely distant object is formed. If you hold a sheet of white paper at that location, an image of the object will form on the paper. If the object is bright enough, or if you prevent stray light from reaching the paper, you should be able to see the image. An image sensor (or a piece of photographic film for that matter) will detect the image. If you move the image sensor to the left or to the right, the image will get blurry.
Now suppose the object brought a finite distance r1 from the lens. An image of the object will still form, but at a new distance r2 from the lens on the other side. The relationship between r1 and r2 is defined by the equation:
For example, suppose the lens has a focal length of f=10mm. If you are imaging something r1=20mm away, then the equation yields r2=20mm- You'd have to put the image sensor 20mm away from the lens to grab an image of the object. If you are imaging something r1=100mm away, then the equation yields r2=11.1mm. If you are imaging something r1=10m=10,000mm away, then the equation yields r2=10.01mm. Essentially as the distance r1 to the object increases, the value of r2 drops to approach f. The "infinite distance" case first discussed is simply the case when r1=infinity, which yields r2=f.
So how does this relate to the optical mouse? The lens that typically comes with an optical mouse is designed to image the desk, which is just a few millimeters away. This short distance is r1. The lens is similarly placed r2 = just a few millimeters away from the optical mouse chip. So the focal length f of the lens was designed to work with these values of r1 and r2. (Notice how the data sheets that come with an optical mouse chip and lens pair specify how far the lens must be from the desk.) In order for the optical mouse chip to see objects further away, you need to either change f (get a new lens) or move the lens closer to the chip. (For those of you who are trying to make a visual odometer using an off-the-shelf optical mouse sensor, I recommend getting some lenses and lens mounts from Sunex and experimenting with those.)
As for whether our smaller sensors can see objects "far away"- Most of these sensors use a focal length on the order of f = a millimeter or two. So from the perspective of the above equation, this makes 1/f very large. Any object r1 = a few centimeters to infinitely far away will have little impact on the optimal value of r2. Thus objects at all of these distances are for all practical purposes in focus.