Mach3 – Relay Control for Pumps and Dust Extraction

In this post I am going to explain how I added a relay to control the power supply for the coolant pumps and dust extractor and made them switch on and off in GCODE. The process is very similar to controlling the laser module which i did in an earlier post.

WARNING – In this post there is some work with mains AC is extremely dangerous. Improper workmanship may cause damage to appliances, fire or death. In New Zealand, it is legal to do DIY electrical work in the home (by the owner), but strongly advised against. See:
Colour coding of wires for flexible cords The colour coding of the wires for NEW flexible cords will be: Brown = Active (Phase), symbol A, P or L Blue = Neutral, symbol N Green/yellow = Earth, symbol E


Never work on mains live circuits. Insulate properly. Test thoroughly. If any doubt, DONT DO IT


I used a heavy duty cord of a burnt out shop vacuum and fed the cord into the side of a standard GPO riser and switch GPO combo faceplate. I also ran a length of 4 core alarm cable from the CNC control box into the riser. Inside, I wired in a relay purchased from Jaycar.



The relay was wired into the power circuit on the CNC controller and the signal pin wired back to the controller board on pin 14.



In mach3, the output needs to be mapped to the correct pin. On this board the relay is activated by Pin 14.  


Mach3 has VBA support. This allows the user to write scripts and save them as macros. Macros can be called from GCODE by saving the macro as an “M##” file in the Mach3\macros\Mach3Mill directory.

Scripting is extremely powerful and useful. I found this video really helpful getting started:

In a script filename: m311.m1s

‘This script enables a relay to be switched ON by calling M311 in the GCODE file. 
‘’Output3’ must be mapped to ‘pin 14’  ActivateSignal(Output3)

In a script filename: m312.m1s

‘This script enables a relay to be switched OFF by calling M312 in the GCODE file.
‘’Output3’ must be mapped to ‘pin 14’ 


Thoroughly test the circuit making sure the circuit behaves as expected WITH NO MAINS POWER. The circuit should break and reconnect as the relay is toggled. Make sure that the pins of the male connector have continuity with the sockets on the female faceplate. Make sure the active is open (as this should be the case when the relay is off).

Use an RCD device in line with the supply of electricity when going for the first live test.


In Mach3, GCODE can be sent directly to the machine manually by using the “MDI” tab (Manual Data Input)

We can enter the “M311” and “M312” codes here to test the relay. To demonstrate the relay is switching on and off coresponding to the input, I have plugged in a lamp as a visual indicator.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s