3D printer filament runout and jam sensor
Build it step by step
0 of 7 doneMount the wheel
Filament turns it.
Test the sensor
Count pulses by hand.
Add the switch
Lever rests on the filament.
Add the logic
Printing, jam and runout.
Test a jam
Hold the filament still.
Test runout
Pull the filament out.
Fit it to the printer
Near the spool.
How do you build a 3D printer filament runout and jam sensor?
A wheel encoder on the filament path pauses the print if filament stops moving. You need Arduino Nano, Optical encoder speed sensor (slot, LM393), Limit switch (micro switch with lever), Active buzzer 5 V and Tactile push button 6 mm. It takes 7 steps and about 120 minutes.
- Level
- Intermediate
- Time
- About 120 min
- Parts
- 5
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Slot sensor VCC and GND | Nano 5V and GND | Power |
| Slot sensor D0 | Nano D2 | Pulse count (interrupt) |
| Micro switch common | Nano D4 | Runout switch |
| Micro switch NO or NC pin | Nano GND | Choose so the switch is closed while filament holds the lever |
| Buzzer plus and minus | Nano D8 and GND | Alert |
| Acknowledge button | Nano D5 to GND | Silences the alert |
| Nano USB | Computer or 5 V adapter | Power |
Code
A printer can run for hours with no one watching, and the worst failures are a spool that runs out, or a jam, where the motor keeps pushing and the filament does not move. The filament turns a small wheel with a slot as it passes, so the sensor produces pulses only while filament moves; a micro switch whose lever rests on the filament opens when it ends. Retractions and short pauses are normal, so the sketch waits 30 seconds with no movement, and it only starts watching after enough pulses show a print is under way. When something is wrong it sounds a buzzer and prints the reason; press the button to silence it and pause the print yourself. This version deliberately does not connect to the printer's board, because the filament-sensor input differs between printers; read your printer's manual before wiring one. Mount the sensor firmly and keep fingers and hair away from the moving filament and the hot end. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Filament runout and jam alert. The slotted wheel turns as filament moves; the micro switch lever rests on the filament.
// Board: Arduino Nano. This sketch only warns you (buzzer and serial): press the button to silence it, then pause the print yourself.
const byte ENC = 2, SWITCH_PIN = 4, BUZZER = 8, ACK = 5;
const unsigned long JAM_MS = 30000UL; // no movement for this long while printing counts as a jam
const unsigned int MIN_PULSES = 20; // pulses before the sensor believes a print is under way
volatile unsigned long pulses = 0;
unsigned long lastCount = 0, lastMove = 0;
bool printing = false;
bool alarm = false;
const char* reason = "";
void isr() { pulses++; }
void setup() {
Serial.begin(115200);
pinMode(ENC, INPUT); pinMode(SWITCH_PIN, INPUT_PULLUP); pinMode(ACK, INPUT_PULLUP); pinMode(BUZZER, OUTPUT);
attachInterrupt(digitalPinToInterrupt(ENC), isr, CHANGE);
lastMove = millis();
}
void loop() {
noInterrupts(); unsigned long p = pulses; interrupts();
if (p != lastCount) { lastCount = p; lastMove = millis(); if (p > MIN_PULSES) printing = true; }
bool filamentPresent = (digitalRead(SWITCH_PIN) == LOW);
if (!alarm && printing && !filamentPresent) { alarm = true; reason = "RUNOUT: filament has ended"; }
if (!alarm && printing && millis() - lastMove > JAM_MS) { alarm = true; reason = "JAM: filament stopped moving"; }
if (alarm) {
if ((millis() / 400) % 2) tone(BUZZER, 2200); else noTone(BUZZER);
Serial.println(reason);
if (!digitalRead(ACK)) { alarm = false; printing = false; pulses = 0; lastCount = 0; noTone(BUZZER); lastMove = millis(); delay(500); }
}
delay(100);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Filament feeding | Pulse count rises |
| Filament held still 30 s | Jam alert |
| Filament removed | Runout alert |
| Button | Alert is silenced |
If it does not work
No pulses
Check the slot sensor and the wheel alignment.
False jam alerts
Lengthen the jam time.
Runout not detected
Swap the switch contacts (NO or NC).
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the 3D printer filament runout and jam sensor?
Arduino Nano, Optical encoder speed sensor (slot, LM393), Limit switch (micro switch with lever), Active buzzer 5 V and Tactile push button 6 mm.
How long does the 3D printer filament runout and jam sensor take to build?
About 120 minutes for a intermediate maker, in 7 steps.
How do I know the 3D printer filament runout and jam sensor works?
Filament feeding: Pulse count rises. Filament held still 30 s: Jam alert. Filament removed: Runout alert.
No pulses: what should I check?
Check the slot sensor and the wheel alignment.
False jam alerts: what should I check?
Lengthen the jam time.
Runout not detected: what should I check?
Swap the switch contacts (NO or NC).
