Paused Prints

Arduino-based Filament Runout Sensor

Geoff Cohen

Issue 40, November 2020

This article includes additional downloadable resources.
Please log in to access.

Log in

Add this filament runout sensor to your 3D printer to help avoid ruined prints and wasting filament.


When 3D printing, there are few things more frustrating than running out of filament. This usually happens on very long prints as these often run unattended (overnight). Walking into the printer room and finding your 3D printer busily 'air printing' nothing at all from an empty filament spool is really annoying, as is having to throw away a ruined print that's nearly completed and wasting filament.

Our Filament Runout Sensor (or FRS) prevents this, pausing the 3D printer when it runs out of filament, allowing you to add another roll of filament and resume printing, without ruining a print or wasting filament.


Filament Runout Sensors, as the name suggests, use a sensor to detect whether there is filament. If there is filament on the spool then continue printing normally, but, if the filament runs out or breaks, pause printing and display a message to add another spool of filament plus an option to resume printing.


Easy to use

The most common problem we found was difficulty in inserting the filament through the Runout Sensor body, as most have internal gaps - meaning the filament won't push through the filament guide unless the filament is absolutely straight, which, coming off a small spool, isn't likely. As an example, our first version Runout Sensor was a really elegant optical sensor design, but unfortunately, when installed on a 3D printer it was nearly impossible to push curled filament through the Filament Runout Sensor body (the yellow sensor with a red arrow), and we found that in a real 3D printer, as opposed to bench testing, it was extremely tedious having to straighten the filament before it would go through the optical FRS.

In contrast, it's easy to push even very curly filament through our second version Filament Runout Sensor as we have eliminated the internal gap, so filament can't jam and doesn't need straightening. It's also cheap and easy to make, only needing one 3D printed part, a short length of Teflon tube, and an affordable micro switch (plus assorted wire and connectors, depending on your model 3D printer).

Avoids excessive friction

A Filament Runout Sensor should not add much load on the extruder, as excessive friction may even stop extrusion. With direct drive extruders, friction can even cause layer shifts. In our Filament Runout Sensor, we have used Teflon tube throughout to minimise friction.


Wearing out is inevitable for Filament Runout Sensors that use a microswitch with a small wheel. These wheels don't have a 'real' bearing, just a rivet that will wear out relatively quickly. When they do, the microswitch needs unsoldering and replacing. Our FRS uses a 11mm short piece of Teflon to trigger the microswitch, so if it ever wears out, it's quick to replace, and only costs a few cents.


The FRS needs to reliably trigger every time. Once again, simple designs that use a micro switch with wheel aren't great. The required 2.6mm movement at the wheel to trigger from the fully open position is larger than the 1.75mm filament diameter available, so the micro switch lever must be pre-loaded by pressing down slightly until it's nearly triggered, reducing reliability.

In contrast, our FRS has the trigger much closer to the fulcrum, and only needs the lever to move 1.2mm from fully open to triggered, much less than the filament diameter. In testing, we have never experienced unreliable triggering when there is no filament present in the Teflon guide tube. Also, as long as the filament spool is correctly oriented, its always been easy to push the filament all the way through the FRS body.

SPDT 125V 3A Sub-Miniature Micro Switch with Lever SM1036 from Jaycar.

Our FRS uses a limit switch with a short piece of Teflon as a low friction trigger. Again, to provide low friction, a 100mm guide piece of Teflon tube goes through the FRS body. To make insertion easy, instead of cutting this tube into two pieces and having the filament jam at the join, we cut a small groove into the Teflon tube.

These 3D renders show how our FRS works. These have filament present (shown in red), with the darker blue Teflon trigger piece held up by the filament, forcing the micro switch to trigger and go open-circuit as we use the C and NC terminals.

Now, look at what happens with NO filament. The Teflon trigger piece drops down into the groove, releasing the micro switch lever and closing the circuit.

The Build:

