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.

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.
| Part | Job | Note |
|---|---|---|
| Arduino Uno R3 | Runs GRBL, turns G-code into step pulses | Clones with a CH340 chip work too |
| CNC Shield V3 | Plugs onto the Uno, provides 4 driver sockets and screw terminals | Motor supply 12–36 V |
| A4988 driver × 3 | Drives the stepper of each axis | DRV8825 or TMC2208 also fit |
| NEMA 17 stepper × 3 | Moves the X, Y and Z axes | Typically 1.5–1.7 A, 1.8° (200 steps/rev) |
| 12–24 V power supply | Powers the motors | 12 V 5 A or 24 V 3 A is enough for three NEMA 17 |
| Mechanical switch × 3 | For limits and homing | Can be wired NO or NC |
| Spindle or laser module | Cutting, carving or burning | Laser driver with PWM input or a MOSFET motor driver |
| Computer and sender | Streams the G-code file | Universal G-code Sender, LaserGRBL, Candle |
CNC Shield V3 pinout (GRBL 1.1)
| Shield label | Uno pin | GRBL 1.1 function |
|---|---|---|
| X.STEP / Y.STEP / Z.STEP | D2 / D3 / D4 | Step pulses |
| X.DIR / Y.DIR / Z.DIR | D5 / D6 / D7 | Direction |
| EN | D8 | Enables all drivers (active LOW) |
| X+ / X− | D9 | X limit switch |
| Y+ / Y− | D10 | Y limit switch |
| Z+ / Z− | D11 | Spindle / laser PWM output in GRBL 1.1 (not the Z limit) |
| SpnEn | D12 | Z limit switch in GRBL 1.1 |
| SpnDir | D13 | Spindle direction |
| Abort / Hold / Resume | A0 / A1 / A2 | Reset, feed hold and cycle start buttons |
| CoolEn | A3 | Coolant (flood) output |
| SCL (Probe) | A5 | Probe input (tool length measurement) |
Flashing GRBL step by step
- Download the source of the latest release from GRBL's GitHub page (gnea/grbl) as a ZIP and extract it.
- Zip the grbl folder inside (the one containing grbl.h) on its own, or copy it straight into Arduino's libraries folder.
- In the Arduino IDE, add that grbl folder as a library with Sketch > Include Library > Add .ZIP Library.
- Open File > Examples > grbl > grblUpload; it contains a single line that includes grbl.h, so don't change it.
- Select Arduino Uno and the right port and click Upload. The build uses most of the Uno's flash memory, which is normal.
- Open the Serial Monitor at 115200 baud with "Both NL & CR"; you should see the line "Grbl 1.1h ['$' for help]".
- 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.
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}
50Setting 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 marking | Formula | Vref for 0.8 A | Vref for 1.0 A | Vref for 1.2 A |
|---|---|---|---|---|
| R050 (0.05 Ω) | Vref = I × 0.4 | 0.32 V | 0.40 V | 0.48 V |
| R068 (0.068 Ω) | Vref = I × 0.544 | 0.44 V | 0.54 V | 0.65 V |
| R100 (0.1 Ω) | Vref = I × 0.8 | 0.64 V | 0.80 V | 0.96 V |
| DRV8825 (different formula) | Vref = I / 2 | 0.40 V | 0.50 V | 0.60 V |
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.
| Mechanics | Travel per revolution | Calculation (200 steps, 1/16) | Steps/mm ($100–$102) |
|---|---|---|---|
| GT2 belt, 20-tooth pulley | 40 mm | 3200 / 40 | 80 |
| GT2 belt, 16-tooth pulley | 32 mm | 3200 / 32 | 100 |
| T8 lead screw, 8 mm lead (4-start) | 8 mm | 3200 / 8 | 400 |
| T8 lead screw, 2 mm lead (single start) | 2 mm | 3200 / 2 | 1600 |
| M8 threaded rod (1.25 mm) | 1.25 mm | 3200 / 1.25 | 2560 |
| DVD drive mechanism (20 steps/rev, 3 mm) | 3 mm | 20 × 16 / 3 | About 106.7 (verify by measuring) |
Key GRBL settings table
| Setting | Meaning | GRBL default | Example for a mini CNC / laser |
|---|---|---|---|
| $100, $101, $102 | X, Y, Z steps/mm | 250 | 80 on a belt, 400 on a T8 screw |
| $110, $111, $112 | Maximum rate (mm/min) | 500 | 3000 on a belt, 800 on a screw, 400 for Z |
| $120, $121, $122 | Acceleration (mm/s²) | 10 | 200 on a belt, 50 on a screw |
| $130, $131, $132 | Maximum travel (mm) | 200 | The machine's real work area, e.g. 300, 200, 45 |
| $3 | Direction invert mask (X=1, Y=2, Z=4) | 0 | 2 if Y runs backwards, 5 if X and Z do |
| $1 | Step idle delay (ms) | 25 | 255: motors stay locked, axes don't drift |
| $5 | Invert limit pins | 0 | 1 if you use NC switches |
| $20 / $21 | Soft / hard limits | 0 / 0 | 1 / 1 with switches fitted (soft limits need homing) |
| $22 | Homing cycle | 0 | 1 with switches fitted |
| $30 | Value of the highest S | 1000 | S1000 = 100% PWM |
| $32 | Laser mode | 0 | 1 for laser engraving, 0 for a spindle |
Your first job with Universal G-code Sender
- Download the Platform version of Universal G-code Sender (UGS); the Windows, macOS and Linux packages include Java.
- 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.
- Use the Setup Wizard first to check motor directions, steps/mm values and limit switches step by step.
- Jog each axis in 1 mm and 10 mm steps from the Jog panel; if a direction is wrong, fix the $3 mask.
- Move the tip (pen, cutter or laser dot) to the bottom-left corner of the workpiece and set the work zero with Reset Zero.
- Open the G-code file with File > Open; check in the Visualizer that the path sits on the workpiece.
- 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.
| Command | What it does |
|---|---|
| G21 / G90 | Units in millimetres / absolute coordinates |
| G0 X10 Y10 | Rapid move (no cutting); in laser mode the laser stays off |
| G1 X50 Y20 F600 | Linear cutting move at 600 mm per minute |
| G2 / G3 | Clockwise / counter-clockwise arc |
| M3 S500 / M4 S500 | Spindle on at 50% / dynamic laser power adjusted to speed in laser mode |
| M5 | Spindle or laser off |
| $H / $X | Homing cycle / clear the alarm lock |
| ? and Ctrl+X | Real-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.
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")
32Limit 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.

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
| Symptom | Likely cause | Fix |
|---|---|---|
| ALARM:1 and motion stopped | A hard limit triggered or the switch cable picks up noise | Unlock with $X, check the switch, add 100 nF or wire it NC |
| error:9 reply | GRBL is in alarm lock and won't accept G-code | Unlock with $X or home with $H |
| ALARM:2 | The command is outside the soft limits ($130–$132) | Check the work zero and the work area settings |
| ALARM:9 during homing | The axis didn't find its switch within the search distance | Check the $23 direction, the switch cable and the D12 connection |
| Motor vibrates but doesn't turn | Coil pairs are mismatched or the speed is too high | Find the coils with a multimeter, lower $110 and $120 |
| Drawing comes out the wrong size | Steps/mm doesn't match the mechanics | Calculate, then measure a 100 mm move and calibrate $100–$102 |
| Layers shift or steps are lost on long jobs | Acceleration or speed too high, current too low or the driver overheats | Lower $110 and $120, raise Vref by 0.1 A, add a heatsink and fan |
| Laser burns during G0 moves too | Laser mode is off | Set $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.
Projects to build after reading this
See all projects
Using a Stepper Motor
A motor that turns step by step, exactly as far as you want, like the hand of a clock.

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.

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.

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.

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…

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.

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.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32, ESP8266, Pico, mBot and micro:bit projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

