# How to set Z-probe boundary limits in firmware when using automatic bed leveling?

In setting up a probe for automatic bed leveling, the limits of the probing area must be entered in the firmware of a 3D printer.

When using a sensor, how do you define the bed limits for the sensor in Marlin firmware?

E.g. the Marlin (1.1.x) configuration.h contains the following inactive statements:

  // Set the boundaries for probing (where the probe can reach).
//#define LEFT_PROBE_BED_POSITION MIN_PROBE_EDGE
//#define RIGHT_PROBE_BED_POSITION (X_BED_SIZE - MIN_PROBE_EDGE)
//#define FRONT_PROBE_BED_POSITION MIN_PROBE_EDGE
//#define BACK_PROBE_BED_POSITION (Y_BED_SIZE - MIN_PROBE_EDGE)


How do you set the values for the constants of your custom setup? Is this generic or specific?

Probe positioning is defined in the Marlin configuration as:

 *      +-- BACK ---+
*      |           |
*    L |    (+) P  | R
*    E |           | I
*    F | (-) N (+) | G
*    T |           | H
*      |    (-)    | T
*      |           |
*      O-- FRONT --+
*    (0,0)


The probe could be placed with a positive or negative X and Y value. Considering this position, how to setup the sensor bed limits?

There are a few questions on this topic, so a more generic solution would be informative and will prevent multiple question of others when their sensor has a slightly different location. This answer intends to cover any position with respect to the nozzle. It also does not matter what kind of sensor it is, it can be 3DTouch, BLTouch, inductive, capacitive, etc., as long as you are able to determine the offset to the nozzle (center to center).

For now, it is assumed that the nozzle can only reach the complete area of the bed, no extra space. So unless the sensor runs of the bed, the nozzle limits are used, otherwise the sensor limits the nozzle with respect to the sensor limits. This is the safest assumption and will prevent the carriage running into the end mounts. But if there is more room for travel, an additional offset may be added to the limits.

First, determine the offset of the sensor (e.g. by measurement or taken from the information of the printable sensor bracket found many share sites on the internet; Thingiverse is a good source for such brackets).

## HINT for Marlin 2.x

Note the version (branch) of Marlin! The answer is written at the time of the 1.1.x branch and as such is perfectly valid for the latest 1.1.x (1.1.9) version. For the 2.0.x branch of Marlin, different constant names are in use! Although the constant names are different, the answer is still valid, just substitute the constant names (and look in Configuration_adv.h):

• LEFT_PROBE_BED_POSITION for MIN_PROBE_EDGE_LEFT
• RIGHT_PROBE_BED_POSITION for MIN_PROBE_EDGE_RIGHT
• FRONT_PROBE_BED_POSITION for MIN_PROBE_EDGE_FRONT
• BACK_PROBE_BED_POSITION for MIN_PROBE_EDGE_BACK

## Sensor Offset

The position of the sensor is set using the following constants:

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


where [XXX] and [YYY] are offset values that specify the center of the sensor with respect to the nozzle. If both are positive values, the sensor is located in the back-right, if both negative, the position is front-left (as seen from the front of the machine using the definition in the Marlin configuration file). The other positions that are possible are the back-left and the front-right (one positive and one negative value).

## Marlin 2.x

Note that in Marlin 2.x, these constants are replace by an array definition:

#define NOZZLE_TO_PROBE_OFFSET { XXX, YYY, ZZZ }


Where ZZZ is the Z offset.

Second, let's set the sensor area limits!

## Sensor Area Limits

In the following images, the nozzle, the sensor and the offsets are defined by:

There are four possible positions of the sensor, this results in the following schematics for the sensor area limits (transparent red area):

# 1. Sensor at the back-right:

This implies that the sensor can reach the back and the right borders, so the limits are set by:

#define LEFT_PROBE_BED_POSITION (X_PROBE_OFFSET_FROM_EXTRUDER)
#define RIGHT_PROBE_BED_POSITION (X_BED_SIZE)
#define FRONT_PROBE_BED_POSITION (Y_PROBE_OFFSET_FROM_EXTRUDER)
#define BACK_PROBE_BED_POSITION (Y_BED_SIZE)


Note that if a minimum probe offset is defined by #define MIN_PROBE_EDGE [value] in the configuration (to account for sensor width/dimension), the bed limits are changed resulting in (where t = MIN_PROBE_EDGE):

Limits are then set by:

#define LEFT_PROBE_BED_POSITION (X_PROBE_OFFSET_FROM_EXTRUDER + MIN_PROBE_EDGE)
#define RIGHT_PROBE_BED_POSITION (X_BED_SIZE - MIN_PROBE_EDGE)
#define FRONT_PROBE_BED_POSITION (Y_PROBE_OFFSET_FROM_EXTRUDER + MIN_PROBE_EDGE)
#define BACK_PROBE_BED_POSITION (Y_BED_SIZE - MIN_PROBE_EDGE)


In the following sensor position placements, this offset for MIN_PROBE_EDGE will be accounted for.

# 2. Sensor at the back-left:

This implies that the sensor can reach the back and the left borders (for zero MIN_PROBE_EDGE), so the limits are set by:

#define LEFT_PROBE_BED_POSITION (MIN_PROBE_EDGE)
#define RIGHT_PROBE_BED_POSITION (X_BED_SIZE  + X_PROBE_OFFSET_FROM_EXTRUDER - MIN_PROBE_EDGE)
#define FRONT_PROBE_BED_POSITION (Y_PROBE_OFFSET_FROM_EXTRUDER + MIN_PROBE_EDGE)
#define BACK_PROBE_BED_POSITION (Y_BED_SIZE - MIN_PROBE_EDGE)


# 3. Sensor at the front-left:

This implies that the sensor can reach the front and the left borders (for zero MIN_PROBE_EDGE), so the limits are set by:

#define LEFT_PROBE_BED_POSITION (MIN_PROBE_EDGE)
#define RIGHT_PROBE_BED_POSITION (X_BED_SIZE  + X_PROBE_OFFSET_FROM_EXTRUDER - MIN_PROBE_EDGE)
#define FRONT_PROBE_BED_POSITION (MIN_PROBE_EDGE)
#define BACK_PROBE_BED_POSITION (Y_BED_SIZE + Y_PROBE_OFFSET_FROM_EXTRUDER - MIN_PROBE_EDGE)


# 4. Sensor at the front-right:

This implies that the sensor can reach the front and the right borders (for zero MIN_PROBE_EDGE), so the limits are set by:

#define LEFT_PROBE_BED_POSITION (X_PROBE_OFFSET_FROM_EXTRUDER + MIN_PROBE_EDGE)
#define RIGHT_PROBE_BED_POSITION (X_BED_SIZE  - MIN_PROBE_EDGE)
#define FRONT_PROBE_BED_POSITION (MIN_PROBE_EDGE)
#define BACK_PROBE_BED_POSITION (Y_BED_SIZE + Y_PROBE_OFFSET_FROM_EXTRUDER - MIN_PROBE_EDGE)


This should have tackled the basics for defining the sensor area limits. It becomes a little more complicated when there is extra travel space. A very easy use of extra travel space can be found in the configuration file; e.g:

// Travel limits (mm) after homing, corresponding to endstop positions.
#define X_MIN_POS [XX]
#define Y_MIN_POS [YY]


where [XX] and [YY] are offset values from endstop to origin (orange arrows represent X_MIN_POS and Y_MIN_POS):

Results in offset constants for a back-right probe:

#define LEFT_PROBE_BED_POSITION (X_PROBE_OFFSET_FROM_EXTRUDER + X_MIN_POS + MIN_PROBE_EDGE)
#define RIGHT_PROBE_BED_POSITION (X_BED_SIZE - MIN_PROBE_EDGE)
#define FRONT_PROBE_BED_POSITION (Y_PROBE_OFFSET_FROM_EXTRUDER + Y_MIN_POS + MIN_PROBE_EDGE)
#define BACK_PROBE_BED_POSITION (Y_BED_SIZE - MIN_PROBE_EDGE)


For all other options, a similar addition of the homing offsets can applied.

A similar addition is possible if the print head is able to travel further on the X or Y axis at the other ends of the axes.

• These properties (xxxx_PROBE_BED_POSITION) no longer exist in Marlin 2.0. Have their names changed? – Michael Dec 26 '19 at 22:45
• @Michael Yes they have changed, the sanity check of the code would have told you this if you used the old names. E.g. LEFT_PROBE_BED_POSITION is now called MIN_PROBE_EDGE_LEFT. See e.g. SanityCheck.h. I will update the answer by adding some lines for use of the 2.x branch. Thanks for reminding me to update the answer to the latest version, much appreciated! – 0scar Dec 26 '19 at 23:02
• I was unaware of the existence of SanityCheck.h. That is very helpful. I didn't previously have these in my config but that header file definitely makes it easy to manually find the replacements as well. – Michael Dec 26 '19 at 23:17