## Introduction: Maze Using CNC M &G Code

There are 2 ways to use a CNC machine. Model your design, and have the computer magically convert it to code that the CNC Machine can read but you can't, or learn the basics to CNC M & G code so that you know whats going on and can troubleshoot problems. It's like coding anything on the computer if you only rely on the magic program to code you're doing yourself a disservice.

Sure with advanced shapes you'll most likely rely on the magic box more, but this tutorial is like the hello world of CNC, the first step to learning any new coding language, the NOTEPAD step.

The machine used for this instructable is a Davinci from my school's shop.

## Step 1: Basic Code and Definations

G90 or G91 = Absolute or Incremental Coordinates.

G70 or G71 = inches or metric

G20 or G21 = inches or metric

G92 X# Y# X#

M06 T#

G43 H#

Body Code:

G00 X# Y# Z#

G01 X# Y# Z#

G02 X# Y# Z# I# J# K#

G03 X# Y# Z# I# J# K#

G81 Z# R# F#

G83

G80

Finish Code:

G28

M05

M02

M03

Before starting here are some tips:

## Step 2: Preliminary Drawing

Before starting to code, some preliminary steps are needed. First you need to get some grid paper out and measure off the outline of the block of wood using 1/4 of an inch increments. For example, the block of wood is 3.5 x 6 inches.

Steps:

Draw any design on grid paper to get the points. Try to keep the ends of the lines and center of the circles on a grid so that everything is easier to calculate.

set the bottom left corner to be 0,0 . find the X Y coordinates of every point that is needed for the CNC to follow the path including the center of the of circles and arcs.

## Step 3: Table of Absolutes

All the points found for the picture need to be ordered from start to finish the way they will be cut. See the picture.

Arcs are the most confusing. On the table of absolutes, the line with the start of the arc should also have the distance from the start to the center of the arc in the I and J values. Then the next line should have the coordinates to the end of the arc. When coding the center of the arc is on the same line as the end of the arc, but the coordinates are the same as here. It will be more clear after I give example of the code.

## Step 4: Start Code Example

