← All projects

Project record / Project

Optical Filament Runout Sensor with Discord Webhook

A custom, non-contact optical filament runout sensor for an Ender 3 V2 that pauses prints and sends Discord alerts.

Installed 3D-printed optical filament sensor assembly on an Ender 3 V2, with the filament spool and guide hardware visible.
FIG. 01Installed optical filament runout sensor on the Ender 3 V2.

TL;DR

An optical infrared fork light barrier was repurposed as a wear-free filament runout sensor for an Ender 3 V2. Klipper pauses the print when filament runout is detected and invokes a Bash script that sends a Discord webhook alert. The setup is intended to avoid unattended filament-exhaustion failures

Features

  • Non-contact infrared filament detection
  • PTFE Bowden-tube filament guide
  • Klipper-configured print pause
  • Discord webhook notifications
  • Extruder-bracket mounting
  • Use of the EXP1 mainboard port

Problem

The Creality Ender 3 V2 has no stock filament sensor. If a spool runs out during a long print, the machine can continue moving without extruding material, wasting time and the partly printed part. Mechanical sensors can introduce contact, friction, and moving parts into the filament path. The printer also has no native remote notification for this event.

Solution

A Honeywell HOA0865-L51 infrared fork light barrier was used as a non-contact filament runout sensor. Klipper monitors the sensor input and pauses the print when filament runout is detected. A Bash script sends a JSON payload to a Discord webhook using `curl`.

Architecture

Hardware

The sensor connects to the unused EXP1 display port on the Creality V4.2.2 mainboard. Pin 9 provides ground, Pin 10 supplies 5 V to the infrared LED through a 330 Ω series resistor, and the phototransistor signal connects to Pin 1 (`PC6`).

An external 10 kΩ pull-up resistor defines the logic level. With filament blocking the optical path, the input is held HIGH; without filament, the illuminated phototransistor pulls the signal LOW.

Underside of the sensor with the wiring connections and resistors visible
FIG. 02Sensor wiring and resistors

Software

Klipper monitors the input through a `[filament_switch_sensor]` configuration. A configured three-second delay and a check that the printer is actively printing reduce alerts during manual filament handling. The `gcode_shell_command` extension installed through KIAUH runs the notification script.

Screenshot of Filament Sensor in Mainsail
FIG. 05Filament Sensor in Mainsail webinterface

Mechanical

A custom 3D-printed enclosure mounts directly to the printer’s extruder bracket. The fork light barrier is held with heat-set inserts. Short PTFE Bowden-tube sections at the inlet and outlet guide the filament through the optical gap.

Implementation

The Klipper configuration connects the `PC6` input to the filament sensor and print-pause behaviour. When runout is detected during a print, the shell-command extension invokes a Bash script that posts a Discord webhook message with `curl`.

Biggest challenge

The optical gap height required three CAD revisions to align the filament to actually block the light beam reliably. Testing also showed that the mainboard’s internal pull-up was insufficiently reliable for this circuit, so a soldered 10 kΩ pull-up resistor was added to provide a defined logic level.

Result

The sensor was installed on the Ender 3 V2 and used successfully through a completed print. A test confirmed that filament runout triggered the configured automatic print pause and Discord webhook notification without observed issues. No long-term reliability or failure-rate measurement is recorded.

Screenshot of the filament runout discord notification

Technologies

  • Honeywell HOA0865-L51
  • Klipper
  • Discord Webhook API
  • KIAUH
  • Bash
  • Ender 3 V2
  • curl
  • Creality V4.2.2