GRBL CNC Macros: Automate Homing, Probing, Tool Change & More
Using a GRBL-based CNC machine doesn’t mean you’re stuck with fully manual control. With the power of macros, you can automate complex workflows — from homing and probing to tool changes and spindle control.
In this guide, you’ll learn how to create, configure, and run powerful GRBL macros in UGS, Candle, and OpenBuilds Control for faster, safer, and more repeatable CNC jobs.
📘 Table of Contents
- What Are GRBL Macros?
- Benefits of Macro Automation
- Supported CNC Interfaces for Macros
- G-Code Commands Every Macro Needs
- Macro 1: Homing & Job Zeroing
- Macro 2: Z-Axis Touch Probe Setup
- Macro 3: Safe Tool Change (Semi-Auto)
- Macro 4: Spindle Warmup & Control
- Macro 5: Emergency Retract + Safety
- Bonus: Auto Job Start Sequence
- Final Tips and Best Practices
1. 🧠 What Are GRBL Macros?
Macros are sets of G-code commands grouped together to perform a complex action with a single button click.
Example Macro Use Cases:
- Homing all axes before a job
- Touch-probing the Z-axis for tool height
- Moving to a tool change position
- Warming up a spindle before cutting
- Returning to a parked location after a job
2. ✅ Benefits of Macro Automation
| Benefit | Description |
|---|---|
| 🕒 Time-saving | Perform multi-step sequences instantly |
| 🎯 Accuracy | Eliminates human error in repetitive actions |
| 🧘 Convenience | Reduce mental overhead and user input |
| 🔁 Repeatability | Ensures consistency between jobs |
✳️ Macros also let you pre-program tool-specific settings and speeds.
3. 🖥️ Supported CNC Interfaces for Macros
| Software | Macro Support | Notes |
|---|---|---|
| Universal Gcode Sender (UGS) | ✅ Yes | Button + startup macros |
| Candle | ✅ Yes | Tool bar macros, startup blocks |
| OpenBuilds Control | ✅ Yes | Custom buttons + job macros |
| bCNC | ✅ Yes | Python scripting support |
All macro examples below work best on UGS Platform and Candle.
4. 🧾 G-Code Commands Every Macro Needs
| Command | Function |
|---|---|
G90 | Absolute positioning |
G91 | Relative positioning |
G38.2 | Probe until contact (used for Z-probe) |
G10 L20 | Set coordinate offset |
M3/M5 | Start/stop spindle |
G0/G1 | Rapid or linear movement |
$H | Homing cycle |
🔐 Always double-check that
G91orG90is set correctly before movement commands.
5. 🔧 Macro 1: Homing & Job Zeroing
; Macro: Home and set job zero
$H
G92 X0 Y0 Z0 ; Set current position as 0,0,0
Use this macro at the beginning of every job to ensure a consistent machine origin.
⚠️ Make sure limit switches are installed and
$22=1is set in GRBL.
6. 📏 Macro 2: Z-Axis Touch Probe Setup
If you have a touch plate connected to Arduino A5, use this macro to automatically zero Z after tool installation.
; Macro: Z-Probe
G91 ; Relative positioning
G38.2 Z-25 F100 ; Probe down slowly
G10 L20 P1 Z1.50 ; Set Z offset based on plate thickness
G90 ; Back to absolute positioning
G0 Z10 ; Lift tool
Replace Z1.50 with your probe plate thickness.
🎯 Use
G38.3for probing without error if touch fails.
7. 🔄 Macro 3: Safe Tool Change (Semi-Auto)
; Macro: Move to safe tool change position
M5 ; Spindle OFF
G0 Z30 ; Lift Z to safe height
G0 X0 Y0 ; Move to front corner
; -- Manual tool change here --
G4 P5 ; Optional 5 sec pause
G0 Z10 ; Return to work
Tip: Place this macro in a button bar or call it manually when M6 is reached in G-code.
8. 🌀 Macro 4: Spindle Warmup & Control
Warm up your spindle (especially in cold workshops) to avoid motor stress:
; Macro: Spindle Warmup
M3 S1000 ; Spindle ON at 1000 RPM
G4 P10 ; Run 10 seconds
M3 S5000 ; Ramp to 5000 RPM
G4 P10 ; Hold
M3 S8000 ; Final working speed
G4 P10 ; Final hold
M5 ; Spindle OFF
🧊 This macro prevents VFD and bearing wear in cold starts.
9. 🛑 Macro 5: Emergency Retract + Safety
When something goes wrong mid-job, use this macro to instantly retract the tool and stop movement:
; Macro: Emergency Retract
M5 ; Spindle OFF
G91 ; Relative mode
G0 Z20 ; Quick lift 20mm
G90 ; Back to absolute
M0 ; Pause job
Use this macro as a physical button, keyboard shortcut, or touchscreen hotkey.
10. 🚀 Bonus: Auto Job Start Sequence
Combine all key steps into one macro to initialize machine before cutting:
; Macro: Job Start Sequence
$H ; Home machine
G92 X0 Y0 Z0 ; Set origin
M3 S8000 ; Spindle ON at 8000 RPM
G0 Z5 ; Raise tool
G0 X10 Y10 ; Move to safe start position
You can insert this macro at the top of your CAM-generated G-code file for automated startup.
🔁 Bonus: Macro for Parking After Job
; Macro: Return to park after job
M5 ; Spindle OFF
G0 Z30 ; Raise tool
G0 X0 Y300 ; Move to parking spot (adjust to your machine)
🅿️ Use this to consistently bring the tool to a safe area for cleaning or manual tasks.
🧰 Macro Management in UGS & Candle
UGS:
- Go to Macros tab
- Create new macro, name it (e.g., “Z Probe”)
- Paste code and assign shortcut key or toolbar button
Candle:
- Click gear icon → “Macros”
- Add custom macros to tool buttons
- You can also set startup G-code blocks
🔐 Safety Considerations for Macros
- Always include
M5(spindle off) before manual steps - Avoid
G91movements without limits - Test all macros in air-cutting or foam mode
- Log macros and back them up
- Avoid using macros that move without visual confirmation on new jobs
💡 Summary Table
| Macro Name | Function |
|---|---|
| Homing + Zeroing | Sets known origin |
| Z-Probe | Automatically zeroes Z after tool change |
| Tool Change | Moves tool to safe access position |
| Spindle Warmup | Pre-heats spindle gradually |
| Emergency Retract | Rapid lift + pause |
| Auto Start Sequence | Full prep before job start |
| Job End Parking | Moves to cleanup/parking area |
🧠 Final Thoughts
Macros are the secret weapon of every efficient CNC hobbyist.
Instead of repeating the same 10 actions before and after every job, let your machine do it — exactly the same, every time.
With just a handful of GRBL macros, you’ll cut down setup time, reduce errors, and get more consistent results.
📎 Coming Up Next:
“Advanced GRBL Configuration: Motion Control, Acceleration & Limit Tuning”
Leave a comment