Homing and limit switches
Posted: Mon 04 Jun 2018 01:50
Some of the most common questions I get are about connecting limit switches to an Arduino running GRBL, with a GAUPS or similar shield that does not have support for limit switches.
First, to clarify the terms, a homing switch helps get the machine to a known position at startup. The machine does not have any position sensing, so it executes a homing cycle, moving slowly until it presses a switch on each axis. These switches are located at known positions, often at the end of travel in the positive direction of each axis (by convention, this is the right-hand side of the X axis, the rear side of the Y axis, and the top of the Z axis). After homing is done, homing switches don't do anything anymore.
A limit switch detects when the machine accidentally overshoots the end of travel on an axis. This should never happen. The controller may not be able to stop the machine before it hits the hard stop, but at least it knows that something went wrong and that the position of the machine is no longer known, and it prevents it from continuing the job (and causing more damage).
With most small machines, one limit switch on each axis doubles as a homing switch. The switches are used as homing switches during a homing cycle, and as limit switches at all other times. To keep things simple, I will refer to them as limit switches from now on.
If you are using these microswitches, the pin functions are marked on the body of the swtich. C is common, NO is normally open, and NC is normally closed. When not pressed, the switch connects C to NC. When pressed, it connects C to NO. Note that all microswitches of this type have the contacts in the same order, and the common contact is the one on the same side as the plunger. Here's how a microswitch works, if you're curious.
The GRBL documentation used to recommend NO (normally-open) switches connected between ground and the respective Arduino pin (D9, D10 and D12); it now shows a few other ideas, and I'll get to them too. Note that ground means the GND terminal on the Arduino, not an earth ground connection.
If you have switches at both ends of an axis, simply connect them in parallel, so that when either is pressed, the Arduino input pin is connected to ground and reads low. Like this (showing only one of the three axes):
When neither switch is pressed, the input pin is not connected to anything* except a resistor (called a pull-up resistor, built into the Arduino) tied to the positive logic supply voltage**, making it read high (hence the name, pull-up).
This simple configuration works for many people. However, some report that GRBL detects false triggering of limit switches, or that the homing cycle sometimes fails. The false signals happen either randomly, or can be traced to devices that generate electromagnetic interference (spindles, vacuum cleaners, refrigerator compressors, or even lights), especially when they turn on or off. There are many ways for electrical noise to make its way to the input pins of the Arduino, but long wires in proximity to noisy devices (spindle, motors) certainly don't help, and neither do noisy power supply circuits.
I am one of the lucky people who experience plenty of spurious limit switch alarms and failed homing cycles when using the simple method, so I took advantage of that and tested several different ways of solving the problem. I'll talk about them in the next few posts, and rate them for complexity and effectiveness.
_____________
* not connected to anything, except a long wire acting as a nice antenna for receiving all sorts of interference.
** logic supply voltage is +5 V in the case of an Arduino Uno or Mega, but some other models (Due, Zero) use +3.3 V. You'll also see this voltage referred to as VCC or VDD in schematics. All non-ancient Arduino boards also have a pin named IOREF, which is connected to the correct voltage for that type of Arduino (+5 V or +3.3 V). It's best to always use this IOREF pin.
First, to clarify the terms, a homing switch helps get the machine to a known position at startup. The machine does not have any position sensing, so it executes a homing cycle, moving slowly until it presses a switch on each axis. These switches are located at known positions, often at the end of travel in the positive direction of each axis (by convention, this is the right-hand side of the X axis, the rear side of the Y axis, and the top of the Z axis). After homing is done, homing switches don't do anything anymore.
A limit switch detects when the machine accidentally overshoots the end of travel on an axis. This should never happen. The controller may not be able to stop the machine before it hits the hard stop, but at least it knows that something went wrong and that the position of the machine is no longer known, and it prevents it from continuing the job (and causing more damage).
With most small machines, one limit switch on each axis doubles as a homing switch. The switches are used as homing switches during a homing cycle, and as limit switches at all other times. To keep things simple, I will refer to them as limit switches from now on.
If you are using these microswitches, the pin functions are marked on the body of the swtich. C is common, NO is normally open, and NC is normally closed. When not pressed, the switch connects C to NC. When pressed, it connects C to NO. Note that all microswitches of this type have the contacts in the same order, and the common contact is the one on the same side as the plunger. Here's how a microswitch works, if you're curious.
The GRBL documentation used to recommend NO (normally-open) switches connected between ground and the respective Arduino pin (D9, D10 and D12); it now shows a few other ideas, and I'll get to them too. Note that ground means the GND terminal on the Arduino, not an earth ground connection.
If you have switches at both ends of an axis, simply connect them in parallel, so that when either is pressed, the Arduino input pin is connected to ground and reads low. Like this (showing only one of the three axes):
When neither switch is pressed, the input pin is not connected to anything* except a resistor (called a pull-up resistor, built into the Arduino) tied to the positive logic supply voltage**, making it read high (hence the name, pull-up).
This simple configuration works for many people. However, some report that GRBL detects false triggering of limit switches, or that the homing cycle sometimes fails. The false signals happen either randomly, or can be traced to devices that generate electromagnetic interference (spindles, vacuum cleaners, refrigerator compressors, or even lights), especially when they turn on or off. There are many ways for electrical noise to make its way to the input pins of the Arduino, but long wires in proximity to noisy devices (spindle, motors) certainly don't help, and neither do noisy power supply circuits.
I am one of the lucky people who experience plenty of spurious limit switch alarms and failed homing cycles when using the simple method, so I took advantage of that and tested several different ways of solving the problem. I'll talk about them in the next few posts, and rate them for complexity and effectiveness.
_____________
* not connected to anything, except a long wire acting as a nice antenna for receiving all sorts of interference.
** logic supply voltage is +5 V in the case of an Arduino Uno or Mega, but some other models (Due, Zero) use +3.3 V. You'll also see this voltage referred to as VCC or VDD in schematics. All non-ancient Arduino boards also have a pin named IOREF, which is connected to the correct voltage for that type of Arduino (+5 V or +3.3 V). It's best to always use this IOREF pin.