/!\ WARNING /!\
This project is on the back burner for now.
Someone else pushed the idea to completion, print his thing instead : https://www.thingiverse.com/thing:3063430
People who have printed this reported some flaws in the design. I have NOT fixed them yet! Print at your own risk.
Optical Filament runout that works even with transparent filaments.
Just print the lever in an opaque filament (black is preferred).
Push the lever down and insert the filament. When the filament runs out, the lever springs up and triggers the optical sensor.
It uses a M3 screw for the hinge.
Any spring smaller than 5 mm diameter and 6 mm compressed and 10mm expanded can do the job. A spring from a clicking pen should work. otherwise this seems to be a good match (not tested) https://www.mcmaster.com/#9657K267
Not tested yet!
V1.2 wiggled some holes to prevent slicing issues with s3d (Cura worked fine by the way lol) and added a nub to the lever for the spring.
Fusion 360 link: https://a360.co/2vgCXrf