Guides · 10 min read

Arduino CNC Shield GRBL: Build a Mini CNC and Laser Engraver

Arduino CNC shield GRBL guide: flash GRBL, CNC Shield V3 pinout, A4988 Vref current, steps/mm and $100–$102, UGS, limit switches, laser safety.

The best-known Arduino CNC recipe has three parts: an Arduino Uno, a CNC Shield V3 plugged on top, and the free GRBL firmware that turns the Uno into a motion controller that understands G-code. With this trio you can build a pen plotter, a small router that carves wood and plastic, or an engraver driven by a diode laser. A program on your computer turns a drawing into lines of G-code, GRBL turns those lines into stepper motor pulses, and the machine moves with a precision of a tenth of a millimetre.

In this guide you'll flash GRBL onto the Uno, wire the CNC Shield's pins correctly for GRBL 1.1 and try the motors with a short test sketch first. Then you'll set the A4988 drivers' current with Vref, calculate the steps/mm value for your machine's mechanics, write it into the $100–$102 settings and run your first job with Universal G-code Sender. Homing with limit switches and the safety rules that are vital for laser engraving are covered too.

A4988 stepper motor driver module
A4988: one sits in the CNC Shield V3 for each axis; the small potentiometer on it sets the motor current.

What is GRBL and how does a mini CNC work?

GRBL is open-source CNC controller firmware written for ATmega328P boards (Uno, Nano). It reads G-code lines from the serial port, plans the moves ahead to work out acceleration and deceleration, and produces clean pulses at up to 30,000 steps per second. On the computer, a sender program streams the file line by line, and GRBL answers "ok" each time it accepts a line. The current version is GRBL 1.1, and it only runs on the 8-bit ATmega328P; the Arduino Uno R4, ESP32 or Mega need separate forks (such as FluidNC or grbl-Mega). So use a classic Uno R3 or a clone for this project.

PartJobNote
Arduino Uno R3Runs GRBL, turns G-code into step pulsesClones with a CH340 chip work too
CNC Shield V3Plugs onto the Uno, provides 4 driver sockets and screw terminalsMotor supply 12–36 V
A4988 driver × 3Drives the stepper of each axisDRV8825 or TMC2208 also fit
NEMA 17 stepper × 3Moves the X, Y and Z axesTypically 1.5–1.7 A, 1.8° (200 steps/rev)
12–24 V power supplyPowers the motors12 V 5 A or 24 V 3 A is enough for three NEMA 17
Mechanical switch × 3For limits and homingCan be wired NO or NC
Spindle or laser moduleCutting, carving or burningLaser driver with PWM input or a MOSFET motor driver
Computer and senderStreams the G-code fileUniversal G-code Sender, LaserGRBL, Candle

CNC Shield V3 pinout (GRBL 1.1)

Shield labelUno pinGRBL 1.1 function
X.STEP / Y.STEP / Z.STEPD2 / D3 / D4Step pulses
X.DIR / Y.DIR / Z.DIRD5 / D6 / D7Direction
END8Enables all drivers (active LOW)
X+ / X−D9X limit switch
Y+ / Y−D10Y limit switch
Z+ / Z−D11Spindle / laser PWM output in GRBL 1.1 (not the Z limit)
SpnEnD12Z limit switch in GRBL 1.1
SpnDirD13Spindle direction
Abort / Hold / ResumeA0 / A1 / A2Reset, feed hold and cycle start buttons
CoolEnA3Coolant (flood) output
SCL (Probe)A5Probe input (tool length measurement)
The CNC Shield V3 was designed before GRBL 1.1. Because GRBL 1.1 moved the PWM for a variable-speed spindle to D11, you must connect the Z limit switch to the SpnEn header (D12) instead of the shield's Z+/Z−; the PWM input of the laser or spindle driver goes to the Z+ pin (D11). If you follow an old diagram and plug the Z switch into Z+, you short the laser output or the Z axis never stops during homing.

