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





Introduction: 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.

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.

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.


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

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.

16 People Made This Project!


  • Epilog Challenge 9

    Epilog Challenge 9
  • Paper Contest 2018

    Paper Contest 2018
  • Science of Cooking

    Science of Cooking

We have a be nice policy.
Please be positive and constructive.


2 Questions

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?

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


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

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

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

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.

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

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

Hi Mickeypop

not sure if your still checking the thread ?

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

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.

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?

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