I bought some microswitches from Aliexpress for a filament runout sensor, but I couldn't find one on thingiverse that I was sure would fit.
So I decided to make my own.
For this project you will need:
1x micro switch with lever arm
1x 4cm or longer length of PTFE tubing
2x M2 or M2.5 bolts of 10mm length or longer (whichever fit your microswitch better. If using the switches I've linked, the M2.5s fit better)
2x nuts that match the bolt diameter
2x washers that match the bolt diameter
Lay it down flat on its back and print without supports.
Depending on your printer's accuracy, the tunnel where the PTFE fits may be too loose or too tight and require some adjustment. You can change the tube's diameter from the .scad file I included. Or you could just drill it out a little if too small or wrap your tube in a little tape if too big.
Push the PTFE tube into the part to the desired position. Using a razor, xacto, or other sharp knife, cut out the portion of the tube that sticks into the interior of the unit, leaving the cut edges flush with the surrounding plastic. Be careful not to completely sever the PTFE, since we want it to be one continuous piece.
- With the PTFE tube already inserted and cut, position the microswitch so that the roller arm falls into the cut of the tube.
- Insert the screws through the back of the part and thread the nuts, but do not tighten yet.
- Position the switch: While testing the switch's action, slide the switch up and down in the housing until it is in the correct position to click when depressed and when released, the roller end pushes against the opening of the cut PTFE. You'll know you've found the sweet spot when you hear the switch click when just barely depressed, and just barely released.
- Tighten the nuts to prevent the switch from moving. Try not to move the switch during this step.
- Test the switch's action: Insert some filament through the PTFE tube, orienting the filament so that any curving will not prevent it from going all the way through the device. If adjusted properly, you should hear the switch click when the filament is inserted and again when it is removed. If the switch needs to be adjusted, loosen one screw and pivot the switch slightly until correct behavior is restored, then re-tighten the screw.
As for the wiring of your switch, you will wire the common and NC leads to your raspberry pi (if using octoprint) or to an endstop on your printer's control board (and adjust your firmware to accomodate). Look for a tutorial on youtube or something for how to get it to work.
I took out my calipers and made a rough model of my switch in OpenSCAD. I then built a little housing around the switch model for it to mount on. That's pretty much it.
I've included my scad file if you'd like to make adjustments for your own needs.