The filament sensor is designed to be attached to a modified Prusa MK2 printhead (which includes the filament sensor model as well, but I wanted to separate it here from the rest). If adapted, it could be used on other printers.

I made this complex holder for a microswitch to act as a filament sensor, because I wanted to be able to attach the sensor mid-print (without unloading and reloading filament). To do so, the switch needs to be pressed using e.g. tweezers, then pushing filament in from the side, and closing the “door”.
The microswitch (plastic part: 20 x 10 x 6.5mm) is held by a 2mm thick copper wire (~35-40mm long), bent to be locked in place. I could have designed it for M2 screws, but I didn't have those at hand when I made this.
Screws needed:
1x M3x16
1x M3 hex nut
1x M4x20
1x M4x25
2x M4 hex nut

The metal lever on the microswitch has to be bent slightly in order to properly activate when filament is inserted and deactivate when empty:
When not used, the base holding the filament sensor can be lifted away by rotating backwards. Since the sensor can't be loaded from the opposite side (from below), after triggering filament runout, if the printer automatically unloads filament, this rotational movement will enable the unloaded filament to push the sensor away (instead of getting stuck or breaking something).

Model Source
