Enable Auto Leveling for Your 3D Printer With an Inductive Sensor (Marlin Firmware)

488,545

931

119

About: Make all the things!

Intro: Enable Auto Leveling for Your 3D Printer With an Inductive Sensor (Marlin Firmware)

This Instructable covers how to setup Auto Leveling for your 3D printer using Marlin firmware typical of many 3D printers such as Makerfarm kits and others that use RAMPS 1.4 + Arduino based controllers with an Inductive sensor.

*View All Steps for Screen Shot, Detailed Text and Image Instructions*


List of Supported boards from the Marlin RepRap Wiki page:
"Works on RAMPS 1.4, Ultimaker, Sanguinololu, Generation_6_Electronics, and probably other controllers based on AVR 8-bit MCUs."

Lots of other firmware and print boards support Auto-leveling. Only Marlin is covered in this Instructable. Check your firmware maker for support.

Benefits
For those who 3D print a lot, manually leveling a 3D printer can be time consuming and a bit mysterious. Getting it "just right" requires a good eye and constant attention while printing the first layer. Thankfully, there's Auto-leveling.

  • Save time messing with springs and screws on your print bed. Run the Auto-level procedure before every print or just one time for each start-up of the printer.
  • Less issues related to un-level print beds like parts coming up on one corner and nozzles jamming because the print started too close.


Summary
To set up your printer for auto-leveling, you will be replacing the z-probe with an inductive sensor like this one and updating your firmware. You will need to make a mount for your z-probe. This feature will enable your printer to take several bed leveling readings and calculate a level plane so your prints are always level. While printing each layer, you z-axis will be in constant motion to compensate for an un-level bed.

Some printer makers use an older firmware version or might be missing auto-leveling in the config. In any case, you may want to get the latest marlin here. A fresh version of marlin will require you to re-configure your firmware. If you're unfamiliar with this and your printer is a manufactured kit, you can pull up their firmware version for a side-by-side comparison. Setting up Marlin is fairly easy by reading though the configuration. file. I recommend an update your firmware and test before enabling auto-leveling to make sure everything works. Covered are some basic steps involved in updating firmware. If you're nervous about messing things up, have a default firmware to go back to.


You will need

  • An auto-leveling sensor. I use the $4.48 LJ12A3-4-Z/BY Inductive Proximity Sensor on eBay (orange tip) that worked on my RAMPS 1.4 without any modification. There is a similar one LJ12A3-4-Z/BX (blue tip) that may require you to supply the sensor with 12v then reduce it's output to work. There's a quick video by Tom's guide here that includes set-up and modifying your sensor (if it doesn't work by default). Detecting Distance should be at least 4mm.

    *****EDIT***** user: mickeypop recommends the LJ18A3-8-Z/BX (8mm sensing distance). This should be a much easier sensor use by not needing to be mounted so close to the print surface.

  • A bracket to hold your sensor on the extruder carriage. There are quite a few examples on thingiverse.com. Any secure attachment that mounts close to your nozzle (not too close) and doesn't get in the way of normal motion should work.
  • Foil tape (available at the hardware store) or copper tape. If your print bed is aluminum, you won't need this. If there's glass on your print bed the sensor will most likely not be able to sense a far enough distance (if using 4mm sensing distance sensors).
  • 3D printer, USB, PC or Mac



Ready? lets do this!


Next step: Wire and test the sensor -->

Step 1: ​Wire, Test and Mount the Sensor

The auto-leveling sensor will be replacing your 3D printers z-end stop on your control board. You won't need the old z-stop because your sensor will be probing the bed for it's z-position.

Make sure your sensor has a detecting distance of at least 4mm. In reality, this might be lower depending on the sensing material. Your sensor should be mounted close to the nozzle and able to reach near the corners of your print bed when mounted. There's a quick video by Tom's guide that includes set-up and modifying your sensor if you have the LJ12A3-4-Z/BX (blue tip) or find out yours requires voltage modification.

The sensor mentioned in this indestructible has an LED that turns on when triggered. It might be dim or not light at all if the sensor isn't getting enough voltage.

For the mount, 123D design is perfect designing simple objects like this and of course, thingiverse.com.

