Turning an Old Mouse Into a Custom Measurement Device

By upcycling an old computer mouse's optical sensor, this device can measure distance with an impressive level of accuracy.

The idea

Whether it is a ruler, tape measure, or even a laser range finding tool, the devices we use to determine the distance from one point to another almost all have one thing in common: only one axis of measurement. This means taking more complex readings can become a struggle, especially when it comes to staking out the lengths of triangles without the need for trigonometry. By extracting the internal circuitry from an optical mouse, the YouTuber who goes by Create Inc was able to come up with a small, portable gadget that allows him to quickly and accurately take measurements in two axes simultaneously where the results can later be viewed on a phone via a mobile app.

How do optical mice work?

At the core of his DIY system are the guts of an optical mouse, which meant utilizing this technology for taking distance readings required some level of understanding of how they work. At the bottom of the computer mouse sits a small cutout that exposes a tiny camera with a resolution of around a mere 30 pixels by 30 pixels. After it takes a snapshot of the surface at a rate of 1500 frames per second, the current frame is compared to the previous one. By recording how far the image was shifted through counting the number of pixels, direction, position, and velocity can all be derived.

Extracting the components and assembly

The first mouse that Create Inc attempted to use had an old PS/2 plug and a well-documented sensor onboard, but after applying power, it refused to work, which meant an alternative was in order. Luckily, this next one had a standard USB output and sensor, along with a labelled PCB, which meant the PCB could simply be cut and soldered to directly. He ran a set of four wires between a Raspberry Pi Zero W's USB Bus pins and the mouse's USB pins and was able to read from it very easily within a Python script as a native HID peripheral. Finally, a small LCD screen was added to the side for tracking distance data without the need for an external device.

Measurement modes

This smart measuring tape has several modes already programmed. The first is the ability to set the measurement unit which can be changed between centimeters, inches, feet, and meters. Next, the distance can be read as either X-axis only, Y-axis only, or a combination of the two. And finally, each direction can be absolute distance or also take into account the direction for plenty of customization potential.

Programming the mouse and Android app

The last step in creating this custom measuring device was building a mobile app that could both read outgoing data and send some back wirelessly. Due to his lack of experience with Bluetooth programming, Create Inc struggled with getting the phone to communicate effectively, although it did eventually work. Upon startup, the user can pair their phone to the Raspberry Pi Zero W via the app which then sends them to a main screen. From there, the measurement units and distance read can be seen- just like on the LCD screen.

Potential uses

The smart measuring tape is an excellent way to accurately measure things in two dimensions simultaneously without giving up portability. And when combined with the mobile app's functionality, it can be a very versatile tool. For more information about this project you can view Create Inc's demonstration/build log video here on YouTube or his code here on GitHub.

Evan Rust
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.
Latest articles
Sponsored articles
Related articles
Get our weekly newsletter when you join Hackster.
Latest articles
Read more
Related articles