How to Program Arduino CNC Machine
To program arduino cnc machine hardware you need three things in order: a flashed controller, correct motion settings, and G-code the machine can survive. This guide covers wiring, GRBL 1.1 setup, and the first-cut checks that stop a broken tool.

In this article
- 1
- 2
- 3
- 4
- 5
- 6
- 7
Key takeaways
What you need to program arduino cnc machine hardware
An Arduino CNC build is a small motion system: a controller board, stepper drivers, stepper motors, a power supply, and a spindle or tool. The Arduino runs firmware, usually GRBL, that reads G-code over serial and turns each line into step and direction pulses for the drivers.
GRBL is a fixed firmware, not a programming language you write from scratch. You flash it once, then change behavior through settings stored in EEPROM. That is why most of this guide is about configuration, not about writing sketches.
Boards that work well: Arduino Uno with GRBL 1.1, or a pin-compatible board such as the CNC Shield v3. Stepper drivers are typically A4988, DRV8825, or TMC2209. The TMC2209 runs quieter and handles 1/16 microstepping cleanly, which matters on a small router.
Power supply sizing is often wrong. Add the rated current of all stepper motors, then add 30% headroom. A three-axis build with 1.5 A motors needs a 24 V, 6 A supply at minimum. Undervoltage shows up as lost steps, not as an obvious fault.
Wiring order before you program arduino cnc machine
Wire in stages. Stage one is USB only: connect the Arduino to the PC and confirm it appears as a COM port. Stage two adds the drivers with the motor power supply off, so you can check jumper positions for microstepping without risk.
Stage three adds motors. Keep the power supply off and turn each motor shaft by hand. It should spin freely. If it feels notchy before power is applied, the coils are shorted through the driver and the driver is likely dead.
Stage four is the spindle or relay. Keep it on a separate circuit from the steppers. Noise from a brushed spindle on the same rail is a common cause of random resets mid-cut.
Flashing GRBL is straightforward. Open the Arduino IDE, load the GRBL sketch, select the board and port, and upload. Do not connect motor power during the upload. After upload, open the serial monitor at 115200 baud and send a question mark. A status line means the firmware is alive.
- 1Never hot-plug motorsDisconnect power before unplugging a stepper. The driver can fail in one move.
- 2Check jumper mathA4988 default is 1/16 microstep. DRV8825 and TMC2209 differ. Write it down.
- 3Share one groundController, drivers, and power supply must share a common ground.
The GRBL settings that decide accuracy
Steps per mm ($100, $101, $102) set how many pulses move one axis 1 mm. Calculate it: motor steps per revolution times microstep, divided by screw pitch in mm. A 200-step motor at 1/16 microstep on a 5 mm pitch screw gives 200 x 16 / 5 = 640 steps per mm.
If the value is wrong, the machine still moves and still cuts. It just cuts the wrong size. A 50 mm test square that measures 63 mm means your steps per mm is roughly 20% too low.
Maximum rate ($110-$112) is the fastest each axis can travel. Start at 2,000 mm/min on X and Y and 500 mm/min on Z for a small router. Acceleration ($120-$122) controls how quickly it gets there. Start at 100 mm/s² and raise it slowly.
Maximum travel ($130-$132) prevents the machine from driving into its own frame. Measure the real usable travel, then subtract 5 mm at each end. This one setting prevents more broken tools than any other.
Writing G-code you can actually run
You rarely hand-write G-code for a real part. Design in CAD, then use CAM such as Fusion 360, Carbide Create, or Inkscape for 2D work. The CAM step chooses toolpath, feed rate, and depth of cut, then exports a .nc file.
The post-processor must match your firmware. GRBL is not identical to Mach3 or LinuxCNC. Selecting the wrong post produces arcs and canned cycles GRBL rejects, and the job stops at line 12.
Read the first 30 lines before you run anything. Check the units command, the work offset, and the spindle speed. If G20 appears and your CAM was set in millimeters, the machine will run 25.4 times too far.
Feeds and speeds on a small Arduino router are conservative. In aluminum, a 6 mm two-flute end mill at 12,000 rpm runs around 800-1,200 mm/min with a 0.5 mm depth of cut. In MDF, the same tool can take 3 mm depth at 2,000 mm/min.
Step by step: from bare board to first cut
- 1Step 1: Flash GRBLConnect USB only. Upload GRBL 1.1 through the Arduino IDE. Open serial at 115200 baud. Send ? and confirm you get a status report.
- 2Step 2: Set steps per mmSend $100=640, $101=640, $102=640 for a 5 mm pitch screw at 1/16 microstep. Recalculate for your own screw and microstep.
- 3Step 3: Set travel limitsEnter measured travel minus 5 mm per end into $130, $131, $132. This caps the machine before it hits the frame.
- 4Step 4: Set rate and accelerationStart with $110=2000, $111=2000, $112=500 and $120-$122=100. Raise acceleration in 50 mm/s² steps until motors stall, then drop 20%.
- 5Step 5: Verify directionJog each axis 10 mm with G91 G0 X10. If it moves the wrong way, invert the direction bit in $3. Never fix direction by rewiring.
- 6Step 6: Cut airLoad the job with no tool and Z raised 20 mm. Watch the whole path at 50% feed override. Any crash here costs nothing.
- 7Step 7: Cut a test squareCut a 50 mm square in scrap at the real depth of cut. Measure it. Adjust steps per mm by the measured ratio and cut again.
- 8Step 8: Set work zero and runSet G54 zero on the stock corner, touch off Z on the top face, and run the job at 100% feed with the dust shoe in place.
Arduino CNC firmware and controller options
Pick the option that matches your machine size and the tolerance you need.
| Option | Best for | Limit | Watch out for |
|---|---|---|---|
| GRBL 1.1 on Uno | Small 3-axis router, hobby to light production | 3 axes, no tool changer | Serial buffer is small; long arcs stall |
| GRBL on Mega with shield | 4-axis builds with a rotary table | Extra pins, same core limits | Pin mapping must be edited in cpu_map |
| grblHAL on 32-bit board | Faster feed rates, more axes | Needs different board and IDE setup | Community plugins vary in quality |
| Dedicated motion controller | Production parts, ±0.005 mm work | Cost and setup time | Overkill if you only cut wood |
When to stop tuning the Arduino and send the part out
If the part needs tight tolerances, certified material, or inspection reports, an Arduino build will not get you there. Program arduino cnc machine hardware for prototypes and fixtures; send production parts to a shop with real metrology.
Questions engineers ask next
Can I program arduino cnc machine without GRBL?
Yes, but you write the step generation yourself. That means managing a timer interrupt for pulses, a G-code parser, and acceleration planning.
For most builds this is wasted effort. GRBL already handles look-ahead, arc interpolation, and soft limits. Only write custom firmware if you need behavior GRBL cannot express.
Why does my machine lose position mid-job?
The usual causes are acceleration set too high, current limit on the driver set too low, or mechanical binding on one axis.
Check the driver Vref first, then halve acceleration and rerun. If the loss disappears, raise acceleration in small steps until it returns, then back off 20%.
What current should I set on the stepper driver?
Set the driver to 70-85% of the motor's rated current. A 1.5 A motor runs at roughly 1.1-1.3 A.
Measure Vref on the driver potentiometer with the motor disconnected. Too high and the motor runs hot; too low and it skips steps under load.
How do I get G-code from my CAD model?
Export the model as STEP or STL, import it into CAM, define the stock and tool, then generate toolpaths.
Post-process with a GRBL post. Check the first 30 lines for units, offsets, and spindle speed before running.
Can an Arduino CNC hold ±0.005 mm?
An Arduino-based hobby router typically holds ±0.05 mm at best, limited by frame stiffness and screw quality.
Holding ±0.005 mm needs a rigid machine with ground ballscrews, temperature control, and metrology. That is production CNC territory, not a desktop build.
Need the part in metal, not in wood?
Upload your files and we will review them for manufacturability before you commit to a run.
12-hour quote100% inspectionNo minimum order