Using the Probe Function to Zero your Axes

G-code has a built in function to use a metallic probe contact to zero out the Z axis on the top of your workpiece.  This function can also be used to zero out the X and Y axes as well, if you have the correct device.  The probe cycle is initiated by a specific g-code sequence.  The probe itself must be properly connected to the correct input on your GRBL motion controller.

This function requires a special input on your motion controller to sense when the probe cycle is complete.  A small metallic sensor (puck) is placed on the top of the workpiece, and an alligator clip is connected to the bit on the router.  These are connected by a pair of wires to the Probe input on the GRBL controller.  When these two make contact, it sends a signal back to the controller, which causes the cycle to stop.  Since the height of the puck is known, the Z axis height can now be set to this value.  This means that the:

current height – height of the puck = zero,

thus the Z axis is now at a known height off the workpiece, and Z=0 will have the bit touching the work.

The G-code function is G38, and it has several sub functions:

Probing Command Reference

Gcode Parameters Command Description
G38.2 axes Fnnn probe toward workpiece stop on contact (switch closed), alarm if probe does not trip
G38.3 axes Fnnn probe toward workpiece stop on contact (switch closed)
G38.4 axes Fnnn probe away from workpiece stop on loss of contact (switch open), alarm if probe does not trip
G38.5 axes Fnnn probe away from workpiece stop on loss of contact (switch open)


The function we are most concerned about is the first one, G38.2.  This command is structured as follows:

G38.2                 Z-10                                                            Fxxx

Command          Axis to be zeroed, Alarm limit (mm)        Feed speed during probe cycle

Note that the value for Z must be negative, this lets the function know to move the Z axis downwards.  This command will move the Z axis down up to 10mm, at a speed set by Fxxx.  If the probe does not make contact with the puck before it has moved 10mm, the system will stop with an error and need to be reset.  The speed used for the G38 command must be very low.  I usually recommend around 50mm/min, this is slow enough that you can see it move, but fast enough so the cycle doesn’t take all day.  The 10mm variable can be set to any amount you want.   You just need to make sure that the bit is within this distance from the puck before starting the Probe cycle.  Of course if you are using inch measurements on your machine, these values would be in inches.

Example Macro using GRBL Panel

GRBL Panel, a commonly used g-code sender program, has the ability for the user to enter in a Macro, which is like a small g-code program.  A lot of other g-code sender programs have this function as well.

To program a Macro in GRBL Panel, click on the Macros tab at the top, this will bring you to the following screen:

Go to the Editor window, and type “Probe” in the name field.  Now click inside the G-Code window, and type “G38.2 Z-10 F50” (without the quotes) and press enter.  Now type “G92 Z 19.5”  –  The G92 command sets the Z axis position to 19.5, which happens to be the thickness of my puck.  Yours may be different.  Measure the thickness of your puck to at least .1mm, and substitute this value after the Z in the second line.  Press Enter, and you will start a new line.  This may be enough, but your bit is actually still sitting on top of the puck.  This will make it difficult to remove the puck.  I usually add a third line as follows:  G0 Z+25.  This will cause the machine to raise the Z axis to an absolute height of 25mm above your work.  Since the puck was 19.5mm high, this puts the bit at 5.5mm above the puck, which can now be removed easily.

Note that this is not actually doing anything yet, we are just entering in the command sequence.  Once all 3 lines have been entered, click the Add button, and then click OK.  The name “Probe” should now appear in the Macro list above the editor window.  Don’t forget to click OK or the macro will not be saved.

Once you click OK, then click the Interface tab to go back to the main screen.  Now, if you look underneath the Manual Command entry bar at the top right above the Jog buttons, you will see a small button labelled “Probe”.  This button is what you click to start the probe cycle.


We will need to do a test to make sure everything is working.  If the Probe is not correctly connected to the GRBL controller, it is possible to damage your bit or machine by crashing the bit into the puck.  Take the puck in one hand, and use the mouse to click on the Probe button.  The Z axis should start to slowly move downward.  Touch the alligator clip to the surface of the puck, and the Z axis should immediately reverse direction and stop with the Z axis height reading 25.000 (or whatever you set it to).

Now you can do an actual test using the router with a bit installed.  Place the puck underneath the bit, and connect the clip to the bit itself.  Make sure you have enough room to raise the router the full 25mm without running into the top limit of the Z axis, and also make sure the tip of the bit is less than 10mm above the puck (or whatever setting you used)  Now, click the Probe button.  The program should do the same as the test above, slowly lowering the Z axis until the bit just contacts the surface of the puck, and then raising to a reading of 25mm.

If you get a red Error and red Unlock button on the screen before the bit gets to the puck, this means you had the bit more than 10mm above the puck when you started the cycle.  Click Unlock, and try it again, starting with the bit within 10mm of the top of the puck.

Note that you must have the puck sitting on TOP of your workpiece for this to work properly.  Do NOT set the puck on the bed.   Even though this program ends with the Z position at 25.000mm, the Z axis has accurately had its zero position set.  If you slowly bring the Z axis down to 0.000, you will see that the bit is just touching the surface of your work.  The final position of the bit, although it is not physically set to zero, has the zero point correctly set at the surface of your work.  You can go ahead and start your program after doing this without moving the Z axis, the g-code will automatically move the bit to the work surface when required, regardless of the starting position of Z.


Other G-code sender  programs may have different ways to set up Macro programs.  Consult your software manual for instructions on entering Macros.  The actual Macro code itself will be the same as above, just the method of entering it, and activating it, may be different.  You can customize the values in the macro to reflect your machine, puck, and speed parameters to suit your requirements.

It is possible to use the Probe function to also set your X and Y axes positions using a similar method, and a special puck with 3 faces that the bit can touch off from.  This is an advanced topic, if I get any feedback requesting this I can add the procedure to this Blog post.