The Filament Runout Sensor MUST be inserted somewhere between the filament spool and Extruder input. It won't work on the OUTPUT side of the Extruder because it relies on the extruder pulling filament through the sensor to detect filament running out or breaking. It's bidirectional, so it doesn't matter which end is first.

Parts Required:JaycarAltronicsCore Electronics
1 x Limit SwitchSM1036-POLOLU-1528A
4 x M3x15mm Screws*HP0406H3130AFIT0273
1 x Length of Teflon TubeRefer to text below

Parts Required:

1 x Limit SwitchSM1036
4 x M3x15mm Screws*HP0406
Optional leads for different 3D printers:JaycarAltronicsCore Electronics
Plug-to-Socket Jumper LeadsWC6028P1017ADA1954
Linker 200mm Jumper LeadXC4558--
Linker 500mm Jumper LeadXC4559--
Linker 1000mm Jumper LeadXC4560--
JST Connector Kit (2.54mm)--FIT0255
40 Pin Female Header Strip ^HM3230P5384PRT-00115
40 Pin Male Header Strip #HM3212P5430ADA2671

Optional leads for different 3D printers:

Although any standard 3D printer 4mm Teflon tube is OK, we used Capricorn XS tube as we prefer it and are (slowly) replacing the 4mm Teflon Tube in all our 3D printers with Capricorn XS. It has noticeably lower friction and importantly it also withstands higher temperatures than standard Teflon. In Australia, it costs roughly $2 per 100mm. We purchased ours from, part number CAPRICORN-XS-175-100.

*Quantity shown, may be sold in packs.

Hook-up wire and heatshrink is also required.

^ Cut off 2 x 3-way for ISP and glue together, 1 for pin 29.

# Cut off 1 pin for Ender "pin 29" connector.


We've endeavored to make installation easy with most 3D most printers.

For a 3D printer with a Teflon feed-in tube between Spool and Extruder, use the Teflon cutting template to make the groove wherever is convenient. Otherwise, use a (roughly) 100mm piece of Teflon tube and cut the groove as shown here.

Whichever method you use, once the groove is cut, remove the Teflon tube from the Teflon cutting template and position it inside your FRS, making sure the groove is positioned correctly, then tighten the four screws just enough to stop slippage of the Teflon guide tube.

Insert the 11mm Teflon trigger part. There is a small viewing window on one side so you can see the trigger moving up and down.

We have also included a mount for an Ender 3. It only required a simple adaptor plate between the sensor and frame, using a 100mm piece of Teflon tube for the filament guide through the FRS. The length isn't critical. It just needs to go all the way through the FRS body with some overlap.


For easy filament insertion, orient the FRS so the filament curls towards the bottom. This ensures the filament slides easily along the Teflon tube and doesn't get stuck at the trigger groove. The Ender 3 picture shows how it should look.

There are four holes available for mounting, they are designed to self tap M3 or small woodscrews. Another option is to drill them out to 3mm and use M3 nuts for attachment.



For Mega/RAMPS printers, the FRS is connected to the Servo 4 connector, between the signal pin and Ground.

For the motherboard connectors, we cutoff the lengths needed from the 40 pin female header strip, using heatshrink as both insulation and strain relief.

Strangely, on one of our RAMPS boards, the servo 4 connector malfunctioned, so we used the Servo 3 connector (the yellow 3-way connector shown here) and changed the value of FIL_RUNOUT_PIN in the pins_RAMPS.h from the default 4 to 5.

Note: The black connector on servo 1 actually goes to an actual Servo, part of a Nozzle Cleaning system we are currently developing.


It's slightly more complicated with Creality printers, as their budget motherboard doesn't have any spare connectors, however, if you have good soldering skills it's not that difficult. Just solder a pin in place to access the unused "pin 29" or else buy a "pin 27" board.

The wiring is straightforward. Just run two wires (or thin figure 8 flex) from the FRS microswitch (C & NC pins). One lead goes to the pin 29 connector, the other goes to ground (As the microswitch is electrically isolated, the polarity of the wires doesn't matter).. We made a 6-pin socket and the ISP ground pin connector from the 40 pin female header strip. The pictures show the extremely simple wiring.

The two thin black wires come from the FRS limit switch. The single yellow connector in the centre is pin 29, and the 6-way connector on the right is the Ground connection using the ISP plug.


We have included a preconfigured version of Marlin (1.1.9) for the Ender 3, with extra comments at the beginning of "configuration.h". This version works with the standard Z-axis limit switch and also has Auto Bed levelling enabled if you want to add an inductive sensor probe or a BL Touch using a "pin 27" board at some stage. If you haven't previously installed an updated Marlin on your Ender, you will need to install a bootloader. We showed how to do this in Fixing Firmware - Part 2, in DIYODE Issue 34. For those of you who just want to modify your existing Marlin firmware for a different 3D printer, you need to make the following changes. In Configuration.h, to enable the Filament Runout Sensor option, uncomment the line with #define FILAMENT_RUNOUT_SENSOR, and also change FIL_RUNOUT_INVERTING to true.

The relevant block of code is:

  #define NUM_RUNOUT_SENSORS   1     
  // Number of sensors, up to one per extruder
  // Define a FIL_RUNOUT#_PIN for each
  #define FIL_RUNOUT_INVERTING true  
  // set to true to invert the logic 
  // of the sensor.
  #define FIL_RUNOUT_PULLUP          
  // Use internal pullup for filament runout pins


To change the servo connector used, in pins_RAMPS.h change FIL_RUNOUT_PIN to the required servo number. As the numbers aren't obvious, we've listed the four servo pins here, as used in our own version of Marlin.

  #define FIL_RUNOUT_PIN    5 
  // default=4 - S4==D4, S3==D5, S2==D6, S1==D11


We have already modified pins_MELZI_CREALITY.h to use pin 29 for you, but if you want to experiment with a "pin 27" board, you need to change FIL_RUNOUT_PIN to 27 like this:

#define FIL_RUNOUT_PIN     29


For many 3D printers, you can easily test your FRS by using GCODE M119 - "Endstop States". Type M119 into your Arduino communications window (don't forget to set the correct com port and baud rate) and it will display ‘filament : open’ when filament is present and ‘filament : triggered’ if you remove filament from your FRS. We used the C and NC limit switch connections as this allows multiple Filament Runout Sensors to be connected in parallel.

An extreme test, we found the curliest filament possible on a very old, nearly used up spool and installed it on one of our experimental home brew 3D printers. The FRS triggered perfectly, and the filament inserted easily.


The Filament Runout Sensor is a single 3D printed part that only takes an hour to print with supports.

When finished, make sure the limit switch pushes in place easily. As with most 3D prints, some sanding/filing may be required. Depending on your printer, you may also need to drill out the 4mm hole for the Teflon 100mm Guide so it slides in easily, and also drill out the 2mm holes for the limit switch mounts. Any 2mm diameter rod can be used here, we used some 2mm carbon fibre rod leftover from the "Modular marble machine" in DIYODE Issue 38 to hold ours in place.

We have also included a Teflon tube cutting template as a (reasonably) easy way of making the groove in the 100mm Teflon guide using a small hobby knife or scalpel. Just remember to always keep your fingers away from the sharp edge - if you look at it and think, ‘gee that could be bad if I slipped’ - Murphy's Law says it probably will - so just make sure fingers aren't there.


We would like to see if it's feasible to design and 3D print a DIY Filament Runout Sensor that, in addition to checking for broken/missing filament, will also detect filament spool jams and blocked nozzles. These features are included with some high end, much more internally complicated (and expensive) commercial Filament Runout Sensors.

like us, you are always trying to improve your 3D printer, having resources to use if you have problems is a big help. Using 3D printer Facebook groups like ‘3D PRINTING ALCHEMY ( Australia )’ helps too.