3D Printer Filament Runout Sensor: Mechanical vs Optical, Wiring, and Firmware Setup — 2026 Guide

You check a 16-hour print at hour 14 and find the extruder clicking in mid-air, 2mm above where the filament ran out. The print is scrap. A filament runout sensor costs $3-8 and takes 20 minutes to install. It would have paused the print at hour 12, saved your part, and let you reload without losing registration. Here’s how to wire, configure, and troubleshoot one on any printer.

Mechanical vs Optical Sensors

Mechanical runout sensors use a microswitch with a roller arm that rides against the filament. When filament runs out, the arm releases and the switch changes state. They’re simple, reliable, and work with every filament type including transparent. They have one failure mode: the roller bearing eventually wears, and abrasive filament (glow-in-the-dark, carbon-filled) accelerates this. Cost: $2-4.

Optical runout sensors use an infrared LED and phototransistor pair. The filament passes between them, breaking the beam. When filament ends, the beam reaches the receiver and the sensor triggers. Optical sensors have no moving parts to wear, but they can false-trigger with transparent or translucent filament (natural PLA, clear PETG) because IR passes through the filament. Some optical sensors include a mechanical flag as a hybrid solution. Cost: $5-8.

For most users, the mechanical sensor is the better choice. It works with every filament and fails in predictable ways. An optical sensor works perfectly until you load a spool of transparent PETG and discover your runout detection is blind to that filament specifically.

Wiring the Sensor

Step 1: Identify the sensor pinout. Most sensors have three wires: VCC (3.3V or 5V), GND, and Signal. The signal wire is typically pulled HIGH by the sensor when filament is present and goes LOW when filament runs out — or the inverse. Check your specific sensor’s documentation, or test with a multimeter before wiring.

Step 2: Find an endstop or dedicated runout pin on your board. Creality 4.2.x boards have a dedicated filament runout header labeled “FIL-DET” near the Z-endstop connector. SKR Mini E3 V3 boards have “E0-STOP” or “FIL-DET” depending on revision. BTT Octopus boards have a dedicated “F.Runout” port. If you don’t have a dedicated port, any unused endstop pin (X-MIN, Y-MAX, etc.) can be repurposed — you’ll configure the firmware to treat it as a runout sensor instead of an endstop.

Step 3: Connect with correct polarity. VCC to VCC, GND to GND, Signal to Signal. Reversing VCC and GND will damage an optical sensor (the IR LED doesn’t tolerate reverse voltage). A mechanical switch is polarity-tolerant on the signal lines but still needs correct VCC and GND.

Step 4: Secure the wiring. The sensor wire runs from the control box to the extruder area — it’s a long, unsupported run that can catch on the moving bed or Z-axis leadscrew. Route it through the existing cable chain or use spiral wrap. A zip-tie every 50mm prevents sag.

Firmware Configuration

Marlin (Configuration.h):

#define FILAMENT_RUNOUT_SENSOR
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
  #define FIL_RUNOUT_ENABLED_DEFAULT true
  #define NUM_RUNOUT_SENSORS   1
  #define FIL_RUNOUT_STATE     LOW     // LOW = triggered when filament runs out
  #define FIL_RUNOUT_PIN       4       // PC4 on SKR Mini E3 V3
  #define FILAMENT_RUNOUT_SCRIPT "M600"
#endif

The FIL_RUNOUT_STATE must match your sensor’s logic. If the sensor outputs HIGH with filament present, set it to LOW (triggered on LOW = filament missing). If the sensor outputs LOW with filament present, set it to HIGH.

Klipper (printer.cfg):

[filament_switch_sensor runout]
pause_on_runout: True
switch_pin: PC4
runout_gcode:
  PAUSE
  M117 Filament runout detected
insert_gcode:
  M117 Filament inserted