Wiring the LJ12A3-4-Z/BY Inductive Proximity Sensor:
1) Locate and disconnect the z-probe from your control board.

2) Connect the output voltage wire (labeled V-out [brown] in this case) to the S signal input on the same row of 3 pins your old z-end stop was connected. On RAMPS boards this pin is nearest to the outside of the board of the rows of endstop pins.

3) Connect the other 2 wires labeled + and - to a corresponding positive and negative power source on your board. This can be directly to your 12 power supply, where 12v connects to your board or, you can use the auxiliary 12v pins on the RAMPS board. (See RAMPS diagram).

4) The sensors mentioned here are "normally open" switches meaning, that signal is only sent to the board when triggered. You may need to check this line in your firmware. False = Normally Open (see picture) or CTRL+F search "Z_MIN_ENDSTOP_INVERTING" in the Arduino Sketch. (more about firmware in the next step)

5) Test the sensor on some metal, aluminum, copper, etc. The LED should light. For a final test, have the printer power disconnect / e-stop handy just in case and raise the z-axis manually to a safe height and home the z-axis (or all axis) and try to manually trigger the inductive sensor while it's above the print bed. If it worked like your old end stop, you're ready to mount the sensor and configure your firmware.

Design a sensor mount and choose level points
These sensors only have a sensing distance of ~4mm. Ideally, the sensor mount should be adjustable from a location that is lower than the tip of the nozzle to a few millimeters above. The z-axis offset can be adjusted in your gcode later. The ideal position for a 4mm sensor could be about 3mm higher than the nozzle. Set the sensor much lower than the nozzle at first to avoid bed-crashing.

Mount the sensor and move your hot end carriage around to 4 points and put 4 pieces of foil (or copper) tape under locations nearest the 4 corners of your print bed that your sensor can reach. It might help to put large pieces down temporarily until you fine-tune exactly where they will go. You should have at least 1-2cm² of tape for these sensors when complete.

*Plastic stuck on the nozzle can sometimes prevent probing and cause bed crashing.*
Clean or Pre-heat your extruder before homing or auto-leveling to avoid this.

Next step: Firmware Setup -->

Step 2: (Marlin) Firmware Set-up for Auto-leveling

Skip to # 5 if you're familar with Configuration.h in Marlin

1) Download install the Arduino IDE and get the latest version of Marlin or your printer MFG available version that has auto-leveling in the Configuration.h file.

2) Un-zip the Marlin contents into any specially named folder.

3) Open the "marlin" folder and double click on the "Marlin" Arduino file to launch the Arduino IDE sketch editor. If this doesn't work you can open the Arduino IDE then go to file > open and select the marlin file inside marlin.

4) With the Marlin Sketch open click on the [Configuration.h] tab. This is where all of the settings are located for setting up your 3D printer from scratch as well configuring the auto-leveling feature.

***************

The following covers firmware configuration for 4 point leveling.

5) Scroll to the section labled: "Bed Auto Leveling". Enable by removing " // " at the start of the line. (see marlin firmware comments and screenshot above. 4 point leveling is enabled by default.

6) Adjust the position coordinates to match the location of the foil tape on the print bed.

The position of the coordinates can be a little confusing. In this example, LEFT and FRONT are set to zero because the home position is 0,0 on the printer. RIGHT is the next probing position. Measure how far your sensor travels along the X axis (left and right usually) to the next piece of foil tape and use this number (in mm) to check the RIGHT position. Do the same for BACK (y-axis). Here's an example from my config.

#define LEFT_PROBE_BED_POSITION 0
#define RIGHT_PROBE_BED_POSITION 225
#define BACK_PROBE_BED_POSITION 278
#define FRONT_PROBE_BED_POSITION 0

In the above example, the printer will probe the following locations in this order:
X0,Y0
X225, Y0
X225, Y278
X0, Y278


*Optional*
Set your probe to lift up between each probing. (see screen shot)

7) file > save, then update your firmware by connecting your board via USB and clicking the arrow button. If this is the first time you've connected your ramps and updated firmware, a few driver installs and reboots may be necessary.

Next Step: Auto-leveling start gcode G29 -->

