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.

<p>Nice! <br><br>Did you have to wire up a voltage divider to get the sensor to work?</p>
<p>absolutely </p><p>the sensor output is 12v and would toast the micro if not dropped. i used a 15K and 10K and got 4.6v out. </p><p>remember to put the 15K on the sensor and 10K to ground. plenty safe for the micro</p>
<p>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.</p>
<p>I've tested a few at 5 volts but the ones i tested were inconsistent on testing. I would do some real testing. </p><p>Allot of electronics can run at reduced supply but often will run erratically when run outside of their designed range. </p><p>If you really do have reliable results at 5 Volts, post the make model for others.</p>
<p>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.</p><p>Thanks again !</p>
<p>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.</p><p>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.</p><p>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.</p>
<p>Thank you - I continue to learn a bit here and there ... working well as you described it.</p>
<p>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.</p><p>Any questions, just ask. If it wasn't for other people asking and helping eachother this would be an impossible hobby. Cheers!</p>
<p>Gentlemen, an uptade:</p><p>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 &quot;slop&quot; 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.</p>
<p>works ok for me as well !</p>
<p>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...</p>
<p>Hi Mickey,</p><p>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)</p><p>Also do you have any suggestions for how to connect the bare leads to the board? </p>
<p>a voltage regulator really is a no go. Most all regulators you would be introducing a delay. </p><p>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. </p><p>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.</p><p>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.</p><p>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.</p><p>hope this helps</p>
You are perfectly right and yours are the best answers. But why do you say that your setup give 4.6V? <br>I think it gives 4.8V. Am I wrong?
<p>The resulting voltage will vary some by the tolerance of the resistors.</p><p>Remember the resistor tolerance is + and -.</p><p>Based on 5% resistors the output range calculates to anywhere between 4.51-5.09 volts to the Z input. </p><p>All of which the micro will see as a HIGH.</p>
Dear Michey,<br>Mounth&rsquo;s ago I realised my 3D printer (i3 prusa) following your posts (proximity sensor included). <br>Everything works like a charm. <br>The only doubt that I couldn&rsquo;t solve was that 4.6V until your post.<br>I knew you were right but I couldn&rsquo;t see why. Now everything is clear again many thanks to you.<br>I will consider &lsquo;tolerances&rsquo; in the future. <br>You were a step forward in the past and still you are a step forward in the present.<br>Thanks again.<br>Roberto <br><br><br>
<p>I thank you for the compliment</p><p>With 54 years in electronics I always hope I can help.</p>
What are you referring to when you say micro?
<p>i was mainly referring to the Z-stop input of the &quot;micro&quot;processor that has a 5V limit on input voltage. </p><p> 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.</p>
<p>I have seen several comments on a voltage divider and the hookup. (schematic below)</p><p>ABSOLUTELY, you do need the divider to protect the micro input pin.</p><p>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.</p><p>Some have noted their Z output from the divider was around 6V and still work.</p><p>The length of the wire and connection resistance may be the only things preventing the micro pin from damage.</p><p>This will likely shorten the life of the arduino. Atmel spec on the micro allow .3 volt higher max than the supply(5v). </p><p>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.</p><p>Any voltage out between 3.3 and 5 volts will be best for the micro to detect it and safe from pin damage.</p><p>-------</p><p>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. </p><p>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.</p><p>Electronics Engineer</p>
<p>I am planning to use a capacitive sensor to eliminate the metal foils.</p>
Yea. I did it with instructions made by Tom, but I used both 10k (1/4Watt) resistor. <br>Measuring the output voltage shows 6V but it works just fine.
<p>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!</p>
<p>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.</p><p>Use the LJ18A3-8-Z/BX. it's inductive and about the same price on eBay.</p><p>As noted in my earlier post here it is NPN out so the &quot;Z_MIN_ENDSTOP_INVERTING&quot; should be left TRUE</p>
<p>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?</p>
<p>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.</p><p>I also get 5.5 vt when metal is away or a floating voltage. I want to get 3.5 VT</p><p>or more. What can I change on the divider to increase the output voltage? Is there a test for the sensor? Thank you.</p>
<p>10K and 15K meaning 10,000 and 15,000 ohms. </p>
<p>Yes the K is the Greek kilo aka 1,000</p>
<p>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.</p>
<p>The probe will actually work at 5V so no need to add the resistors!</p>
<p>I made the change and used the LJ12A3-4-Z/BX 4mm sensor but ran into an issue.<br><br>I have an aluminum bed and the sensing distance was only 1.24mm, due to low inductive nature of aluminum.</p><p>This a caused minor obstruction. </p><p>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<br><br>I should note the replaced unit is NPN output so the &quot;Z_MIN_ENDSTOP_INVERTING&quot; should be left TRUE</p>
<p>Hi Mickeypop</p><p>not sure if your still checking the thread ?</p><p>with the 8mm model you got do you still need the two resistors ?</p>
yes<br> without dividing down the voltage you will fry the micro pin on the Z input.<br> <br> Atmel allows only .3 volt (point 3 v) over the 5 volt max. the sensor is designed with a 6-30 volt supply.<br> <br> 12 volt out from the sensor would destroy the arduino if no level shifting were done.<br> <br> 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.
<p>Sorry to post a question in this old thread.</p><p>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.</p><p>I do measure 12V when open, is this some floating phenomenon? Is a voltage divider needed?</p>
i looked up your part<br><br>you still need the 2 resistor voltage divider.or you will burn the microprocessor<br><br>this is not floating, there is a n internal pullup resistor.<br> you are seeing the pullup voltage when open. <br> if you want a better idea of why lookup Thevenin Theorem it best explains it <br><br>
<p>Thanks for your reply.</p><p>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.</p><p>I wired everything save for the sensor signal. That will have to wait till I receive some resistors I ordered.</p><p>After 35 years I'm getting the hang of electronics again :-)</p>
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!
<p>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.</p>
<p>There is an inherent flaw with the instructions related to the voltage divider across the web.</p><p>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.</p><p>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) </p><p>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.</p><p>My resulting digital Output is 5.2VDC.</p><p>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.</p>
<p>I have a 10k and 22k is that to large of a jump</p>
<p>use a relay to be driven by either a NPN or PNP sensor and you have a choice of NC or no contacts to connect to the Z axis</p>
<p>Will this work with dual z axis steppers? I have mine independent right now so they can adjust the left/right side of my bed respectively. How will Marlin know if z1 or z2 is left/right based on the probe position?</p>
<p>Hello everyone,</p><p>I have MeCreator2, Is that possible to add Auto Leveling? Has anyone done that or can someone help?</p><p>Thanks</p>
<p>If I put this sensor in a non-metallic casing to protect it, will it effect the sensor? Thanks in advance!</p>
<p>Hi,</p><p>I am using glass on my print bed. Is it ok if I use small pieces of copper band on calibraion points?</p>
<p>The problem is with the 4mm version of the sensor because these sensors are most active with a steel/iron bed which, of course, we don't use and Aluminum it sees but not as well. Now couple that with the normal 3mm glass you would have to kiss the glass and it may not even see it then (depends on the glass etc...). Use the 8mm version instead and you will not need small pieces of anything plus you will not have to kiss the glass like a 4mm almost has to do (the sensor can snag your print at the worst time so I always tell people to go directly to the 8mm version).</p>
<p>I could not find the 8 mm probe in my country so I bought a 4 mm one. I planned to buy an aluminium to use instead of glass. But before that, I tried it with piece of aluminium tapes on glasses aaannnd it worked very well :) Probe detected aluminium tape like 3-4 mm. away.</p>
<p>Hey guys,<br>why dont you simple use any simple diode instead of 2 resistors to prevent the 12V from destroying the AVR input?</p><p>(works flawless for me)</p>
<p>Won't compile.</p><p>#error The X axis probing range is too small to fit all the points defined in AUTO_BED_LEVELING_GRID_POINTS</p><p>This<br> is a 200mm delta (geeetech g2s pro) and I'm not sure I can mount the sensor any closer <br>before I get printing working... for which I need bed leveling because <br>my bed is not flat.</p>

About This Instructable




Bio: Make all the things!
More by marshallpeck:Tap 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) UV LED Oven for curing DLP Resin 3D prints 
Add instructable to: