Autolevel for the A8 Anet 3D Printer

With autolevel your printer will scan the surface of your heatbed and adjust the Z-axis offset according to the position. Therefore you will not need to adjust the heatbed any more. You will need the following:

  1. Distance sensor
  2. Connector(JST XHP-3)
  3. Sensor support (normally printed by yourself)
  4. Firmware
  5. Slicer settings

A good combination is highlighted in bold.

The sensor will replace your Z axis switch. There are many sensor types available here an overview selection of some possibilities. The cost is only approximate and for information only. There is information missing, so if you have any knowledge please add it (this is a WIKI!).

A video comparison of the different types can be found here

Sensor name Type glass bedDistancecommentcostlinkvoltageocsig*
ROKO SN04-NNPNno<3 mmthe “official” Anet sensor4-15 USD10-30 V(5 V)no
TRONYX XY-08NNPNno8 mmWith Support12 USD6-38 V(5 V)no
HallONHall effectyesOn any surfaceWith Connector for Anet10-16 EuroPnP and DIY kits5 Vno
LJ18A3-8-Z/BX NPN inductive no8 mm with connector3 USD 6-36 V(5 V)no3.2 µm
LJ18A3-8-Z/BX-5V NPN inductive no8 mm 6 USD 5 Vno3.0 µm
LJC18A3-H-Z/BX NPN capacitiveyes1-10 mm5 USD6-36 V0.6 µm @ 25 °C, 9 µm @ 60 °C
LJ12A3-4-Z/BXNPN Inductiveno4 mm 2 USD6-36 V
LJ12A3-4-Z/BX-5VNPN Inductiveno4 mm 3 USD 5 V

If (5 V) is mentioned on the sensor, it has been tested that it works on the 5 V provided by the Z-switch connector, but officially it need a higher voltage therefore it might not work reliably. See “wiring chapter” to connect it to the 12 V power supply.

*)The standard deviation obtained according to the testing_repeatability_of_the_probe chapter

  • inductive sensors are using magnetic fields for the detection. They can only detect metal. It can detect the metal under the glass, if the range of the sensor is high enough. But if the metal is deformed beneath the glass the printer will try to compensate a non-existing deformation. Also while using Inductive sensors, the detection range needs to be adjusted according to the metal which the sensor senses. They are designed for sensing Iron based metals. So for other metals, the sensing distance needs to be derated. A rough multiplier for sensing distances for various metals are given in brackets - Steel (1.0), Stainless Steel (0.6 - 1.0), Aluminum (0.30 - 0.45), Brass (0.35 - 0.50), Copper (0.25 - 0.45). For eg: if an 8 mm Inductive sensor is used to sense Aluminum, the sensing distance is actually between 2.4 mm and 3.6 mm. So it would be best to test the sensing distance with the sensor you purchased before installation, especially while using 4 mm sensors along with a glass build plate.
  • capacitive sensors are using electrical fields for the detection. They can detect many materials including glass. They have a little screw to adjust the field to fit your needs and your material. The drawback of capacitive sensing is that it is affected by temperature and humidity.

Therefore a general recommendation could be: inductive for metal, capacitive for glass

Read more at:

First of all, why do we need a NPN for the Anet-board? The input on the Anet-board is low-active. That means it is held high at 5 V with an internal pullup-resistor and is actively switched down to 0 V. That is what a NPN-Sensor does.

If you get an open collector sensor you will have an easier wiring. To know if it is a open collector connect the power supply (12 V) to the brown(+) and blue(-) wire. Then take a multimeter and check the voltage between black and blue. If there is none you have an open collector sensor, which can be directly connected to the board.

Most Chinese sensors do not have an open collector output (might be the LED-circuit). They have an internal pull up resistor. This is why the black wire is not only high impedance when the sensor is not switched but has any voltage on it. For those you need to add at least one resistor between the black and the blue wire to reduce the voltage to nearly 5 V. (as mentioned above it is not for switching but securing the board. switching is done with 0 V). Another way it to put a diode in, which should also prevent from damaging the board with voltage-peaks from the sensor while switching.

As you can see this topic is not easy to solve. So “universal” way is to put in an optocoupler which is not only working but protects your board from damaging

Descriptionfor SensorPrinterlink/commentoffset Xoffset Y
Official AnetROKO SN04-NA8expensive, fragile and collides the heat bed harness and connector15 mm55 mm
Official Anet likeROKO SN04-NA8 mm55 mm
ROKO SN04-N/XY-08NA8 mm-43 mm
HallON A8A8 mm42 mm
LJ18A3-8-Z/BXA8 mm-36 mm
18 mm capacitive sensorA8
12 mm inductive sensor

The offset in X,Y, and Z are the values defined in the firmware (In Marlin Configuration.h). The value for X and Y can be quite coarse. Z has to be accurate and has to be adjusted quite accurately. This value you can set also via display (Marlin): Menu→Control→ Motion→Z-Offset. Procedure to get this value:

  1. Set a large Z-offset value (i.e. 2 mm)
  2. Autohome your printer
  3. place a sheet of paper beneath the nozzle (make sure it is clean)
  4. Go into Prepare → Move Axis and disable Soft Endstops
  5. move Z-axis down by steps of 0.1 until it touches the paper.
  6. note the Z value (i.e 0.7 mm) and subtract it from the initial value (2 mm-0.7 mm).
  7. Set the value as Z-offset (1.3 mm)

HallON Only Sensor with ready to use predefined firmware, and full project support.

HallON Youtube channel: Installation and user guide

The Sensor will be replace the Z switch. You will need a “JST XPH-3” 3 pin connector. You might also use the connector of your Z probe if you do not need a 5 V power supply as the middle pin is missing. The position of the pins on the board is described in the picture:

Normally the following color code is used for the sensor Harness:

  • Black - Signal - for NPN it is 0 V=active, high impedance OR supply voltage for inactive
  • Brown - Power supply - See sensor for the Voltage*
  • Blue - Ground - 0 V

As most sensors need a voltage larger than the 5 V provided by the connector there are a few alternative options:

  1. Purchase a pre made board:
  2. For 5 V sensors or for some 6-36 V sensors use the 5 V supply of the connector. Anet and Skynet3D use this option for their sensor and it works for the LJ18A3-8-Z/BX. According to some users the low voltage is acceptable for the “orange” sensors. But the this might lead to unreliable readings as it is not designed for this voltage.
  3. If you have an open collector NPN sensor (see above) than you may connect the brown wire to the the 12 V input of your board and the blue to the ground and finally the black wire to the Z switch (the board should have an internal pull up).
  4. If you have a sensor with an internal pull up resistor(see above) than you may connect the Brown wire to the the 12 V input of your board and the blue to the ground. The following options are available:
    1. Add a resistor between the black(signal) and the blue(ground) wire to reduce the resulting voltage from 12 V to 5 V. The best way is to test it with different resistors and measure the voltage between the signal (black) and ground (blue). Best to start with is 10 kΩ, for me it worked with 5 kΩ. Increase the resistance if the voltage is to low, decrease if it is to high. When you found the correct resistor you can connect the signal pin (black) to the signal pin of the Z-probe plug as shown on the picture.
    2. The disadvantage of using resistors is that it depends on the power supply voltage and a change of this voltage my damage your printer. This can be avoided by using a diode. Assuming a typical NPN normally-open (NO) sensor, connections can be made as in the schematic below (be careful with the polarity of the diode). See Method 3 here and this post for more details.
  5. Some tutorials recommend to use two resistors. But this is only for PNP-sensors and for high-active inputs. In our case this would lead to errors. When the sensor switches to 0V and the Atmega internal pull up is activated there would be about 2.5 V on the signal pin which is not recognized as low by the AVR.
  6. last but not least there is the universal/safe way for your NPN-Sensor. Putting the optocoupler in:

(R2 is optional for Anet-Boards as it has its own Pullup)

Normally the installed printer software does not support autolevel. Therefore you will have to upload a new one via the USB port. There are 2 options:

* Skynet 3D A marlin-based firmware modified for the Anet A8 Skynet3D is obsolete. Use Marlin.

Instructions and information can be found here: Marlin Anet Board Defs for Arduino

You will have to make the following changes in the configuration.h file:

Set the position of the probe according to the probe support table above:

 #define X_PROBE_OFFSET_FROM_EXTRUDER 65  // X offset: -left  +right  [of the nozzle] 
 #define Y_PROBE_OFFSET_FROM_EXTRUDER -36  // Y offset: -front +behind [the nozzle] 


 #define X_PROBE_OFFSET_FROM_EXTRUDER -21  // X offset: -left  +right  [of the nozzle]
 #define Y_PROBE_OFFSET_FROM_EXTRUDER -43  // Y offset: -front +behind [the nozzle]

To define the positions(of the probe) of the points for the autolevel (sometimes needed):


Goes With Alternative:


These points have to reachable with the x,y offset defined for your probe support otherwise you get an error message when compiling and uploading.

Set the auto leveling method that you will be using (in this case Bilinear), just uncomment it:


In the case that the sensor is outside of the plate after homing the Y and X axis, use Z safe homing (applies if you are using a sensor support with a negative Y-offset:

  #define Z_SAFE_HOMING

Enable the Soft Endstops option in the menu by uncommenting:


The slicer needs some specific setup to execute the autolevel before each print and that the autohome works.

There are already some configuration files available at Cura

Auto home

Before homing of the Z axis the probe has to be positioned above the heat bed. When the code G28 is sent to the printer this is done automatically. But if “G28 Z” is sent it is not. This is the case for some Cura 2.1 json files.

Auto level

The G code G29 starts the autolevel procedure. It should be executed after the G28 command

Implementing G-code in CURA 2.1

The G-code executed before a print is defined in the json file (see also Cura) Example:

"default": "G21 ;metric values\nG90 ;absolute positioning\nM82 ;set extruder to absolute mode\nM107 ;start with the fan off\nG28;move X/Y/Z to min endstops\nG29 ;auto level"\n

To test the repeatability of the probe Marlin/Skynet3D has the G-code M48. Which has to be activated in the configuration.h file: #define Z_MIN_PROBE_REPEATABILITY_TEST

For the following G-code “M48 P50 X100 Y100 V4” was used to obtain the values for the table above.

If you have Octoprint installed on your 3D printer use built in operation:

Without Octoprint but you will be limited 7×7 Matrix:

With the “G29 T P10 V4” your printer will scan your heatbed in a 10×10 point matrix.

FreeMat/Matlab tool and instruction to analyze your output can be found here A online tool can be found here (send G-code “G29 T P7 V4” to your printer to get the output)

Only works with at least a 7×7 Matrix! If you use a smaller matrix, use the link below

Another, more interactive online tool can be found here - paste the same output as above. Web page No longer available

Automatic bed levelling is a complex beast. When set up well it can work extremely well, but if it isn't working well for you, there are a few basic things to check.

A very typical problem scenario is where the print is fine on one edge or in the middle, but the nozzle is too near the bed in one corner or on one edge. In this case, the first thing to check is if the probe X and Y offsets are correct.

Another common problem is the nozzle being too high above the bed when printing starts. This is often caused by the Z offset being incorrect.

These problems, and many others, can be solved by working through these simple troubleshooting steps.

ABL can't work miracles. You need to make sure your bed is as level as you can get it by adjusting the corner screws. When you have ABL working well you may like to consider to swap the springs and screws for fixed stands. (Like these, for example

There's no magic number for how flat your bed needs to be, but you probably want any variations to be no more than 1 mm across the entire bed. You can check it manually by laying a straight edge (such as a steel rule) across it, or using your probe by increasing the number of probed points using the instructions under 'Measuring your bed flatness'.

The two main levelling methods in Marlin are linear and bilinear. Linear creates a single tilted plane, and is best suited to a perfectly flat surface which is tilted lower or higher on one side or corner. Bilinear is best suited to an uneven bed with dips and rises, and is the Marlin-recommended method.

It is unlikely that your bed is perfectly flat, so bilinear is usually a good option, especially if linear does not give good results.

One of the first things you should do after installing your Z-probe is check how well it works using the M48 command to test it.

In order to run M48 you need to uncomment this line in configuration.h:


Use commands like this to run 10 probes and get the measurements:

M48 P10 X100 Y100

The output will look similar to this:

M48 Z-Probe Repeatability Test
Mean: 3.450000 Min: 3.442 Max: 3.452 Range: 0.010
Standard Deviation: 0.004330

This shows the absolute maximum and minimum measurements the sensor took, the mean (average) of all the measurements, the range between the maximum and minimum, and the standard deviation.

The standard deviation is interesting because it tells us that 68 % of all the measurements were within 0.00433 mm (one standard deviation) of either side of the mean, and 95 % of the measurements were within 0.00866 mm (two standard deviations) of the mean.

A good probe should consistently give a range in the hundredths of mm, e.g. 0.05 mm. A very good probe will have a range in the thousandths.

More information about standard deviation:

If you get a very large range or standard deviation you should look for sources of movement in your Z-axis. The motor couplers can contribute to excess play and you can consider upgrading them to better ones. Failing that, consider getting a new probe.

Probe area

You should do the M48 probe test in multiple places across your build area to ensure your probe is consistent everywhere. If you're using a capacitive sensor, make sure you check at the extremes of your probing grid to make sure you're not suffering from any wrap-around near the bed edges.

These lines in configuration.h define the probing grid boundaries:


Some tips for probe accuracy

  • The 'spring' type Z-motor couplers allow vertical play, which can affect the Z-probe results. You can replace them with 'Plum' style couplers (like these) which have no vertical movement.
  • Capacitive probe measurements will vary near the edge - ensure that your probe boundaries are far enough from the edge to avoid this.

If your bed is curved or particularly warped you can increase the number of points the probe measures in order to create a more detailed correction matrix (at the expense of time - more probes means G29 takes longer).

Try a 5×5 or 7×7 grid by changing this line:


For ABL to work correctly it is essential that the printer knows the exact offset from the nozzle to the probe, otherwise any correction is not going to be applied in the right place, and it may look like the printer isn't correcting at all.

If you downloaded SkyNet3D (now obsolete) or Marlin Firmware and used one of the example configurations, it probably came with some pre-configured probe offsets and a recommended sensor mount for you to print. It is absolutely vital that you check the sensor offsets once your probe is installed, and update the values in configuration.h accordingly.

These are the relevant lines:

 #define X_PROBE_OFFSET_FROM_EXTRUDER 65  // X offset: -left  +right  [of the nozzle] 
 #define Y_PROBE_OFFSET_FROM_EXTRUDER -36  // Y offset: -front +behind [the nozzle] 

Typically, sensors are most sensitive in the center, so we need to know the offset from the tip of the nozzle to the center of the probe. Here is an approach you can use to measure it:

Measuring X and Y offsets

  1. Measure the bed and make a mark in the center (X110 Y110)
  2. Home the printer then move to X110 Y110 Z0
  3. If the nozzle is not on the mark you will need to make small movements to get it on the mark
  4. With the nozzle on the mark in the center of the bed, measure the X and Y distance from the edge of the bed to the side of the probe
  5. Measure the diameter of the probe
  6. The probe offset values are 110 - [the distance from the bed edge to the probe] + [probe diameter / 2]

The offset parameters are integers, so round your results to whole numbers before updating configuration.h

Getting the Z-offset right is critical to get your first layer. Use this process to find and set it:

With a firmware based on Marlin 1.1.x the procedure is a bit different as the behaviour of G92 in pre 1.1.x versions was buggy:

  1. Heat your printer up to your printing temperature and allow a few minutes for it to expand and settle
  2. Reset the existing Z-offset to zero
    M851 Z0
  3. Home all axes
  4. Move the nozzle to the middle of the bed
    G1 X110 Y110

    (if your bed is 220 x 220)

  5. Turn off the software endstops with
    M211 S0
  6. Move the nozzle down so it is just gripping a piece of standard printer paper
  7. Set the Z-offset to the displayed value. E.g. if the printer displays a Z-Value of -1.23 enter
    M851 Z-1.23
  8. Store it to the EEPROM
  9. Important notice! Enable the endstops again with
    M211 S1

    or the printer head will collide with the bed on the next



Pre Marlin 1.1.x

  1. Heat your printer up to your printing temperature and allow a few minutes for it to expand and settle
  2. Reset the existing Z-offset to zero
    M851 Z0
  3. Home all axes
  4. Move the nozzle to the middle
    G1 X110 Y110
  5. Move the nozzle down so it is just gripping a piece of standard printer paper
  6. Mark this position as Z zero
    G92 Z0
  7. Use the sensor to probe the middle of the bed (where we just set Z0)
    G30 X110 Y110
  8. Take the Z value of the bed and put a minus sign in front; this is the Z-offset. E.g. 1.23 becomes -1.23
  9. Set the Z-offset
    M851 Z-1.23
  10. Store it to the EEPROM

Before setting your Z-offset you need to make sure your printer is up to temperature and you've given it a few minutes for any thermal expansion to occur. Differences in nozzle height of around 0.2 mm have been observed between a hot and a cold nozzle. If you set your Z-offset with the nozzle cold, you will most likely find it is too close to the bed when it is hot.

You should also ensure that the printer has had sufficient time at temperature before starting a print. Ideally give the printer 3-5 minutes after it reaches printing temperatures before you start to print.

Several experts have edited and corrected this page. This is just an recommendation without any warranty. If you are an expert and knows something better or just has found an error, please feel free to edit this wiki and add your knowledge.

  • reprap/anet/a8/improvement/autobedleveling.txt
  • Last modified: 2023/11/02 00:35
  • by fdll