Step 3: Auto-leveling With Gcode G29

Auto-leveling is a command that is run after the " G28 ; home all axis " gcode line in your start code or run once in a separate file each time you boot up your 3D printer. At this point, you may need to adjust your firmware a few times to get the probing locations set correctly.

The auto-leveling command is: G29

You may need to add a G92 line to tell your printer to lower the nozzle after probing. In this example, my nozzle is .9mm above the print bed after leveling.

I run code like this for auto-leveling. You can make a separate text file and put this on your SD card or run it at the start of every print.

G28 ; home all axis
G29 ; Auto Level
G92 Z.9 ; Lower = Z Pos, Lift = Z Neg

^if the nozzle is too high when printing, raise the Znumber. If it's too close, lower it.

Once you're happy with the probing locations, you can use Pronterface aka PrintRun to run the G29 command or put it at the start of all your prints.

The above screenshots show auto-leveling enabled at the start of every print in Cura and Slicer.

That's all there is to it. I Hope this was helpful. Let me know in the comments if you have any questions or notice something missing.

favorite, comment, vote and enjoy!

Marshall P.
Protobuilds.com

16 People Made This Project!

Recommendations

  • Optics Contest

    Optics Contest
  • Electronics Tips & Tricks Challenge

    Electronics Tips & Tricks Challenge
  • Audio Contest 2018

    Audio Contest 2018

119 Discussions

0
None
mickeypop

3 years ago

I made the change and used the LJ12A3-4-Z/BX 4mm sensor but ran into an issue.

I have an aluminum bed and the sensing distance was only 1.24mm, due to low inductive nature of aluminum.

This a caused minor obstruction.

As a workaround I replaced it with the LJ18A3-8-Z/BX 8mm (on eBay) model this gave me almost 5mm clearance and all is working now

I should note the replaced unit is NPN output so the "Z_MIN_ENDSTOP_INVERTING" should be left TRUE

10 replies
0
None
NaderH8mickeypop

Reply 2 months ago

Hi Mickeypop,

I have a question about a LJC18A3-B-Z/BX inductive sensor I just installed on an ANET A8. I bought the sensor as a complete kit from Amazon and for the most part it is a good kit. It came pre-wired with resistor and instruction on how to connect to the board 12V. I removed the spring back screw of my aluminum (Siliconate Glass Covered) heated board with fixed length.

The actual sensor works. M119 triggers when it should and doesn't when it shouldn't. I have executed a G28 with cold bed. Then heated the bed and extruder, moved the extruder down on the Z axis 10mm and calculated my Z index offset. I saved it to memory with M500. G29 command performs and gives me results. I am doing this with Cura and Pronterface.

The issue is even after I enter the G29 code in Cura (15.04.6). The print is very bad. First layer is complete trash, cannot even finish. it's just like the autolevel is not being observed.

I should add that I only added 'G29' to my start.gcode, nothing else.

listed below is my start.gcode:

;Sliced at: {day} {date} {time}

;Basic settings: Layer height: {layer_height} Walls: {wall_thickness} Fill: {fill_density}

;Print time: {print_time}

;Filament used: {filament_amount}m {filament_weight}g

;Filament cost: {filament_cost}

;M190 S{print_bed_temperature} ;Uncomment to add your own bed temperature line

;M109 S{print_temperature} ;Uncomment to add your own temperature line

G21 ;metric values

G90 ;absolute positioning

M82 ;set extruder to absolute mode

M107 ;start with the fan off

G28 X0 Y0 ;move X/Y to min endstops

G28 Z0 ;move Z to min endstops

G29

G1 Z15.0 F{travel_speed} ;move the platform down 15mm

G92 E0 ;zero the extruded length

G1 F200 E3 ;extrude 3mm of feed stock

G92 E0 ;zero the extruded length again

G1 F{travel_speed}

;Put printing message on LCD screen

M117 Printing...

I have the G29 result I can put up also. any ideas?

0
None
mickeypopNaderH8

Reply 2 months ago

in general it looks like it is running but 2 things I see here. The sensor type and the print head to bed height.

