Limit Switch for "Z" in arduino program

Hi
I would like to add a limit switches and emergency stop to my machine.

  1. “Z” Limit to pause G-code run. For safety of equipment like accidental set G-code to over run distance supposed to be 10 but entered 100. So it makes a mechanical contact Switch. to tell machine, so I can make corrections without damage. Z to stop up or down, and turn off spindle.
  2. X-Y Limit. to pause G-code run. I will place a bump in one of the links on the chain so I can physically set the limit, Then a roller switch could open contact.
  3. E-stop, Emergency stop all, also for power outage will not restart by itself. magnetic relay and reset. so equipment will not restart without control.

The limit switches will be normally closed. each axis X,Y will need 1 pin each, Z will need 2 pinsa total of 4 pins.

So I need Arduino programing and what digital pins are available for control.

Arduino Mega 2560 Rev3
Driver Board v1.2b

Please Help
Thanks
James

Right now the limits are all in software. We have a mega version of firmware currently in testing that has user settable soft limits that will stop the z axis at a preselected position that you define from webcontrol (also a beta version).

The spindle start/stop is AUX 1 on your shield and functions with M3 / M5 gcode for ON/OFF. (I think I have a 1.2b shield and it doesn’t have any aux pins broken out, so you will either need a stacking shield to break out more pins, or solder on your mega on the back side (I like network cable thin strand wires for that type of work
I believe some boards have up to 7 aux inputs available, but I don’t believe the firmware operates end switch limits in code, so you will need to develop that code base to do what you want.

You can get an e-stop mushroom from amazon and wire it to your arduino power supply output using a simple 12V relay from amazon or aliexpress. From your 12V motor power supply output, go to the emergency switch, then split and go to the reset switch and then to normally open relay side. Continue from the reset switch to the coil and from the coil to the relay center pole. From the relay center pole, connect back to the arduino motor shield. When power is cut, the relay will turn off and not turn back on until the reset button is pressed.
If EPO is pressed, relay will trip and EPO must be pulled back out and reset pressed to latch relay on.
Power to the motors will stop any movment, but allow the arduino to stay on. When the encoders stop moving, the system will error with sled not keeping up error and stop. It will not pause. It will cancel the job. I’ve drawn a really poor quality diagram real fast…


that will stop all movement except the spindle. IF you get a double pole double throw relay, you can switch your router power with the other pole.

1 Like

Thankyou for the info.

I wonder if I could add another control board like an arduino uno then pulse one pin on the board for limit switch.

James

I feel long winded, so here is some free information. Feel free to discard whatever you like from it.

Theoretically you could do that with the uno, but the mega just a more powerful uno. If know how to code an uno, you can code the mega. It is just more code to follow, so a bit more complex, but the same language.

Once calibrated, the arduino mega has all the limits internally except the z axis which is in testing and can be included. Since the maslow does not home itself each time you turn it on like a stepper-driven 3D printer, limit switches are not really very helpful except when things go really south. Responsible CNC users observe their systems and don’t let them run wild without supervision (like some children in the walmart). I wired a set of light switches with romex on my frame, so if anything goes wonky, I turn it off. There is an outlet at the bottom center of the back of the frame for my router to plug in and it is switched by one of the light switches and it runs through a relay toggled by AUX1. My dust collector goes through an outlet switched by another light switch, and the electronics go through a third one. I also have big red emergency off switches on each side of the system to cut everything, but I really never use them and often use the pause or stop button on my controller instead of killing power. It has never run off the work space. It has limited out on the z axis from a fat finger or a loose set screw error and it has halted itself with a sled-not-keeping-up error when the router power cord caught on a cutout and the sled stopped moving. It worked and stopped like it was supposed to.

3D printers have limit switches as a way of ensuring positional accuracy. The Maslow has encoders on each motor to keep track and those values are stored in the eeprom on board. As long as you don’t yank power from the mega during a move, you won’t need to mess with it unless you do jump a chain tooth (put sprockets at 12:00 and reset chains), which can happen, though its occurance is rare. It may actually be easier to mess up the gcode by using incorrect post processor settings than the hardware.

The M2 folks with the DUE processors are the ones who probably need the limit switches because their firmware doesn’t have a sled-not-keeping-up error. You tell it to move and it will move.
If it doesn’t move because of no power to the shield, it will wait until you plug the shield in and then it will move like hours later unless you reset it (I tested this).

For some of the hating on the Mega, they are actually a pretty stable and reliable platform. The users of the DUE have had some mixed results thus far. I don’t know the statistics because the forum usually only gets wind of something if there is a problem. There have been a few errant sleds possibly due to incompatible firmware/makerverse versions (most all were M2 versions that ripped the ring apart), but if you are using a Mega and webcontrol, your chances of runaway sled are very very slim (make sure your gcode doesn’t use the R command) and that you have the correct firmware for your board version.

limit switches on the Z to keep you from hitting the limits of the machine are
not a bad idea. The Z position that is tracked is the position of the end of the
bit, the maslow has no idea how much is sticking out, so it really doesn’t have
a way of knowing if you are near the mechanical limits of the system.

David Lang