G Code for Drilling Holes: Syntax, Example, and Tips
To drill holes using G code, use the
G81 drilling cycle command followed by coordinates and drilling parameters. The command moves the tool to the hole location, drills to a specified depth, and retracts automatically.Syntax
The basic syntax for drilling holes with G code uses the G81 drilling cycle command. It includes the following parts:
G81: Starts the drilling cycle.XandY: Coordinates of the hole position.Z: Depth to drill (negative value means down).R: Retract height above the part before drilling.F: Feed rate for drilling.
Example: G81 X10 Y20 Z-5 R1 F100 drills a hole at X=10, Y=20, down 5 units, retracting to 1 unit above the surface.
gcode
G81 X10 Y20 Z-5 R1 F100Example
This example drills three holes at different positions using the G81 drilling cycle. It shows how to set the coordinates, depth, retract height, and feed rate.
gcode
G90 ; Absolute positioning G21 ; Set units to millimeters G81 X10 Y10 Z-5 R2 F150 ; Drill hole 1 G81 X30 Y10 Z-5 R2 F150 ; Drill hole 2 G81 X50 Y10 Z-5 R2 F150 ; Drill hole 3 G80 ; Cancel drilling cycle
Output
Moves to X10 Y10, drills down 5mm, retracts 2mm
Moves to X30 Y10, drills down 5mm, retracts 2mm
Moves to X50 Y10, drills down 5mm, retracts 2mm
Stops drilling cycle
Common Pitfalls
Common mistakes when using G81 drilling cycle include:
- Forgetting to use
G80to cancel the drilling cycle after finishing holes, which can cause unexpected drilling moves. - Not setting the retract height
Rproperly, causing the tool to crash into the part. - Using positive
Zvalues for drilling depth instead of negative, which drills above the surface. - Not setting feed rate
F, leading to default or unsafe speeds.
gcode
G81 X10 Y10 Z5 R2 F150 ; Incorrect: Z should be negative for drilling G81 X10 Y10 Z-5 R2 F150 ; Correct: Z is negative to drill down
Quick Reference
| Command | Description |
|---|---|
| G81 | Start drilling cycle |
| X | X coordinate of hole |
| Y | Y coordinate of hole |
| Z | Depth to drill (negative value) |
| R | Retract height above surface |
| F | Feed rate for drilling |
| G80 | Cancel drilling cycle |
Key Takeaways
Use G81 with X, Y, Z, R, and F parameters to drill holes automatically.
Always use negative Z values to specify drilling depth below the surface.
Cancel the drilling cycle with G80 after completing all holes.
Set a safe retract height (R) to avoid tool crashes.
Specify feed rate (F) to control drilling speed safely.