M04 G-Code Command

  • 2 mins read

M04 G-Code Command

M04 is a G-code command used in CNC machining to activate the spindle in a counter clockwise rotation. It is used to start the spindle and initiate the cutting process when a counter clockwise rotation is required. This is not very common but it needs to be used with reverse helix tooling for example. Lathes also use this command if a tool is loaded upside down, which can be useful in certain situations.

In a program M04 is followed by a numeric ‘S’ value that specifies the spindle speed in revolutions per minute (RPM). For example, M04 S1000 would set and start the spindle speed to 1000 RPM in a counter clockwise direction.

How M04 G-Code Command Is Used

Here’s an example of how M04 might be used in a CNC program, with comments in brackets:

N10 G20           (Set units to inches)
N20 G54           (Select coordinate system)
N30 M04 S2000     (Start spindle clockwise at 2000 RPM)
N40 G0 X1.0 Y1.0  (Rapid move to position X1.0 Y1.0)
N50 G1 Z-0.5 F10  (Linear move to position Z-0.5 at a feed rate of 10 inches per minute)
N60 G0 X2.0 Y2.0  (Rapid move to position X2.0 Y2.0)
N70 G1 Z-1.0 F20  (Linear move to position Z-1.0 at a feed rate of 20 inches per minute)
N80 M05           (Stop spindle)
N90 G91           (Set incremental mode)
N100 G0 Z0.5      (Rapid move up 0.5 inches)
N110 G90          (Set absolute mode)
N120 M30          (End of program)

In this example, the program starts by setting the units to inches and selecting a coordinate system. Then, the spindle is started in a counter clockwise direction at 2000 RPM using the M04 command. The program then moves the cutting tool to various positions and depths before stopping the spindle with the M05 command. Finally, the program ends with some additional commands. The M03 spindle on command turns on the spindle in a clockwise direction.