Step 5: Test before trusting. Load filament, start a test print, then manually pull the filament out of the sensor. The printer should pause within 1-2 seconds and display a runout message. If it doesn’t, check the signal state with M119 (Marlin) or QUERY_FILAMENT_SENSOR (Klipper) and verify the pin state changes when filament is removed.

Runout Sensor Options Compared

Type Price Compatible Filaments Wear Parts False Trigger Risk Response Time
Mechanical Microswitch $2-4 All (including transparent, flexible) Roller bearing (after thousands of hours) Very low 50-100ms
Optical (IR Break-Beam) $5-8 Opaque filaments only None (solid state) Medium (transparent, translucent filament) 10-50ms
Optical with Mechanical Flag $6-10 All Mechanical flag pivot (long-term) Low 50-100ms
Filament Motion Sensor $10-15 All Encoder wheel bearing Low Requires 5-10mm movement to trigger
Smart Filament Sensor (BTT SFS) $12-18 All Encoder wheel Low — also detects jams, tangles Near-instant on jam; 5mm on runout

What Most Makers Get Wrong About Runout Sensors

Mistake 1: Mounting the sensor with too much friction on the filament path. If the sensor adds drag, it affects extrusion consistency — especially with flexible filaments. The filament should pass through the sensor freely. If you feel resistance when pulling filament by hand, the sensor guide hole is undersized or the mechanical arm is pressing too hard. Drill out the guide hole slightly or bend the switch arm for less preload.

Mistake 2: Setting FIL_RUNOUT_STATE backwards. This is the most common reason a newly installed sensor doesn’t work. When filament IS present, the signal state should be the opposite of FIL_RUNOUT_STATE. If you set LOW and the sensor outputs LOW with filament present, the printer thinks filament has run out before the print even starts. Use M119 to read the actual pin state and set the constant accordingly.

Mistake 3: Not enabling FIL_RUNOUT_ENABLED_DEFAULT in Marlin. The runout sensor is compiled in but disabled by default if this isn’t set. The printer will happily print an entire spool without pausing, and you’ll discover the error only after a failed print. Always test after firmware changes — pull the filament and verify pause behavior.

Mistake 4: Relying on runout detection as the only filament monitoring. A runout sensor detects the end of the spool. It does not detect jams, tangles, heat creep, or a stripped extruder gear pushing filament that isn’t actually advancing. For jam detection, you need a filament motion sensor (like the BTT Smart Filament Sensor) that measures actual filament movement. A basic runout sensor is only half the monitoring solution.

⚠️ Safety Notice: Filament runout sensors are low-voltage devices, but they connect to your printer’s controller board. Ensure all wiring is properly insulated and strain-relieved. A loose signal wire that contacts the heated bed or hotend heater terminals can send 24V back to the controller board’s 3.3V input, destroying the MCU. In accordance with 2026 electrical safety standards, all printer modifications should include wiring strain relief and insulation verification before applying power.

A runout sensor saves prints from empty spools — but it can’t fix filament that’s already compromised by moisture. Our filament dryer guide covers when moisture actually matters and which filaments need drying before use. A dry spool that triggers the runout sensor at the right time beats a wet spool that strings and pops for 12 hours before running out.

For remote monitoring of print status alongside runout detection, our OctoPrint setup guide covers camera monitoring, timelapse recording, and the Filament Sensor plugin that sends push notifications when the printer pauses for a filament change. Combined with a physical runout sensor, you can reload filament from anywhere with an internet connection.

If you’re already upgrading your control board, many modern boards include a dedicated runout port. Our motherboard upgrade guide compares SKR and Octopus boards — all of which have native runout sensor support with clearly labeled headers.

The basic mechanical runout sensor with microswitch is the reliable budget choice — but the BTT Smart Filament Sensor V2 adds jam and tangle detection for only slightly more. If you print overnight or remotely, the extra $10 buys peace of mind that a tangle at hour 3 won’t waste the remaining 11 hours of filament and electricity.


Leave a Comment

Scroll to Top