Flashing GRBL step by step

  1. Download the source of the latest release from GRBL's GitHub page (gnea/grbl) as a ZIP and extract it.
  2. Zip the grbl folder inside (the one containing grbl.h) on its own, or copy it straight into Arduino's libraries folder.
  3. In the Arduino IDE, add that grbl folder as a library with Sketch > Include Library > Add .ZIP Library.
  4. Open File > Examples > grbl > grblUpload; it contains a single line that includes grbl.h, so don't change it.
  5. Select Arduino Uno and the right port and click Upload. The build uses most of the Uno's flash memory, which is normal.
  6. Open the Serial Monitor at 115200 baud with "Both NL & CR"; you should see the line "Grbl 1.1h ['$' for help]".
  7. Type $$ in the Serial Monitor and press Enter; if a list of all settings appears, GRBL is running. Close the Serial Monitor, because only one program can open the port at a time.

Hardware test: try the motors before GRBL

If a motor doesn't turn while GRBL is loaded, it's hard to tell whether the problem is the wiring, the driver or a setting. So first upload the short test sketch below: it turns each axis one revolution forward and one back in turn, then prints the state of the three limit switches to the Serial Monitor. The pin numbers are exactly the same as GRBL 1.1, so if the test passes, GRBL will work with the same wiring. When the test is done, flash GRBL again. You'll find the details of driving a single motor in the A4988 stepper driver guide.

C++ (Arduino IDE)
1// CNC Shield V3 donanım testi (GRBL yüklemeden önce) / hardware test before flashing GRBL
2// Pinler GRBL 1.1 ile aynı / pins match GRBL 1.1
3const int STEP_PIN[3] = {2, 3, 4};      // X, Y, Z STEP
4const int DIR_PIN[3] = {5, 6, 7};       // X, Y, Z DIR
5const int EN_PIN = 8;                   // Tüm sürücüler, aktif LOW / all drivers, active LOW
6const int LIMIT_PIN[3] = {9, 10, 12};   // X, Y, Z limit (GRBL 1.1'de Z = D12 / Z = D12 in GRBL 1.1)
7const char AXIS[3] = {'X', 'Y', 'Z'};
8const long STEPS = 200L * 16;           // 1/16 mikro adımda bir tur / one revolution at 1/16 microstep
9
10void setup() {
11  Serial.begin(115200);
12  for (int i = 0; i < 3; i++) {
13    pinMode(STEP_PIN[i], OUTPUT);
14    pinMode(DIR_PIN[i], OUTPUT);
15    pinMode(LIMIT_PIN[i], INPUT_PULLUP);  // Anahtar basınca GND'ye çeker / switch pulls to GND when pressed
16  }
17  pinMode(EN_PIN, OUTPUT);
18  digitalWrite(EN_PIN, LOW);            // Sürücüleri aç / enable the drivers
19}
20
21void moveAxis(int axis, long steps, bool dir) {
22  digitalWrite(DIR_PIN[axis], dir);
23  delayMicroseconds(5);                 // DIR, STEP'ten önce otursun / let DIR settle before STEP
24  for (long s = 0; s < steps; s++) {
25    digitalWrite(STEP_PIN[axis], HIGH);
26    delayMicroseconds(10);
27    digitalWrite(STEP_PIN[axis], LOW);
28    delayMicroseconds(300);             // Yaklaşık saniyede 1 tur / about one revolution per second
29  }
30}
31
32void loop() {
33  for (int a = 0; a < 3; a++) {
34    Serial.print(AXIS[a]);
35    Serial.println(F(" ileri / forward"));
36    moveAxis(a, STEPS, HIGH);
37    delay(300);
38    Serial.print(AXIS[a]);
39    Serial.println(F(" geri / back"));
40    moveAxis(a, STEPS, LOW);
41    delay(300);
42  }
43  for (int a = 0; a < 3; a++) {         // Limit anahtarları: LOW = basılı / limit switches: LOW = pressed
44    Serial.print(AXIS[a]);
45    Serial.print(F(" limit: "));
46    Serial.println(digitalRead(LIMIT_PIN[a]) == LOW ? F("BASILI / PRESSED") : F("serbest / free"));
47  }
48  delay(1000);
49}
50