1) How you calibrate the height of the sensor relative to the bed is critical. If the proper height from the Print Head to the Bed is say .28mm(typical Business card thickness) the mounting of the sensor must be such that when the sensor is at its trigger point the head is also at .28 above the bed.

simply loosen the sensor mount and raise it some till not sensing.

Adjust the bed like you did in the past with the appropriate paper thickness.

Now with a volt meter, scope or what ever, slowly adjust the sensor down till the trigger output changes voltage. then lock the sensor mount there.

Here's the problem though, your sensor is capacitive so your body becomes part of the calibration so repeated set and test may be needed here. Fortunately you can micro step the height.

2) I looked up the sensor and it is capacitive not inductive.

That may not be an issue when rules are followed. Remember, like an old radio changes tuning when you get close to an antenna the accuracy can also change with capacitive sensors, so generally stay a distance from the sensor while printing.

0
None
NaderH8mickeypop

Reply 2 months ago

Thank you sir for the quick reply.

In response to item #1, The distance of print head to the bed is the size of the thickness of a sheet of standard paper (A4). The sensor head is at 2.5mm height (they supplied a plastic washer for sizing). The sensor has a screw that you use to adjust the sensitivity to fire at the A4 level. But as you mentioned because of the sensor type, the sensitivity changes as I go to do minor adjustments to the screw. It's very much small moves back and forth movement and lots of testing.

However, it does seem to be working as far as recognizing the bed. G29 command does return values in a matrix that I can post. The issue is It doesn't seem to compensate for the difference in the bed height when I go to print. I have added G29 to my start.code but nothing else. Do I need to have another gcode instruction for it to engage auto leveling? I was under impression that is what G29 does that.

And overall, I am wondering if I got to the wrong sensor. Would you recommend another type over this? I am not very happy with this sensor because the fact that it seems like I have to use Pronterface (USB) and not OctoPrint (RasPi wireless networked) which I prefer.

I am about to remove the sensor and go back to hand leveling to make isolate the issue. I want to confirm it can't be anything else (such as a clogged nozzle - which I have already cleaned and I also want to make sure my extruder motor isn't having a problem).

I will report back so the info is preserved in this thread, but I would appreciate any advice you have on upgrading to a good auto level sensor. I am looking to build a very good quality 3D printer to learn more about building custom 3D machines.

0
None
mickeypopNaderH8

Reply 2 months ago

-- sounds like the print head is not lowering all the way after G29 probe. This can happen sometimes. --

NOTE; You should normally only need to Auto level once when you power up or if you think you bumped things enough to through it off. You don't need it with every print.

=== borrowed ======

FROM the PAGE (about half way down)

Auto-leveling is a command that is run after the " G28 ; home all axis " gcode line in your start code or run once in a separate file each time you boot up your 3D printer. At this point, you may need to adjust your firmware a few times to get the probing locations set correctly.

The auto-leveling command is: G29

You may need to add a G92 line to tell your printer to lower the nozzle after probing. In this example, my nozzle is .9mm above the print bed after leveling.

I run code like this for auto-leveling. You can make a separate text file and put this on your SD card or run it at the start of every print.

G28 ; home all axis
G29 ; Auto Level
G92 Z.9 ; Lower = Z Pos, Lift = Z Neg

if the nozzle is too high when printing, raise the Znumber. If it's too close, lower it.

=== end borrowed ====

From your control software you might run a simple test

G28 ; home

G29 ; auto level

M0 ; pause, will wait for a mouse click or possibly M226 also a different kind of pause

This will home, auto level and pause. Once stopped, see if the head is down all the way. If you know the difference you can calculate how much the G92 Z value needs to be.

I'm not sure but if you run the G28 after the G29 the HOME should be to the auto leveled height.

G28 ; Remember always HOME first

G29 ; auto level

G28 ; re home to auto leveled value?

0
None
Raidramonmickeypop

Reply 1 year ago

Hi Mickeypop

not sure if your still checking the thread ?

with the 8mm model you got do you still need the two resistors ?

0
None
mickeypopRaidramon

Reply 1 year ago

yes
without dividing down the voltage you will fry the micro pin on the Z input.

Atmel allows only .3 volt (point 3 v) over the 5 volt max. the sensor is designed with a 6-30 volt supply.

12 volt out from the sensor would destroy the arduino if no level shifting were done.

thought some have said their sensor operates at 5 volt all of my testing has shown inconsistent measure at 5 volts and since there is no 6 volt on the printers the 12 volt is usually there to use.

0
None
HansV42mickeypop

Reply 2 years ago

Sorry to post a question in this old thread.

I got a LJ12A3-4-Z/BX. It is NPN and NO. When open the signal should be floating, when closed it is shorted to GND.

I do measure 12V when open, is this some floating phenomenon? Is a voltage divider needed?

0
None
mickeypopHansV42

Reply 2 years ago

i looked up your part

you still need the 2 resistor voltage divider.or you will burn the microprocessor

this is not floating, there is a n internal pullup resistor.
you are seeing the pullup voltage when open.
if you want a better idea of why lookup Thevenin Theorem it best explains it

0
None
HansV42mickeypop

Reply 2 years ago

Thanks for your reply.

I see what happens: there is a pullup to 12V and when open this is the voltage I get. So I need to use a voltage divider (this is not like an open mechanical switch). I suppose I better disable the internal pullup when connecting the sensor, there is a setting for this in Configuration.h.

I wired everything save for the sensor signal. That will have to wait till I receive some resistors I ordered.

After 35 years I'm getting the hang of electronics again :-)

0
None
marshallpeckmickeypop

Reply 3 years ago

I had similar sensing distance issues too. Glad to hear the 8mm ones work. Excellent note about enstop inverting. I'll update the 'ible. Thanks!

0
None
cube-convict

Question 8 months ago

So this senses that it is out of level and compensates by moving the z stepper. Is there such a thing as something that controls motors or something to actually physically level the bed?

0
None
NicholasM130

Question 8 months ago

Where did you get the pins to connect to the ramps board?

0
None
Stulander

1 year ago

Is this doable with a delta? Are the steps more or less the same?

0
None
k-labit

1 year ago

Thank you for this tutorial! I just ordered a proximity sensor and will be installing it.

0
None
mattpev

1 year ago

Hi, i have been through the above and when i home all my z axis just keeps going up. What have i done wrong? Thanks

0
None
abqam

1 year ago

What I mean is that you can use 5V as the input voltage instead of 12V. I guess 5V is close enough to the 6V minimum.

0
None
abqam

1 year ago

The probe will actually work at 5V so no need to add the resistors!

0
None
gismo1

1 year ago

I have a sensor with an orange tip but its a NPN type and the led is always on until the sensor is in the proximity of a metal object. it is an LJ12A3-4-Z/AX It appears to work with a 5v supply so i do not see any reason to not just connect it directly to the board. but should i invert the signal to turn the led off until its activated.

0
None
DanielS960

1 year ago

There is an inherent flaw with the instructions related to the voltage divider across the web.

You only need to add a resistor between ground and the digital output pin, not a full voltage divider circuit. Why? There is already a resistance in the power circuit of the sensor. You need to measure your particular sensors resistance between + and - inputs and then calculate the resistance you need, but it sure makes for a cleaner install.

For my specific inductive sensor I use a 12VDC input to the sensor from the +12VDC control board input and then I drop in a 3.3KOhm resistor between digital out and ground of the sensor. The digital signal wire is the only wire that is connected to the sensor row of pins (ground is already attached to the power input and you don't want to create a ground loop)

NOTE: Again the web is generally incorrect here. Do NOT connect your sensor output to the black input pin of the sensor input on your control board unless you confirm on the PCB schematic that it is indeed the digital input pin. Generally the black is the common ground and red is common +5V for the control boards. The alternate color (not black or red) is generally the digital input. I don't know how this is consistently wrong on websites, but I hope to prevent others from struggle with their installation.

My resulting digital Output is 5.2VDC.

One other thing, I find I don't need to keep active the auto bed level compensation with this sensor. Why? Well if you think about the accuracy and consistency of the inductive sensor relative to the large mechanical switch hysteresis, you home to the exact height every time. So if you don't mess with your bed leveling screws, you should maintain a perfectly level bed.