Introduction: Digital 3D Printer Filament Counter Use PS/2 Mouse
Ever wonder how much filament did you actually use for a project? Have an old mechanical ball mouse laying around waiting for recycling? Let's convert it into a filament counter with simple Arduino and 3D printed parts. The mechanical PS/2 mouse contains fairly high-resolution encoder wheels and a simple serial interface as well as electronics to process the quadrature input signals from the encoder wheels. There are Arduino libraries written to talk to the mouse and get the direction of the distance of rotation of the encoder wheels. By connecting the encoder wheel to a filament roller, we can track the actual usage of the filament for each project by using the Arduino and display the results in millimeter on a LCD display. Since the mouse outputs the relative position to its original position in both directions, the counter is able to accurately measure and actual usage of the filament even when the filament direction is reversed occasionally due to retraction.
Step 1: What You Need
Here is a list of all the materials you need. The Dell M-SAW34 PS/2 ball mouse is made by Logitech which can be easily found online cheaply. Additionally you'll need some wires and screws, as well as access to a 3D printer (I assume you already do if you're interested in making a filament counter), and a soldering iron. Also I recommend to buy a bottle of rosin based liquid soldering flux which is also used as a coating to the filament idler wheel to increase friction.
1×PS/2 Mouse Dell Logitech 2-Button PS/2 Ball Mouse M-SAW34
1×Arduino UNO
1×Serial LCD 1602 16x2 Module With IIC/I2C Adapter Blue or green
1×12x12x7.3mm Momentary Tactile Push Button Switch with key cap
1×625zz 5x16x5 Shielded Miniature Ball Bearing
1xPS/2 socket (optional)
Dupont jumper wires or 16-18 AWG stranded wires, several
Step 2: Print the Sensor Body and the Box
I printed all the parts use PLA with 25% infill. The STL files are attached, and are also available here
Step 3: Assembly of the Sensor Unit
Take the mouse apart, what we need is the circuit board and one of the encoder wheels. The mouse has two encoder wheels for X and Y axis respectively, we only use one of the wheel on the X-axis.
1. Cut the encoder to half near the small rims in the middle.
2. Prepare the idler wheel. Use a 2mm drill to clear out the mounting hole. Coat the idler wheel with the liquid lux. Once dry, the rosin residual will help to increase the surface friction.
3. Insert the printed idler wheel into the 625zz bearing, apply small amount of the Teflon spray lubricant then insert the bearing into the printed sensor body. Use epoxy if needed, make sure the bearing and the idler wheel assembly is perpendicular to the sensor body.
3. Insert the mouse encoder wheel to the other end of the idler wheel, again make sure the encoder wheel is perpendicular with minimum wobbling.
4. Mount the mouse printed circuit board, use a tweezer to adjust the location of the IR emitter and receiver so the encoder wheel is in the middle and cover at leat 1/2 of the receiver.
Step 4: Electronics
Wiring the rest of the circuit according to the wiring schematic. You can use either Dupont jumper wires or solder the wires directly to the pin headers.
Step 5: Programming
1. Add the ps2 library to your Arduino IDE
2. Connect your Arduino to the computer and install the sketch.
Step 6: How to Use
The display has two rows. "U" is the current filament usage in millimeters. "T" is the total filament usage from the beginning. There is one RESET button. A short click will reset the "U" counter to zero, which is useful for each new project. A double click will reset the "T" to zero which s useful when replace the filament rolls. Additionally, when the unit powered up, the user is able to choose the direction of the filament movement, i.e. forward or backward depending on the mounting position of the sensor unit by pressing the Reset button.
Step 7: Dual Extruders
The mouse has two channels, i.e. X and Y. So far only X is used, but it can be easily extended with an additional channel, handy for those have dual-extrudes. Just print and assemble anther sensor body and make a small circuit board to transplant the IR emitter and receiver to the 2nd sensor body. The software is capable of reading the Y axis already, just need to add some extra lines of code and maybe the Reset to make it work.

Participated in the
First Time Authors Contest 2016

Participated in the
Design Now: 3D Design Contest 2016