Setting the A4988 current (Vref)

The potentiometer on the A4988 sets the upper limit of the motor current. The formula is I = Vref / (8 × Rs), or turned around, Vref = I × 8 × Rs. Rs is one of the two small sense resistors next to the chip: R100 means 0.1 Ω, R068 means 0.068 Ω and R050 means 0.05 Ω; the SMD resistor code calculator helps you decode them. To measure, power the shield with 12–24 V, set the multimeter to DC 2 V, touch the black probe to GND and the red one to the metal top of the potentiometer, and adjust by turning very slightly with a plastic-tipped screwdriver. Even if the motor label says 1.7 A, an A4988 without a heatsink comfortably handles about 1 A; 0.8–1.0 A is a good starting point for a mini CNC.

Rs markingFormulaVref for 0.8 AVref for 1.0 AVref for 1.2 A
R050 (0.05 Ω)Vref = I × 0.40.32 V0.40 V0.48 V
R068 (0.068 Ω)Vref = I × 0.5440.44 V0.54 V0.65 V
R100 (0.1 Ω)Vref = I × 0.80.64 V0.80 V0.96 V
DRV8825 (different formula)Vref = I / 20.40 V0.50 V0.60 V
Never plug or unplug a stepper motor cable while the power is on, and never insert a driver the wrong way round; either will kill an A4988 instantly. When you insert a driver, check that its EN pin lines up with the EN label on the shield and that the potentiometer usually faces the outer edge of the shield. Reversing the power supply's plus and minus on the terminal can also destroy every driver.

Steps/mm calculation and the $100–$102 settings

You tell GRBL how many step pulses to send to move each axis 1 mm: steps/mm = (motor steps per revolution × microstepping) / travel per revolution (mm). A 1.8° NEMA 17 makes 200 steps per revolution; with all three jumpers fitted under the driver on the CNC Shield, the A4988 runs at 1/16 microstepping and one revolution takes 3200 pulses. The travel per revolution depends on the mechanics: for a belt it's pulley teeth × belt pitch, for a lead screw it's the screw's lead. After calculating, always calibrate: command G1 X100, measure the real travel with a ruler and correct it with new value = old value × 100 / measured. For example, if 80 steps/mm moved 98.5 mm, the new value is 80 × 100 / 98.5 = 81.22, so you enter $100=81.22.

MechanicsTravel per revolutionCalculation (200 steps, 1/16)Steps/mm ($100–$102)
GT2 belt, 20-tooth pulley40 mm3200 / 4080
GT2 belt, 16-tooth pulley32 mm3200 / 32100
T8 lead screw, 8 mm lead (4-start)8 mm3200 / 8400
T8 lead screw, 2 mm lead (single start)2 mm3200 / 21600
M8 threaded rod (1.25 mm)1.25 mm3200 / 1.252560
DVD drive mechanism (20 steps/rev, 3 mm)3 mm20 × 16 / 3About 106.7 (verify by measuring)

Key GRBL settings table

SettingMeaningGRBL defaultExample for a mini CNC / laser
$100, $101, $102X, Y, Z steps/mm25080 on a belt, 400 on a T8 screw
$110, $111, $112Maximum rate (mm/min)5003000 on a belt, 800 on a screw, 400 for Z
$120, $121, $122Acceleration (mm/s²)10200 on a belt, 50 on a screw
$130, $131, $132Maximum travel (mm)200The machine's real work area, e.g. 300, 200, 45
$3Direction invert mask (X=1, Y=2, Z=4)02 if Y runs backwards, 5 if X and Z do
$1Step idle delay (ms)25255: motors stay locked, axes don't drift
$5Invert limit pins01 if you use NC switches
$20 / $21Soft / hard limits0 / 01 / 1 with switches fitted (soft limits need homing)
$22Homing cycle01 with switches fitted
$30Value of the highest S1000S1000 = 100% PWM
$32Laser mode01 for laser engraving, 0 for a spindle

Your first job with Universal G-code Sender

  1. Download the Platform version of Universal G-code Sender (UGS); the Windows, macOS and Linux packages include Java.
  2. Select the Uno's port, 115200 baud and GRBL as the firmware, then click Connect; you should see GRBL's start-up line in the console.
  3. Use the Setup Wizard first to check motor directions, steps/mm values and limit switches step by step.
  4. Jog each axis in 1 mm and 10 mm steps from the Jog panel; if a direction is wrong, fix the $3 mask.
  5. Move the tip (pen, cutter or laser dot) to the bottom-left corner of the workpiece and set the work zero with Reset Zero.
  6. Open the G-code file with File > Open; check in the Visualizer that the path sits on the workpiece.
  7. Do the first run in the air: raise Z a few millimetres or keep the laser off and watch the whole path, then start the real job with Send.
CommandWhat it does
G21 / G90Units in millimetres / absolute coordinates
G0 X10 Y10Rapid move (no cutting); in laser mode the laser stays off
G1 X50 Y20 F600Linear cutting move at 600 mm per minute
G2 / G3Clockwise / counter-clockwise arc
M3 S500 / M4 S500Spindle on at 50% / dynamic laser power adjusted to speed in laser mode
M5Spindle or laser off
$H / $XHoming cycle / clear the alarm lock
? and Ctrl+XReal-time status report / soft reset of GRBL

What UGS does behind the scenes is actually simple: it sends a line, waits for "ok" from GRBL, then sends the next. The small Python script below runs this send-and-wait protocol on your own computer; install the pyserial library and change the PORT variable to the Uno's port. It prints error lines and stops if an ALARM arrives. For real jobs use proven programs such as UGS or LaserGRBL; this script is for seeing how GRBL talks and for automation experiments. If the computer doesn't see the Uno, read the CH340 driver installation article.

Python
1# Basit GRBL G-code gönderici (bilgisayarda çalışır) / simple GRBL G-code sender (runs on the PC)
2# Kurulum / install: pip install pyserial
3# Kullanım / usage: python gonder.py cizim.gcode
4import sys
5import time
6import serial
7
8PORT = "COM3"   # Linux: "/dev/ttyACM0" ya da "/dev/ttyUSB0", macOS: "/dev/cu.usbmodem..." / or
9DOSYA = sys.argv[1] if len(sys.argv) > 1 else "cizim.gcode"
10
11with serial.Serial(PORT, 115200, timeout=2) as grbl:
12    grbl.write(b"\r\n\r\n")         # GRBL'i uyandır / wake GRBL up
13    time.sleep(2)                   # Açılış mesajını bekle / wait for the start-up banner
14    grbl.reset_input_buffer()
15    with open(DOSYA) as f:
16        for satir in f:
17            satir = satir.split(";")[0].strip()   # Yorumu ve boşlukları at / drop comments and spaces
18            if not satir:
19                continue
20            grbl.write((satir + "\n").encode())
21            while True:             # "ok" ya da hata gelene kadar bekle / wait for "ok" or an error
22                cevap = grbl.readline().decode(errors="ignore").strip()
23                if cevap == "ok":
24                    break
25                if cevap.startswith("error"):
26                    print("HATA / ERROR:", satir, "->", cevap)
27                    break
28                if cevap.startswith("ALARM"):
29                    sys.exit("ALARM: " + cevap + " ($X ile kilidi aç / unlock with $X)")
30            print(satir)
31print("Bitti / done")
32

Limit switches and homing

