I'm looking to adapt a spindle motor to my 3D printer but I'm not

I’m looking to adapt a spindle motor to my 3D printer but I’m not sure how to turn the spindle motor on. I would like to have the spindle motor connected to a relay which would be activated by my ramps 1.4 board and then have Gcode turn the spindle on and off. Can anyone assist me. Where would I connect the relay to on the ramps board, 5V would be ideal but I could also work with 12V, and what Gcode would turn it on and off (I’m running the latest version of Marlin). TIA

I don’t know if anyone has put spindle operation code into Marlin. You could even use an SSR from a PWM pin to control spindle speed.

How would the PWM pin be turned on. Would I use a Fan gcode to turn it on and off

Then connect to a configured fan pin and enter the command to turn it on. The code for turning on a fan is at http://reprap.org’s g code page, I don’t remember it off hand.

You can use M42 to pull unused pins high or low, or even output a PWM signal on capable pins. M42 P23 S255 sets pin 23 to 5V, M42 P23 S0 sets it to 0V. Then, just use a relay board (with optocouplers) to turn the spindle on and off.

Thanks @Thomas_Sanladerer That’s exactly what I was looking for.

@Thomas_Sanladerer
WOW! I’m not looking to add a spindle, but M43 opens up a TON or possibilities!

@Carlton_Dodd *M42
I use it to control a WRGB LED strip to light up in specific colors during the different phased of a print. And for extra fans connected on the same transistor expansion board.

@Thomas_Sanladerer
RGB lights are just one of my maniacal plans!
Thanks again!