Participated in the
Arduino Contest 2016
16 Comments
3 years ago
Thanks for your great design.
The actual marlin 2.0.x supports rotary encoders as filament motion sensors. You only have to uncomment "#define FILAMENT_RUNOUT_DISTANCE_MM 25" and "#define FILAMENT_MOTION_SENSOR" in configuration.h
The principle is as follows:
In FILAMENT_RUNOUT_DISTANCE_MM you define the lengh of filament extraction reliable causing an impule from the encoder disc. Marlin counts the lengh of filament extruded. Every tongle from the Sensor output resets the counter. If the counter exceeds the Filament runout distance set, this means the filament is tangled, the hotend clogged or the filament has runout. The printer pause and you can change filament, untongle it or try to clean nozzle.
So defining an output pin toggling on every impulse of the encoder wheel might be a good idea, so the filament counter also acts as smart filament sensor - like the Bigtreetech Smart Filament sensor, only much cooler and even cheaper.
Reply 3 years ago
Thanks for your comments. The purpose of this project is to accurately measure the actual filament usage, including the retraction. However with some additional programming it can also act as a filament sensor to detect breakage or jamming. At the time when the article was written, marlin has not incorporated rotary sensors.
3 years ago
I am wondering if an optical mouse would work also. The protocol is the same so it's a matter of detecting filament move and focusing the optical sensor. Any thoughts on this?
Reply 3 years ago
There's no rotary encoder inside optical mouse
4 years ago
I realize this article is old so I’m really not expecting a reply but trying anyway. How was the roller diameter determined? I have a bit of a different method of construction and not sure how the calculation was made. If I go too big the readings will not be accurate. Does the sketch define this?
Thank you for any feedback
Reply 4 years ago
The roller size is determed by experiment for best performance and size. The mouse sensor resolution is known so you can calculate mm/step. Then use the calibration factor in the software to address the error.
Reply 4 years ago
I see the cal setting now, thank you.
5 years ago
Love this idea, but it seems as tho the mouse you suggest to use has become as rare as rocking horse snot, can any other ball mouse be used or does it have to be the mouse you mentioned? Thanks
Reply 5 years ago
Any PS/2 mouse should suffice. The particular model I used was made by Logitech and pretty much the universal design underhood of HP and Dell mice. You may need to change the sensor module design to fit the different circuit board if use different brands, or simply adds wires to the IR sensors.
5 years ago
Hey, could you make one that uses the commandline instead of the lcd? i just dont have the money for a lcd
6 years ago
Hi, Can you tell me where you downloaded the library from which is needed for this project. I have everything ready to go but get an error message ' positive was not declared in this scope' when I try to run the program.
Reply 6 years ago
Seems the errors is due to the LiquidCrystal_I2C library, you can download it from https://github.com/fdebrabander/Arduino-LiquidCrys...
Please use the ps2 library that is included in this instructable, and install the latest Arduino IDE tool from https://www.arduino.cc/en/main/software.
Good luck and let me know if there's any quesiton! Thanks.
6 years ago
this is a clever piece of up cycling. Since i always use filament from the same manufacturer, i just rely on weighing my spool before a long print.
Reply 6 years ago
I have another project that would help you track the usage by weight. Check it out at http://www.thingiverse.com/thing:1935177. Thanks!
6 years ago
Thanks for this project! It looks like it could be "half" of what I'm looking for.
The problem: Knowing how much filament is LEFT on a reel. I don't care so much about color, but I don't want to start a multi-hour printing and then run out of filament.
My slicer, Simplify3D, calculates how much filament will be used for any given printing. Knowing how much filament is on a reel when new, I could simply take a pen and mark up the side of the reel as the filament is used. But, this is "old school".
My first printer, a DaVinci, required use of proprietary filament contained within a cartridge, a turn off for many. Each cartridge has a "chip" that records remaining filament. So, I would like some electronic way, such as this, to "mark up the side of the reel".
Your device records usage. So, what's needed is a way for your device to "write" to a chip on the reel. Since the reel is turning, direct wiring seems out. Perhaps an optical or IOT solution. I know I could simply make a cartridge, but I don't particularly want the extra bulk for every reel.
6 years ago
Great design, we need one of these for the printer at the library :)