Limit switches mark the ends of the machine and do two jobs: hard limits ($21=1) stop the machine before an axis crashes into its end, and the homing cycle ($22=1, the $H command) drives the axes to the switches at every start-up to find the machine's own zero point. GRBL uses internal pull-up resistors on the limit pins; just connect one side of the switch to the signal pin and the other to GND. After homing you can also enable soft limits ($20=1): GRBL rejects any command that would leave the work area before it even starts.

  • NO or NC: normally open (NO) wiring is simple, but normally closed (NC) also catches a broken cable as an alarm; if you use NC, set $5=1.
  • Noise: long switch cables running next to motor cables can cause false ALARM:1 errors. Use shielded or twisted cable and add a 100 nF capacitor between signal and GND.
  • Direction: by default homing drives the axes in the positive direction; if your switches are at the front left of the machine, invert the direction with the $23 mask (X=1, Y=2, Z=4).
  • Pull-off: $27 sets how far the axis backs off after touching the switch; 1–2 mm is enough for the switch to release.
  • Z axis: in GRBL 1.1 the Z switch goes to D12 (the SpnEn header); homing always starts by raising Z, so the tip doesn't drag across the workpiece.

Laser engraving and laser safety

Diode laser modules are usually powered from 12 V and have a TTL/PWM input. Connect that input to the shield's Z+ pin (D11) and GND, and enable laser mode in GRBL with $32=1. In laser mode GRBL switches the laser off automatically during G0 rapids, and with M4 it scales the power to the instantaneous speed, so lines don't get thicker as the machine slows into corners. With $30=1000, S1000 means full power and S100 means 10%. For photo and logo engraving, a program such as LaserGRBL converts the image straight into G-code. If you use a 775-type DC motor as a spindle, never connect D11 directly to the motor; put a MOSFET driver board in between. For the general features of small laser modules, see the laser module article.

Engraving lasers (usually 445 nm blue, 2–10 W optical power) are Class 4 devices: both the direct beam and reflections from shiny surfaces cause instant, permanent eye damage. Always wear certified laser goggles rated at least OD4+ for 445 nm; the tinted glasses bundled with cheap modules are often not enough. Put the machine in a closed, light-tight enclosure, never leave it unattended while it runs, keep a fire extinguisher nearby and vent the smoke outside. Never cut PVC, vinyl or faux leather: they release chlorine gas when burned, which harms both you and the machine. Don't run a laser around children or pets.
Arduino Uno with GRBL
Arduino Uno R3: GRBL only runs on the ATmega328P; the Uno R4 and ESP32 need other firmware.

Arduino CNC project ideas

  • Pen plotter: draw on paper with two axes; lift the pen with a small motor on Z or use a GRBL fork with servo support (what is a servo motor).
  • Wood laser engraving: burn names or logos into cutting boards, key rings and box lids; draw low-power test squares (S100) first.
  • PCB isolation milling: mill circuit boards out of copper-clad board; prepare the design as in the PCB design with EasyEDA article.
  • Quiet machine: fit TMC2209 drivers instead of A4988 to almost eliminate the motor whine (TMC2209 stepper driver).
  • Motor choice: compare which motor makes most sense for which axis (DC vs servo vs stepper motors).

Common mistakes and fixes

SymptomLikely causeFix
ALARM:1 and motion stoppedA hard limit triggered or the switch cable picks up noiseUnlock with $X, check the switch, add 100 nF or wire it NC
error:9 replyGRBL is in alarm lock and won't accept G-codeUnlock with $X or home with $H
ALARM:2The command is outside the soft limits ($130–$132)Check the work zero and the work area settings
ALARM:9 during homingThe axis didn't find its switch within the search distanceCheck the $23 direction, the switch cable and the D12 connection
Motor vibrates but doesn't turnCoil pairs are mismatched or the speed is too highFind the coils with a multimeter, lower $110 and $120
Drawing comes out the wrong sizeSteps/mm doesn't match the mechanicsCalculate, then measure a 100 mm move and calibrate $100–$102
Layers shift or steps are lost on long jobsAcceleration or speed too high, current too low or the driver overheatsLower $110 and $120, raise Vref by 0.1 A, add a heatsink and fan
Laser burns during G0 moves tooLaser mode is offSet $32=1 and use M4 instead of M3

