Filament runout is just what it sounds like - your printer runs out of filament in the middle of a print and ruins the print. There is no good way to determine exactly where the printer ran out of filament and it is next to impossible to get the printer to start back up where it left off. If you have a filament runout sensor, the printer knows when it runs out and will immediately stop and wait for you to add more filament before it starts printing right where it left off.
This design is more than just a runout sensor; it can also detect filament binds. I have had filament tangle up and bind, so the print head could not pull more filament. I have also seen some spools have the end of the filament attached to the center of the spool to bind up when the end of the spool is reached - more traditional runout sensors would not detect binds resulting in a failed print.
I designed the files for this runout sensor using a free subscription to Onshape (model available here). Something like TinkerCad or any other CAD modeling software could be used, but I have had good luck with Onshape when designing more complex models. I don't have any formal training in CAD design; I am sure someone that knows what they are doing could do a better job refining the design. I have the STL files published on Thingiverse (STL available here). Go ahead and start printing the parts, there are only three and they should not take too long to print.
Most of this list is a copy/paste from the list I have on Thingiverse. I had a bunch of small screws, nuts, t-nuts, etc., leftover from my printer build so the only things I had to buy were the magnets, limit switches, and wire - your mileage may vary.
Assembly is pretty straightforward. Look at the picture at the top of this post to get an idea of what the completed project will look like. I mean, there are only 3 printed pieces and two limit switches... Again, most of this is copied/pasted from my Thingiverse post.
Designing, printing, and assembling the limit switch was the easy part for me. After some trouble finding the g-code needed for it to work, I came up with this after some digging and experimenting.
config.g (your command will be different depending on how you have the sensor wired):
; this is the older command for RepRap 2.x firmware
;M591 D0 P2 C3 S1 ; filament runout sensor
; if you have the newer RepRap 3.x firmware use this instead
; the only difference is the end stop name vs end stop number
M591 D0 P2 C"E0_STOP" S1 ; filament runout sensor
pause.g (the M109 command will need to be updated for your machine!):
; the following command work for RepRap 2.x and 3.x
M83 ; relative extruder moves
G91 ; relative positioning
G1 Z5 F360 ; lift Z by 5mm
G90 ; absolute positioning
G1 X280 Y280 F6000 ; go to the front left corner of the machine
M109 S30 ; turn off the hot end
M106 S0 ; turn off the part cooling fan
resume.g:
; the following commands work for RepRap 2.x and 3.x
; MAKE SURE YOU UPDATE THE HOT END TEMPERATURE BEFORE YOU RESUME PRINTING!!!!
G1 R1 X0 Y0 Z5 F3000 ; go to 5mm above the position of the last print move
G1 R1 X0 Y0 ; go back to the last print move
M83 ; relative extruder moves
M106 S0 ; restart the part cooling fan
The following is how I had octoprint set up before I upgraded to a Duet. This is pulled from old notes I had; your mileage may vary. First, the g-code to move the hotend when the board detects a limit switch getting triggered:
G91 ; XYZ relative
M83 ; E relative
G1 Z+10 E-5 F4500 ; retract filament, move Z slightly upwards
M82 ; E absolute
G90 ; XYZ absolute
G1 X290 Y290 ; move to a safe rest position adjust this value!
{% snippet 'disable_hotends' %}
M106 S0 ; turn off the part cooling fan
Now for the g-code that is used to restart the print:
M83 ; relative extruder
M82 ; absolute E
G90 ; absolute XYZ
G92 E{{ pause_position.e }} ; reset E
G1 F4000 ;
G1 X{{ pause_position.x }} ; reset X
G1 Y{{ pause_position.y }} ; reset Y
G1 Z{{ pause_position.z }} ; reset Z
{% if pause_position.f is not none %}
G1 F{{ pause_position.f }} ;
{% endif %}
Give it a go and see if it works! There are a couple of short videos on YouTube that show how the sensors work, the first runout sensor was an initial design before the binding sensor was added, but the idea behind it is the same:
And the binding sensor - this is the same sensor I have had on my machine for a while, and it works great: