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

Picture of 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 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

Picture of ​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,

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

Picture of (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

Picture of 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.


PiotrG4 made it! (author)2015-08-10


marshallpeck (author)PiotrG42015-08-10


Did you have to wire up a voltage divider to get the sensor to work?

mickeypop (author)marshallpeck2015-10-31


the sensor output is 12v and would toast the micro if not dropped. i used a 15K and 10K and got 4.6v out.

remember to put the 15K on the sensor and 10K to ground. plenty safe for the micro

mickeypop made it! (author)mickeypop2015-10-31

I have seen several comments on a voltage divider and the hookup. (schematic below)

ABSOLUTELY, you do need the divider to protect the micro input pin.

Though 15K and 10K are most often noted, any pair where one is 1.5 times higher and both range between say 7K and 25K should work.

Some have noted their Z output from the divider was around 6V and still work.

The length of the wire and connection resistance may be the only things preventing the micro pin from damage.

This will likely shorten the life of the arduino. Atmel spec on the micro allow .3 volt higher max than the supply(5v).

If the output is around 6V a diode in series will steal .7 volt and greatly extend the arduino life. Alternatively, a 1.2K to 2K instead of the diode should also work.

Any voltage out between 3.3 and 5 volts will be best for the micro to detect it and safe from pin damage.


Separately, several have mentioned capacitive sensors. I strongly suggest you stay away from them and only use inductive or the micro switch idea some have used.

Like standing close to a radio and the reception changes. The sensing distance is not constant if you are move around the printer the sensing distance will change too.

Electronics Engineer

bart.wybouw (author)mickeypop2017-09-29

Hi Mickey, why the range 7K to 25K?

mickeypop (author)bart.wybouw2017-10-01


the internal pullup resistor on the Arduino is 100K.

If the resistor pair is too high the micro may have trouble differentiating HIGH from LOW.

If the resistor pair are too low values, you pull a lot more current but the output to the micro would be out of range.

using my sensor as an example

inside of the sensor there is a 1K pullup connected from the 12V on the output circuit connected to the collector of the NPN and the emitter is the output pin of the sensor.

now say we connect a voltage divider of a 100 ohm to ground and a 150 ohm to the sensor and connected to the other side of the 100 and the connection between the two resistors is my micro pin connection.

the voltage at the sensor point the the micro would be only .96 volts when high and the micro would read it as low.

1000 + 150 + 100 = 1250 ohm

12V / 1250 = .9.6mA SENSOR in the HIGH output state

V across100 ohm = 9.6mA x 100 ohm = .96V

NEEDS to be around 3.3V to 5V to be a HIGH to the micro

if instead the divider was 10K and 15K the micro will see approx 4.6 V when HIGH and 0 when LOW

the 7K to 25K sets a range that will always be readable and not load the circuit while keeping the HIGH output voltage reading as A HIGH

bart.wybouw (author)mickeypop2017-10-17

Thanks Mickey!

PetreA1 (author)mickeypop2017-08-30

i see you have a lot of experience, can you please tell if i can do it using the "Photoelectric Sensor Switch E3F-DS10C4 10-30V 3 Wire Difuse Type NPN NO" and a "LM7805 7805 Voltage Regulator +5V 1.5A"?

i can see the senzor has some better specs and i think using a LM7805 will also work great

mickeypop (author)PetreA12017-08-31

the E3F-DS10C4 might work, but know the issues.

these photo type range sensors work by emitting a light pulse and timing the reflected return. different colors and surface textures often will produce different readings because they also look for the realitive brightness of the return reflection. White vs. Black surface will change the reading per the spec sheet

If the bed has uniform color it will likely work. However you need to know if you change the color say you use blue painter tape and the next time glue stick or Kapton tape the color will change and likely need calibration because the range may read differently.

since a lot of printer beds are the RED with white text heaters covered with glass you probably want to set the locations where the readings take place to follow a constant color.

PetreA1 (author)mickeypop2017-08-31

Thank you, i will then use the "classic" inductive one.

BodrubiginH (author)mickeypop2017-01-04

By using a NPN sensor the active signal is 0v and there is no need for a voltage divider. Getting the sensors that are rated for 6-36v also seem to work fine on 5v.

mickeypop (author)BodrubiginH2017-01-04

I've tested a few at 5 volts but the ones i tested were inconsistent on testing. I would do some real testing.

Allot of electronics can run at reduced supply but often will run erratically when run outside of their designed range.

If you really do have reliable results at 5 Volts, post the make model for others.

RickyK11 (author)mickeypop2017-01-30

Mickey - thank you so much for the great posts. I learned how to wire up the sensor, and a little bit about electronics along the way, it's much appreciated ! I have one question though - in your diagram that says to wire to ground, is it the same thing if you wire it to the ground on the power supply or the ground on the ramps 1.4 pin (beside where the sensor signal pin is)? I've tried it both ways, and it works the same - but not sure if ground is just ground, or there is a difference because the 12V comes from the power supply that it should also be grounded there too.

Thanks again !

mickeypop (author)RickyK112017-01-31

Electrically they are the same ground, however anything you attach to the Ramps ground also would require the current to pass thru the ramps ground path.

If you tie the ground and power pins to the supply and send the 5 volt adjusted digital back to the Z-input you don't load the current to the circuit board paths.

Since the steppers are using a large current and the heaters even more, off loading the current is probably a good idea, even though the sensors are fairly low current devices.

ProffesorD (author)mickeypop2017-02-10

Gentlemen, I am using the 6.36V (blue tipped). My results are consistent, and duplicable to within .05mm. I am however, not running my wiring the same as most. I remember seeing a comment on some youtube video I was watching while researching how to accomplish the autolevel upgrade(I really wish I could find the video or the comment, I would love to give credit where it is due, because this is NOT my origonal idea.) The commenter brought up the idea of using the 12v supply to the board (my board is ANET v1.0) then running the ground to the ground of the z-axis sensor, and the signal through a diode and into the other side of the Z-axis sensor. The Diode is 1N4001, the sensor is LJ18a3-8-Z /BX-G. This allows 5V (4.42V actual) of the 12V to pass under switch open condition, but when the switch is closed, it will draw it low (0.24V). The only side effect of this system is that the LED on the switch itself is always on, but does get brighter when the switch is active.

Any questions, just ask. If it wasn't for other people asking and helping eachother this would be an impossible hobby. Cheers!

BorjaA4 (author)ProffesorD2017-07-19

Hi, does anybody know if Marlin reads the sensor during probe moves? (during the times that it is NOT lowering the tip towards the bed). I am testing an alternative sensor but it might activate some times during travel. Could this be a problem?

If someone is going to print, I would appreciate a lot if you could test it in a moment.

Thanks in advance

mickeypop (author)BorjaA42017-07-20

The Marlin code only reads the leveling sensor during calibration, not while printing.

BorjaA4 (author)mickeypop2017-07-20

Thank you for your answer. However I do not mean while printing. I mean during the calibration process itself. You start automatic calibration, it probes one point, does anything happen if the sensor activates while moving to the next point? (before it starts lowering the tip at the next point)

mickeypop (author)BorjaA42017-07-21



In calibration; it moves to a test point position lowers till it sees the Z input change state then just rises, moves to the next point and repeats.

There are no readings taken while moving between points because the sensor it too high to change state and the code only looks at the preset test points not in between.

There shouldn't be anything on the bed while calibrating anyway so it should not be an issue.

BorjaA4 (author)mickeypop2017-07-24

Thank you. I had to tweak a bit the Marlin firmware and I got my custom probe working. I will get back to you when it's fine dialed!

ProffesorD (author)ProffesorD2017-02-10

Gentlemen, an uptade:

After I actually typed out the 0.05mm tolerance, it got me thinking. So I've spent the last 3 hours adjusting and tightening the "slop" in my machine, to see what kind of improvements can be made to this tolerance. Well, after 3 hours of tedious adjustment the repeatability deviation is now .002! I assume this is acceptable... Pic for proof.

RickyK11 (author)mickeypop2017-02-14

Thank you - I continue to learn a bit here and there ... working well as you described it.

David LG (author)BodrubiginH2017-02-09

works ok for me as well !

WV_Kokamo_Joe (author)mickeypop2017-01-21

Exactly! Choke the voltage back but more on the entrance side, it is gonna take what it needs but the 10k is gonna still allow flow...

JonC49 (author)mickeypop2015-12-22

Hi Mickey,

Would a voltage regulator work just as well? I note a lot of resistors are only rated for .5 or .25 W and at 6V the sensor would throughput up to 1.8 W (8mm sensor)

Also do you have any suggestions for how to connect the bare leads to the board?

mickeypop (author)JonC492015-12-23

a voltage regulator really is a no go. Most all regulators you would be introducing a delay.

you could cheat and use some resistor on the sensor output(say 4-6K) and a Zener Diode but that would add a capacitive issue from the diode and the state change would have some delay added also.

A pure resistor approach is still best. Accuracy is not an issue, just remember anything between 3 and 5 volts will be seen as a HIGH by the micro. My setup gave 4.6V out and works fine. Just keep the Z input under 5 volts to protect the input pin of the micro.

as to the wiring, you only have 3 connections; ground, 12 to the sensor supply, and the attenuated output(5v max) goes to the Z axis sensor input.

there are too many controller boards to put them all here, that would take a whole article to cover just the top ones out there.

hope this helps

byX1 (author)mickeypop2016-09-15

You are perfectly right and yours are the best answers. But why do you say that your setup give 4.6V?
I think it gives 4.8V. Am I wrong?

mickeypop (author)byX12016-09-16

The resulting voltage will vary some by the tolerance of the resistors.

Remember the resistor tolerance is + and -.

Based on 5% resistors the output range calculates to anywhere between 4.51-5.09 volts to the Z input.

All of which the micro will see as a HIGH.

byX1 (author)mickeypop2016-09-17

Dear Michey,
Mounth’s ago I realised my 3D printer (i3 prusa) following your posts (proximity sensor included).
Everything works like a charm.
The only doubt that I couldn’t solve was that 4.6V until your post.
I knew you were right but I couldn’t see why. Now everything is clear again many thanks to you.
I will consider ‘tolerances’ in the future.
You were a step forward in the past and still you are a step forward in the present.
Thanks again.

mickeypop (author)byX12016-09-18

I thank you for the compliment

With 54 years in electronics I always hope I can help.

Craig_AR (author)mickeypop2015-11-13

What are you referring to when you say micro?

mickeypop (author)Craig_AR2015-11-14

i was mainly referring to the Z-stop input of the "micro"processor that has a 5V limit on input voltage.

Most 3D printers are based on the Atmel chip set AKA. Arduno and are limited to 5 Volt max. supply. Without a voltage divider or converter the micro would burn out a pin or more.

PiotrG4 (author)marshallpeck2015-08-13

I am planning to use a capacitive sensor to eliminate the metal foils.

PiotrG4 (author)marshallpeck2015-08-11

Yea. I did it with instructions made by Tom, but I used both 10k (1/4Watt) resistor.
Measuring the output voltage shows 6V but it works just fine.

dbarciela (author)PiotrG42015-10-03

What is the model of your sensor? LJC18A3? Can you give us a review about the precision, in Tom's video comments it is said that capacitive sensors are less accurate, is it significant? Thanks!

mickeypop (author)dbarciela2015-10-09

your right about capacitive being inconsistent. Just like getting too close to a radio and changing the tuning you can become part of the reading and trough things off.

Use the LJ18A3-8-Z/BX. it's inductive and about the same price on eBay.

As noted in my earlier post here it is NPN out so the "Z_MIN_ENDSTOP_INVERTING" should be left TRUE

It seems like you know what to do, can you please help me, I got the LJ12A3-4-Z/BX and I am so confused now, since this one is NPN do I need to divide the voltage? and how do I wire this thing?

Hi - I have put a LJ12A3-4-Z/BX sensor (blue tip) and have connected it to 12 VT dc supply with a 15 ohm and 10 ohm resistor per Tom's sketch. My problem is I only get 2.2 VT on the signal lead when the sensor is activated.

I also get 5.5 vt when metal is away or a floating voltage. I want to get 3.5 VT

or more. What can I change on the divider to increase the output voltage? Is there a test for the sensor? Thank you.

etarts (author)RandB32016-07-22

10K and 15K meaning 10,000 and 15,000 ohms.

mickeypop (author)etarts2016-07-23

Yes the K is the Greek kilo aka 1,000

Stulander (author)2017-09-28

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

PetreA1 made it! (author)2017-08-29

anyone any experience with this senzor?

Photoelectric Sensor Switch E3F-DS10C4 10-30V 3 Wire Difuse Type NPN NO

it seems to have better specs:

also order as a backup a normal one:

and a : L7805 LM7805 7805 Voltage Regulator +5V 1.5A

and planning to use the atached schematic as i think is super safe.

My question is will this work with the "E3F-DS10C4"

k-labit (author)2017-07-21

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

mattpev (author)2017-04-30

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

abqam (author)2017-03-05

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.

abqam (author)2017-03-05

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

mickeypop (author)2015-10-09

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

Raidramon (author)mickeypop2017-03-01

Hi Mickeypop

not sure if your still checking the thread ?

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

mickeypop (author)Raidramon2017-03-02

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.

HansV42 (author)mickeypop2016-08-17

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?

About This Instructable




Bio: Make all the things!
More by marshallpeck:Neva 3D Printer Maintenance V1.0Tap straight holes in Aluminum Extrusion with a 3D printed Tap Jig (20mm / Openbuilds V-slot, Misumi, Makerslide / Universal)Enable Auto Leveling for your 3D Printer with an inductive sensor (Marlin Firmware)
Add instructable to: