How to Make an Automated CNC Machine Using Arduino

Creating an automated CNC machine using Arduino is one of the best engineering projects for students in Pakistan. A CNC (Computer Numerical Control) machine automates cutting, drilling or milling using programmed commands — you draw a design on the computer, and the machine cuts it out. With Arduino-based control it becomes cost-effective and accessible for student projects and industrial prototypes. This guide explains every detail, from circuit design to component setup, using GRBL firmware and a CNC Shield.

Automated CNC machine circuit diagram — Arduino UNO, CNC Shield V3, GRBL, NEMA17 motors and limit switches.

How a CNC Machine Works

When you load a design into the software, the design is converted into G-code — simple text commands like "move to X20 Y20" or "cut down 1 mm". The G-code is sent to the Arduino over USB. GRBL firmware running on the Arduino reads the G-code and generates the step and direction pulses for the motors. The CNC Shield does not interpret commands — it is a passive board that only routes power and signals: it holds the stepper drivers, connects them to the Arduino pins, and feeds 12V to the motors. Each motor turns a lead screw, shifting the tool head precisely. Limit switches stop the tool safely at the defined boundary.

This project suits mechanical, electrical and electronics engineering students looking for practical automation experience.

Main Components Required

ComponentPrice / link
Arduino UNO R3 DIPArduino UNO R3 DIP ATmega328P with USB Cable — Rs 1,200
CNC Shield V3Arduino CNC Shield V3 Compatible with A4988 and DRV8825 Drivers — Rs 350
NEMA17 stepper motor × 3 (X, Y, Z axes)Branded NEMA 17 Stepper Motor — Rs 670 each
12V 2A AC/DC adapter12V 2A AC/DC Adapter — Rs 275
A4988 or DRV8825 stepper driver × 3No QKZEE listing — available at the Hall Road shop on request
Limit switch × 6 (two per axis)No QKZEE listing — available at the Hall Road shop on request
Frame, lead screws and linear railsNo QKZEE listing — build from aluminium extrusion or a kit
Small rotary tool / 775 DC motor (spindle)No QKZEE listing — any small rotary tool works as the cutting head
NodeMCU ESP8266 (optional, for the IoT version)NodeMCU ESP8266 CH340 WiFi Board — Rs 590

Use the Arduino UNO (or Nano) — standard GRBL does not run on the Arduino Mega. The small 28BYJ-48 stepper is too weak for a CNC; use NEMA17 motors.

Wiring

Step 1: Stack the Shield

Plug the CNC Shield V3 directly onto the Arduino UNO — it sits on top of the UNO's pins. No jumper wires are needed between the two boards.

Step 2: Fit the Drivers

Insert one A4988 or DRV8825 driver into each of the X, Y and Z slots on the shield. Check the orientation first: the driver's EN (enable) pin must line up with the shield's EN marking. A driver inserted backwards burns instantly. Fit the three microstepping jumpers under each driver (all three jumped = 1/16 microstepping on an A4988, 1/32 on a DRV8825).

Step 3: Connect the Motors

Connect each NEMA17 motor to its 4-pin port on the shield: X motor to the X port, Y to Y, Z to Z. If a motor runs backwards later, swap one coil pair (or fix it in software with $3 — see GRBL Settings below).

Step 4: Power — 12V to the Shield Only

Connect the 12V adapter to the shield's screw terminals (12–36V input). The 12V goes to the shield for the motors only — the Arduino is powered separately through its USB cable. Do not feed 12V into the Arduino's 5V pin.

Step 5: Limit Switches

Fit one limit switch at each end of each axis (6 total). Wire them to the shield's limit pins — see the GRBL pin table below. GRBL stops the machine when a switch is hit, so the tool cannot run past the end of an axis.

Step 6: USB Communication

Connect the Arduino to your computer via USB. This carries the G-code from Universal G-code Sender (UGS) to the GRBL firmware.

GRBL Pin Map (Arduino UNO)

SignalArduino pin
X stepD2
Y stepD3
Z stepD4
X directionD5
Y directionD6
Z directionD7
X limitD9
Y limitD10
Z limitD11
Spindle enableD12
Spindle directionD13
ProbeA5
Feed holdA1
Cycle startA2
ResetA0

