Controlling a relay via gcode, ie. for cooling, using M8, M9

Post Reply
Posts: 37
Joined: Tue Sep 29, 2015 8:16 pm

Controlling a relay via gcode, ie. for cooling, using M8, M9

Post by grep » Fri Jan 26, 2018 7:37 pm

Hi all,

I am in the process of hooking up an electrical solenoid valve, in order to blow air on the bit.
I have a 24VDC valve ( ... c-24v.html) and a 2.4 controller board.
The idea is to use M8 and M9 to turn it on and off.

I just asked carbide3d support on which pins i should connect a relay (will post the answer here), and what are the extras steps necessary in order to get it working. Meanwhile, if some of you have done it, you are welcome to add your input in this thread :geek: .

Edit : I was initially planning to use M7 to turn on coolant, but looking up on the grbl wiki, it is disabled by default, might as well use M8.
Last edited by grep on Sat Jan 27, 2018 12:32 am, edited 1 time in total.

Posts: 37
Joined: Tue Sep 29, 2015 8:16 pm

Re: Controlling a relay via gcode, ie. for cooling, using M8

Post by grep » Thu Feb 01, 2018 2:08 am

Here is the info I got from Carbide3D :

Disclaimer : This is for 2.4D board. Hooking up a 3rd party device will void the warranty.
There are no on board relays that would let you hook that up, you'd have to put something together.
There is also no convenient place to grab 24V from the board but I'm attaching a board image for 2 pins you can use. If you need to turn a relay on, you can use the 4 pins next to the limit switches labeled GND, PWM, 5V and D13 (inside the red rectangle in the image)
Also, M7 and M9 commands are not supported in carbide Motion, so if you end up going that route you'd need a different gcode sender, like UGS or bCNC

Friendly PSA, hooking up a third party device to the board will void the warranty
PWM is D11. It sends a square wave for spindle speed. If you use either D13 or D11 you won't be able to use them for spindle ON/OFF.
There is one more place you can grab a signal, A3 inside the red circle. That pin turns on automatically with M7 and M9. A3 is the coolant ON/OFF pin.
You don't need to recompile GRBL to use M7, M8, or M9, you'll just need to use a different gcode sender than Carbide Motion.
I think M7 is deactivated by default, see GRBL documentation. You need to enable it in the config file and re-compile grbl. I prefer to use M8 instead :)
You can definitely flash grbl1.1 onto your board.
Carbide Motion Board Layout, ver. 2.4D
CM_24_silk_led.png (296.8 KiB) Viewed 960 times
With this info in hand, I first started to hook it up this way ( When I would press M8, it would turn ON, when I would press M9, it would turn OFF, and suddenly, repeats that same command over and over until my CPU (or memory) gets saturated and I can't move the mouse and have to shut off manually the computer. Maybe I didn't something wrong, maybe I should have put a flyback diode across the solenoid valve (i put one across the relay coil though).

So instead, I switched to another circuit, I built this one :
Schematic for controlling a DC 24V Solenoid Air Valve on shapeoko
irl.png (28.6 KiB) Viewed 960 times
And it works perfectly for now :) Special thanks to the Cardbide3D support, top notch! ;)
Picture of shapeoko with air cooling
air.jpg (222.49 KiB) Viewed 960 times

Post Reply