Before building a CNC machine, getting to know steppers, servos and laser modules one by one makes the job much easier. The BlueGrays app has projects such as using a stepper motor, turning a stepper into a 360-degree servo, servo control with a potentiometer and a laser warning system, each with a wiring diagram and ready-made code; once that foundation is in place, you'll build your first GRBL mini CNC with far more confidence.

Frequently asked questions

Can you build a CNC machine with an Arduino?

Yes. With an Arduino Uno, a CNC Shield V3 and three A4988 drivers running the GRBL firmware, you can build a pen plotter, a small router or a laser engraver. GRBL reads G-code files and drives the steppers with a precision of a tenth of a millimetre.

How do I install GRBL on an Arduino?

Add the grbl folder from GRBL's source code to the Arduino IDE as a library, then open the grblUpload example from the Examples menu and upload it to the Uno. If you see the "Grbl 1.1" line in the Serial Monitor at 115200 baud, it's installed.

How do I calculate GRBL steps per mm?

Steps/mm is the motor's steps per revolution times the microstepping, divided by the travel per revolution. With a 200-step motor at 1/16 microstepping, a 20-tooth GT2 pulley gives 3200 / 40 = 80 and a T8 screw with 8 mm lead gives 3200 / 8 = 400. Always calibrate the result by measuring.

What should the A4988 Vref be?

Use Vref = desired current × 8 × Rs. On common boards with R100 resistors, 1 A needs 0.80 V and 0.8 A needs 0.64 V. An A4988 without a heatsink handles about 1 A comfortably, so 0.8–1.0 A is a good starting point for a mini CNC.

Which pin is the Z limit on the CNC Shield V3?

In GRBL 1.1 the Z limit switch goes to D12, the SpnEn header on the shield. D11, labelled Z+ and Z−, is the spindle and laser PWM output in GRBL 1.1. This is often confused because older diagrams were drawn for GRBL 0.9.

How do I do laser engraving with GRBL?

Connect the laser module's PWM input to D11, enable laser mode with $32=1 and set the power with M4 S commands. Programs like LaserGRBL convert images straight into G-code. Before engraving, always wear OD4+ goggles rated for your laser's wavelength and run the machine in a closed enclosure.

See all projects
Using a Stepper Motor
AR-67Intermediate
Premium

Using a Stepper Motor

A motor that turns step by step, exactly as far as you want, like the hand of a clock.

4.5(31)
42
360-Degree Servo from a Stepper Motor
AR-68Intermediate
Premium

360-Degree Servo from a Stepper Motor

Teach an ordinary stepper motor to go to any angle you want, all the way around the circle.

4.5(22)
33
Using a Servo Motor
AR-35Beginner
Premium

Using a Servo Motor

The arm of a small servo motor turns to three positions in turn: all the way to the start, right to the middle and all the way to the end, waiting two seconds at each stop.

4.7(49)
69
Servo Motor Operation with Potentiometer
AR-36Beginner
Premium

Servo Motor Operation with Potentiometer

As you turn the potentiometer knob, the servo motor's arm turns right along with it: one end of the knob means zero degrees, the other end means half a turn.

4.6(37)
54
Laser Warning System
AR-22Intermediate
Premium

Laser Warning System

You set up an invisible beam fence, just like in the movies. A laser shines onto a light sensor on the other side; the moment someone walks through and breaks the beam, the LED lights up and the…

4.8(65)
83
Laser Security System
AR-23Advanced
Premium

Laser Security System

Just like the laser heist scenes in films: a laser beam shines on a light sensor, and the moment someone steps in and breaks the beam, the red LED lights up and the buzzer starts sounding.

4.8(61)
78
ESP32 Servo Motor (Potentiometer Control)
ES-16Intermediate
Premium

ESP32 Servo Motor (Potentiometer Control)

In this project, we control an SG90 servo motor using a potentiometer. We adjust the servo angle by mapping the analog value read from the potentiometer to the 0–180-degree range. The ESP32Servo library generates servo signals on suitable output-capable GPIO pins of the ESP32; this project uses GPIO 18. This is a fundamental control method for robotic arms, camera gimbals, and automatic door mechanisms.

4.3(30)
42