Flashing GRBL onto the Arduino

GRBL is firmware, not a sketch you write — you flash it onto the UNO once, and from then on the UNO only understands G-code. (If you have never uploaded a sketch before, see our How to Upload Code in Arduino UNO guide first — the upload steps are the same.)

  1. Download GRBL from github.com/gnea/grbl (the grbl-master.zip file).
  2. In the Arduino IDE: Sketch → Include Library → Add .ZIP Library, and select the downloaded file.
  3. File → Examples → grbl → grblUpload. Select your UNO board and port, then Upload.
  4. Open the Serial Monitor at 115200 baud. It should print Grbl 1.1h ['$' for help]. If it prints garbage, the baud rate is wrong — set it to 115200.
  5. Open Universal G-code Sender (UGS), connect at 115200 baud, and type $$ to see the GRBL settings.

GRBL Settings You Will Actually Change

SettingWhat it means
$100, $101, $102Steps per mm for X, Y, Z — calibrate these (see Testing)
$110, $111, $112Maximum speed in mm/min for X, Y, Z
$120, $121, $122Acceleration in mm/s² for X, Y, Z
$130, $131, $132Maximum travel in mm for X, Y, Z
$3Direction invert — flips an axis that runs backwards
$22Homing enable (1 = home the machine on $H)
$$Show all settings

Sample G-code (Test Cut)

This cuts a 20 × 20 mm square, 2 mm deep, in two passes. Run it in UGS on a piece of foam first — never test a new machine on hard material.

G21         ; millimetres
G90         ; absolute positioning
G0 Z5       ; lift the tool to 5 mm
G0 X0 Y0    ; move to the start corner
G1 Z-1 F100 ; plunge 1 mm down
G1 X20 F300 ; cut along X
G1 Y20      ; cut along Y
G1 X0       ; back along X
G1 Y0       ; back along Y
G1 Z-2 F100 ; second pass, 2 mm deep
G1 X20 F300
G1 Y20
G1 X0
G1 Y0
G0 Z5       ; lift the tool
M30         ; end of program

What the G-code Does

  • G21 sets millimetres and G90 sets absolute positioning — every coordinate is measured from the same zero point.
  • G0 moves fast without cutting (the tool is lifted to Z5 first so it does not drag across the material).
  • G1 moves while cutting, at the feed rate after F (F300 = 300 mm/min; the plunge uses a slower F100).
  • The square is cut twice — 1 mm deep, then 2 mm deep — because cutting the full depth in one pass stalls the spindle and bends the tool.
  • M30 ends the program and resets to the start.

How to Make the CNC Machine

Step 1: Build the Frame

Build a rigid frame from aluminium extrusion or plywood, with lead screws and linear rails for the X, Y and Z axes. A wobbly frame gives wobbly cuts — rigidity matters more than size.

Step 2: Mount the Motors and Spindle

Mount one NEMA17 motor per axis, coupled to its lead screw, and the rotary tool as the spindle on the Z axis. Check each axis slides freely by hand before powering anything.

Step 3: Wire the Electronics

Stack the shield, fit the drivers (orientation first), connect the motors, the 12V supply and the limit switches as in the tables above. Set each driver's current (Vref) before the first run — for a typical 1.5 A NEMA17 with 0.1 Ω sense resistors, Vref ≈ 1.2 V on an A4988. Check your driver's datasheet; never run a driver with no motor connected.

Step 4: Flash GRBL and Connect UGS

Flash GRBL as above, connect UGS at 115200 baud, and confirm the Grbl 1.1h message. Jog each axis from UGS and check it moves the right way and the right distance.

Step 5: Calibrate Steps per mm

Command a 10 mm move and measure the real movement with a ruler. If it moved 8 mm, raise $100 (for X) by 10/8. Repeat until a commanded 10 mm is a real 10 mm on all three axes. This one step decides whether your parts come out the right size.

Step 6: First Cut in Foam

Run the sample G-code on foam or soft wood. Only when the square measures 20 × 20 mm should you cut harder material.