This is my example of start code. Everything after a ( is a note and will be ignored.

G90 (set to absolute coordinates

G70 (set to inches

M06 T1 (set to tool #1, don't have tool changer

G92 X0.0 Y0.0 Z1.0 (set home position

M03 S2000 (turns spindle on with a speed of 2000 rpm

## Step 5: Body Code

The notes explain the line above them

G00 X0.75 Y1.5 Z0.25

(notice that because there is no change in Z we can omit it

(all it says is Y2.0 because X and Z are assumed to be the same

Y2.75

G02 X0.75 Y3.0 I0.25 J0.0

X5.0

X5.5

Y1.75

X4.25 (POINT 15

Y1.5

Y1.75

X3.75

Y1.5

Y1.75 (PT 20

X3.5

X3.75

Y2.5

X4.5

Y2.25

Y2.5

X5.0

X3.0

Y2.25

Y2.5 (PT 30

X1.0

X1.25

Y2.25

Y2.5

X2.25

Y1.75

X2.75

X2.5

Y1.5

Y1.75 (40

X1.75

Y1.5

X.75

Z0.25

G00 X0.0 Y0.0 Z1.0

## Step 6: End Code

Not much to it, turn off the drill, stop the code and end the job.

M05 (turns off the spindle

M02 (stop the code

M30 (end the job

## Step 7: Full Maze Code

Almost done now with a few less comments this is the full code I used to cut the map of the maze.

G90 (set to absolute coordinates

G70 (set to inches

M06 T1 (set to tool #1 don't have tool changer

G92 X0.0 Y0.0 Z1.0 (set home position

M03 S2000 (turn spindle on

G00 X0.75 Y1.5 Z0.25 (point 1 not touching yet

G01 Z-0.125 F8.0 (start cutting material

G02 X0.5 Y1.75 I0.0 J0.25 (first arc

G01 Y2.0 (POINT 3

X.75

X.5

Y2.75

G02 X0.75 Y3.0 I0.25 J0.0 (arc

G01 X5.25

G02 X5.5 Y2.75 I0.0 J-0.25 (arc

G01 Y0.5 (POINT 10

Y1.0

X5.0

X5.5

Y1.75

X4.25 (POINT 15

Y1.5

Y1.75

X3.75

Y1.5

Y1.75 (PT 20

X3.5

X3.75

Y2.5

X4.5

Y2.25

Y2.5

X5.0

X3.0

Y2.25

Y2.5 (PT 30

X1.0

X1.25

Y2.25

Y2.5

X2.25

Y1.75

X2.75

X2.5

Y1.5

Y1.75 (40

X1.75

Y1.5

X.75

Z0.25

G00 X0.0 Y0.0 Z1.0 (take bit 1 inch above board

M05 (turn off spindle

M02 (stop

M30 (end

## Step 8: Drilling Code

G90 (set to absolute coordinates

G70 (set to inches

M06 T1 (set to tool #1 don't have tool changer

G92 X0.0 Y0.0 Z1.0 (set home position

M03 S2000 (turn spindle on

G00 X0.25 Y2.0

(notice first hole coordinate is the point before the G81

X1.5 Y3.25 (hole 2

X4.25 Y3.25

X5.75 Y2.25

X4.25 Y1.5

G80

(the G80 stops the holes

M05 (turn off spindle

M02 (stop

M30 (end

## Step 9: Name Code

Here is code i used to write Bill Reen if you need more examples. There is nothing special in the code besides lifting off the board between letters.

G90 (set to absolute coordinates

G70 (set to inches

M06 T1 (set to tool #1 don't have tool changer

G92 X0.0 Y0.0 Z1.0 (set home position

M03 S2000 (turn spindle on

G00 X0.25 Y0.25 Z0.25 (point 1 NOT TOUCHING

G01 Z-0.03 F8.0 (drill goes into material

Y1.25 (POINT 2

X0.5 (POINT 3

G02 X0.5 Y0.75 I0.0 J-0.25 (an arc from point 3 to x.5 y .75

G01 X0.25

Y0.25

X0.5

G03 X0.5 Y0.75 I0.0 J0.25 (an arc for bottom of B

G00 Z0.25 (LIFT OFF BOARD FAST

X1.0 Y0.25 (MOVE FAST TO BOTTOM OF I

G01 Z-0.03 (DRILL INTO BOARD

Y0.75 (TOP OF I

G00 Z0.25 (LIFT OFF BOARD FAST

X1.25 Y0.25 (MOVE FAST TO BOTTOM OF L1

G01 Z-0.03 (DRILL INTO BOARD

Y1.25 (TOP OF L1

G00 Z0.25 (LIFT OFF BOARD FAST

X1.5 Y0.25 (MOVE FAST TO BOTTOM OF L2

G01 Z-0.03 (DRILL INTO BOARD

Y1.25 (TOP OF L2

G00 Z0.25 (LIFT OFF BOARD FAST

X2.0 Y0.25 (MOVE FAST TO BOTTOM OF R

G01 Z-0.03 (DRILL INTO BOARD

Y1.25 (TOP OF R

X2.25

G02 X2.25 Y0.75 I0.0 J-0.25

G01 X2.0

X2.26

X2.5 Y.25

G00 Z0.25 (LIFT OFF BOARD FAST

X3.0 Y0.25 (MOVE FAST TO BOTTOM OF E1

G01 Z-0.03 (DRILL INTO BOARD

X2.75 (SIDE OF E1

Y.5

X3.0

X2.75

Y0.75

X3.0

G00 Z0.25 (LIFT OFF BOARD FAST

X3.5 Y0.25 (MOVE FAST TO BOTTOM OF E2

G01 Z-0.03 (DRILL INTO BOARD

X3.25 (SIDE OF E2

Y.5

X3.5

X3.25

Y0.75

X3.5

G00 Z0.25 (LIFT OFF BOARD FAST

X3.75 Y0.25 (MOVE FAST TO BOTTOM OF N

G01 Z-0.03 (DRILL INTO BOARD

Y0.75 (TOP OF N

X4.0 Y0.25

X4.0 Y0.75

Z1.0

G00 X0.0 Y0.0 Z1.0 (take the bit 1 inch above board

M05 (turn off spindle

M02 (stop

M30 (end

## Step 10: Test the Design

To test the design, run it through a CNC simulator. The one I used is for the Davinci CNC machines it is called Preview 2.0 but I can't find anything else about it and it may not work well for your machine. Any preview program should work. A nice free previewer is called CncSimulator, it shows the cnc machine and the bit in a 3d model, you can past the code straight into the code panel or code in the program. Read This Tutorial to get the most out of CncSimulator.

## Step 11: Machining the Design

Now that the design is tested it is time to machine it.

The basic idea of machining it is to open the program for the CNC machine that is on the computer. In the program should be a jog option so that the center of the bit can be placed on the corner of the board. This project doesn't need very tight tolerance so we don't need centering tools just eye ball where the corner is. Center the point to (0, 0, 0).

You should do a test run above the board before cutting into it. in a normal run we start with the bit an inch off the board, it is in the example code. However, for the test run we will have the machine jog to position z=1.5 from the board. Now the drill should not cut into the board and you can make sure the holes don't go to deep, hit anything, or that you have the axis backwards.

After you're satisfied with the practice run you can jog the bit down .5 inches or recenter it on the corner and jog it up an inch.

Remember to wear safety glasses even if there is a shield and to have a hand on the stop button in case of emergency.

## Step 12: CNC Results

Here is the board finished along with other boards designed with the same process.

next step is to put a small ball bearing in the maze and plexiglass on top so I can give as a birthday present.

## Step 13: Plexiglass

Cutting the plexiglass top can be done with a laser cutter or CNC machine but because there are only 2 lines to cut I will use a Band saw. Trace the board on the corner of the plexiglass then cut it out. Last step is to use some small screws to attach it to the board.

## Share

## Recommendations

We have a **be nice** policy.

Please be positive and constructive.

## 4 Comments

have you ever tried using masterCAM?

I'm learning featureCAM now.

lots of great info here! does this apply to other cnc machines besindes the davinci?

Mostly. Different companies use a little different syntax and some are more picky then others but this should do the trick on most of the machines. For example I included 2 different codes for inches so if one doesn't work the other should.

G70 or G71 = inches or metric on older machines

G20 or G21 = inches or metric on newer machines