Report inappropriate content

Filament Sensor for 3D printers and filament extruders

What it Is

This is a prototype for an optical sensor that measures the width of plastic filament in real time as it goes into a 3D printer or a filament extruder. It is prototype #3 (other 2 are on Thingiverse ).

What it Does

The idea is that with a real-time width measurement the 3D printer (or filament extruder) could compensate the extruded flow for changes in filament width. Also if there is variation between spools of filament, there is no need to calibrate for that when slicing. The g-code is independent of the filament diameter. For filament extruders, the measured width can be used as feedback in the extrusion process.This version includes a custom designed pc board as well as a housing.

For 3D Printers

A version of Marlin is modified to use the sensor data.

The sensor outputs a voltage in millimeters (3v=3mm) that is shown on the voltmeter.

I made some changes to Marlin to read the filament diameter real-time and compensate the extrusion rate. Code uses a buffer to manage the transit delay between the sensor measurement and the nozzle.

The main branch of Marlin now has initial support for the sensor. However, it does not have LCD support (yet - pull request was submitted). You can find the version with LCD support at

For Filament Extruders

This prototype sensor is compatible with the design of the latest Lyman extruder. I worked with Hugh on building the controller and incorporating the sensor into the system.

Other applications

Sensor Specs (my Estimates)


1. Accuracy: Practical usage: 0.02- 0.05mm in ratiometric mode for 3mm filament. Theoretical: The sensor has .06mm wide pixels, and with the subpixel edge detection, my guess is that it is 5-10 times better, so .01mm.

2. Sampling Speed: Internal sampling of image is 100Hz, output is averaged to update roughly once every second.

3. Limitations: May not work with clear or translucent filament. Not fully tested for 1.75mm filament but should work.

 How it works: see attached doc.



See the following video for additional info on construction and usage:


First step - decide if you want a sensor for 3D printing or Filament extrusion.




1. Get the PC board made.
See for files needed to order a board from Seeedstudio. The specs are on the PC_board_BOM.pdf.

Alternatively, use the EagleCAD files to order from somewhere else. PCB thickness is critical in the design to ensure case closes. Should be 1.6mm as listed on the PC Board BOM.

2. Order parts from the BOMs (PC Board and either the Extruder_version_BOM or Printer_version_BOM)

Alternatively, I have a small supply of presoldered and tested boards here:

Make the Case Parts

1. Print out the relevant parts
(Printer or Extrusion .stl's) in ABS with 20% infill, .5mm nozzle, .4mm
layer height.
2. Paint inside of tower and top
plate sensor area with flat black craft paint (reduces light reflections).

3. Drill out the hole in the
tower to fit an LED (if needed) using #9 (0.196inch) Drill out the screw
holes in the top plate with a #50 (0.07 inch) to allow the 2-56 screws to

Make the Electronics 

1. Use solder paste in a syringe and an electric skillet to reflow solder the parts to the PC board. See
2. Check the PC board with a meter for solder shorts and fix them.
3. Solder two 4 inch wires to the 5mm through-hole LED that will be put in the sensor tower.

4. Flash the MCU using
    • If all you want to do is load the firmware on the mcu you can use the software that came with the programmer board (USBDM board). If you install the drivers, it installs some flash programmer software, one called HCS08 Programmer. This software lets you load the compiled firmware 'hex' file (called FilamentSensorproto2.abs.s19 in the directory called FLASH in the zipped project) into the MCU. No need for the IDE in this case.
    • If you want to open the code in the IDE, see the dev tools for free from freescale: - look for the one for microcontrollers, eclipse version.

Final Assembly

1. Use ABS juice to glue the tower onto the top plate using the attached photos as a guide. Hole in tower should line up with hole in top plate.
2. Print out the Case_labels.pdf on an injet printer and cut out the label to paste on the back of the case. Glue with ABS juice. Can let ABS juice soak in to the paper.
3. Press the PC board into the printed Base Plate. Make sure it fully seats against the standoffs (use an exacto knive to clear plastic)
4. Push the Top Plate assembly onto the Bottom Plate (they should mate) and fasten with the 2-56 screws (3 for extruder version, 4 for printer)
5. Attach the LED wires to the +An and -Cath screw terminals. LED has a flat on the -Cath terminal side.
6. Insert the LED into the tower (should fit gently) and screw on the ABS Cap while holding the leads in place.


Testing and Calibration

1. Connect a voltmeter to the 'Out' terminal and 'Gnd' terminal.
2. Provide 5 volt power to the correct terminals (I use a USB charger and cut-off USB cable)
3. LEDs should light up and voltmeter should read below 1v.
4. Place a piece of calibration rod (precise 1/16 in drill rod) in the sensor and gently hold level and down. - Voltage should show >1volt. Press and hold the button on the sensor for >3 seconds - indicator LED will go off and then on when complete.
5. Output voltage should show 1.56 volts, assuming power voltage is exactly 5.00 volts. Can press button <1 sec to switch modes to absolute output to confirm calibration. - see Board_instructions file for more details.


Attach the Sensor to 3D Printer or Filament Extruder


See Filament Extruder thing for instructions for Filament Extruder:

For 3D Printer:

1. Connect the sensor to an A/D
input and +5v power on 3D printer control board - see 3D
Printer_hookup.pdf file.

2. Download the modified version
of Marlin from Github - hopefully this will be
incorporated into the official Marlin some time in the future.

3. Change the Config file as
needed for your printer. There are some new defines for the filament
sensor in this code.

4. Upload firmware into your 3D

Using the Sensor with your Extruder or Printer

See Filament Extruder thing for instructions for Filament

For 3D Printer:

1. Add custom g code to your
slicer software to enable sensor:

M405 ; turn on filament control

2. While printer is idle you can
see the filament sensor reading by keying in and sending an M407 to your
printer. It will return the diameter to the log.

What's New in this Prototype
Version (#3)

I improved the PC board (now Version 2) to use screw terminals for the connections. I removed the unused components. Board has the same dimensions as previous V1 for Prototype #2. Note that Prototype #1 had board V0 (hand-made), so board version number is one behind the Prototype #.

There are two case designs, one for 3D printers and one for filament extruders. The same PC board works in both.


Information on Prior Versions

There is lots of relevant discussion at the prior version sites:

Version 2:

Version 1:


Obtaining Parts (Vendor Sources)

1. PC Board - The files include everything you need to submit to Seeedstudio's board service:

2. Electronic components can be ordered from Mouser. Digikey is also an alternative.

3. Enco provides the calibration drill rod:

4. If you want to avoid making and soldering your own board, I am selling a limited number of completed and tested pc board kits at:

Where to take it from here:

Here are some thoughts on where to take this idea, some suggested by others:

1. It only measures diameter in 1 dimension. Filament may be oval, so measure in more dimensions. Some options are multiple image sensors, or using an RC servo to physically scan the sensor around the filament and make a geometric average.

2. Improve existing precision - use lenses or better illumination to ensure filament distance from sensor does not affect reading. Also could use small rollers to hold filament in place.

3. Improve output so that it produces a digital I2C output rather than analog voltage.

4. Update Marlin so that the sensor also checks for end of filament.

5. Sensor should work for 1.75mm filament, but more info/feedback/work needed to refine the design (I don't have a printer that uses 1.75 mm filament)

6. The calibration rod is difficult to source in Europe, so make the board work with a 3mm calibration rod as well.

7. Make a version with an Atmel processor so it can use Arduino toolchain.

8. Use existing Arduino board and sensor board:

Your email is used to contact you if we need more information.

Back to design