Testing the System

  1. Air cut first. Run the G-code with the spindle off and the tool lifted — watch the axes move the right pattern before anything cuts.
  2. Test homing. Send $H — the machine should move each axis to its limit switch and stop. If it keeps pushing, a limit switch is wired wrong.
  3. Measure the square. Cut the 20 × 20 mm test square in foam and measure it. Wrong size = wrong steps per mm ($100–$102).
  4. Test the limits. Jog each axis to its end by hand (slowly) and confirm the limit switch stops it.

Troubleshooting

  • GRBL prints garbage in the Serial Monitor: wrong baud rate — set it to 115200.
  • Driver dead on first power-up: it was inserted backwards. Check the EN pin marking before fitting the next one.
  • Motor stutters or does not move: driver current (Vref) too low, or a motor wire loose. Raise Vref slowly and check the connections.
  • Axis runs backwards: set $3 (direction invert) for that axis — do not rewire the motor.
  • Cut is the wrong size: steps per mm ($100–$102) are wrong — calibrate as in Step 5 above.
  • Machine ignores limit switches: check the switch wiring and that $21 (hard limits) is set to 1.
  • Spindle stalls in the cut: cut shallower per pass (1 mm, not 3 mm) and slow the feed rate.

Safety

A CNC machine has moving parts and a spinning cutter — treat it with respect. Keep hands clear of the tool while it runs. Wear eye protection. Fit an emergency-stop switch in the 12V line. Never leave a running machine unattended. This is a student model, not an industrial machine — do not cut metal with it.

Applications of Automated CNC Machines

  • Final year projects in Lahore universities
  • Industrial automation setups for small manufacturing units
  • PCB drilling and engraving for electronics projects
  • DIY robotics and mechanical projects
  • IoT-based smart manufacturing models

Many students in Pakistan use this system for their FYPs, combining mechanical design, electronics and software programming.

Advantages of Arduino-Based CNC Systems

  • Low cost compared to commercial CNCs
  • Easy programming with open-source GRBL
  • Accurate control with stepper motors
  • Expandable for IoT monitoring using ESP8266 or ESP32
  • Educational value for engineering and automation learning

Software and Hardware Integration

To create an advanced version, integrate:

  • ESP8266 module for IoT-based remote control
  • ThingSpeak IoT or Firebase for machine data logging
  • Touchscreen display for on-device operation

These upgrades make your CNC project part of the next generation of industrial automation.

Where to Buy the Components

The Arduino UNO, CNC Shield V3, NEMA17 motors, 12V adapter and NodeMCU are available at QKZEE Technologies, Shop 20, 1st Floor, Al-Khalil Center, Hall Road, Lahore, and online at qkzeetech.com with delivery all over Pakistan — see the links above. A4988/DRV8825 drivers, limit switches, the frame and lead screws, and the rotary tool spindle are available at the Hall Road shop on request.

Still Stuck?

If GRBL does not respond, or a motor does not move, message us — tell us what the Serial Monitor shows and which step you are on, and we will help you find the fault.

Chat on WhatsApp Watch on YouTube

FAQs

Can I use an Arduino Mega for GRBL?

No — standard GRBL runs on the ATmega328P (UNO/Nano) only. Use the UNO. The Mega is not supported.

Do I need the CNC Shield, or can I wire the drivers directly?

You can wire drivers directly to the Arduino, but the shield makes it far easier: it holds the drivers, routes the step/dir pins, and takes the 12V supply in one place. For a first build, use the shield.

Why does my driver burn on first power-up?

It was inserted backwards. The EN pin must line up with the shield's EN marking. Always check orientation before powering the shield.

What is Vref and why does it matter?

Vref sets the driver's motor current. Too low and the motor stalls; too high and the motor and driver overheat. Set it from your motor's rated current and your driver's datasheet before the first run.

Can this CNC cut metal?

No — this is a student model for foam, soft wood, plastic and PCB engraving. Cutting metal needs a rigid industrial machine and a proper spindle.

What software makes the G-code?

For 2D shapes, Inkscape with a G-code extension; for 3D parts, Fusion 360 or FreeCAD. Both export the .nc/.gcode files that UGS loads.

Conclusion

An automated CNC machine using Arduino is the perfect engineering project blending automation, mechanical control and IoT innovation. By following these steps — wire the shield and drivers correctly, flash GRBL, calibrate the steps per millimetre, and test on foam first — students in Pakistan can build a professional-grade system for final year projects or industrial automation research.