Homing and Limit Switches

Homing and Homing Electronics

So the machine is now up and running, and ready to make some shavings. There are still a few things you need to know about machine operation. You need to learn about homing and what the purpose of it is, and you need to know a bit about co-ordinate work systems.


Homing is an automated process that returns your machine to a known position, hopefully repeatable and accurate. I find it indispensable for getting your machine into a known state. Homing requires a bit of hardware added to your machine, namely homing switches or sensors. If you have limit switches installed on your machine, you can simply use those. If you do not have limit switches, you will need to add homing switches and enable the homing cycle in GRBL settings. Programs like GRBL Panel will show a homing button if the homing function is enabled.

Most CNC’ers, including the OpenBuilds crowd, use the front left corner of the machine as the home point. The homing switches are set to bring the Y Axis full forward, The X Axis full left, and the Z Axis to full height. This is X and Y axes to their full negative value, and the Z axis to its full positive value. Thus, all work will be in a positive direction for both the X and Y axes. Most CAM programs for gantry type CNC’s work this way.

Some CNC users set their homing point at the right rear of the machine, and all work is in the negative X and Y planes. This is less common, but it’s out there. You can find any number of arguments on the forums about which is best. Users of large CNC milling machines typically also use a different format. Ultimately it depends on your CAM program and how it lays out the work space. I typically use SketchUp and Sketch-U-Cam, which defaults to the lower left corner as zero. Of course, when you do your toolpath generations, typically the CAM program will let you put your Zero Reference Point anywhere you want.

In any case, you need to set the machine up to home properly to the selected homing position. When the machine is first powered up, it loads the machine position from the GRBL Settings X, Y, and Z Max Travel parameters (the last 3 settings in the GRBL Setup Menu) into the Machine position register. Actually, it subtracts the Homing Offset from these values before loading. I don’t know why it does this, it’s kind of annoying. The Machine Position is usually displayed somewhere in whatever G-Code sender program you use. I typically use GRBL Panel; it seems to be pretty robust and is made to work with GRBL Arduino code. In GRBL Panel, the small numbers below the X, Y, and Z position bars on the upper left of the main screen Work tab are the Machine position, as well as being displayed in the Offsets Tab. GRBL panel may also load this information into the G54 fields.  With the machine powered up, make sure all your axes are working and going in the right direction using the jog buttons

  • Y + is to the rear, Y- is to the front
  • X + is to the right, X – is to the left
  • Z + is up, Z – is down

Manually move the carriages to their home positions using the jog buttons, and check to see that the homing sensors LED’s light up before the machine hits the bumpers. Adjust either the bumpers or the proximity sensors as needed until they work right. Adjust all the axes away from home for the next step (if they are already at home position, nothing will happen)

Press the Home Cycle key on the GP main page. The machine should home and stop in the front left corner with the Z axis fully raised. If it does not, check your homing switches and adjust if necessary.  Now you need to zero the X , Y and Z axes positions and the machine position displays. This is most easily accomplished by simply disconnecting GRBL panel from the machine and reconnecting. GRBL will automatically zero the machine position and all axis indicators when this is done.  Just hit the Disconnect button in the GRBL box (top center where the COM port setup is). The button then changes to Connect, press it again.  You can also use your Estop button to accomplish the same thing.

Now you should have all zeros in your position display.  This is good; your machine is now fully zeroed.  Don’t move your machine yet! I like to set G28, or Special Position 1 to this zero point for later. If something were to happen, I can always return to the home position without doing a home cycle. To do this:

Go to the Settings Tab.  About the center of the page, at the bottom, you will see Machine Locations G28 and G30.  Press the Set button beside the G28 value.   You should see the current position (0,0,0) in the G28 display.  You have now set G28 to your Home position

You can also set the G30 position using the same steps as above, but pressing Set beside the G30 location instead. Follow the instructions above, but set this position to the G30 key instead. You can use G30 to be any important position on the table. I usually use this to move the carriage to the back of the machine so I can easily position the work on the table without the gantry being in the way. Of course, this is entirely my way of doing things; you have several other options for setting work offsets. This is a whole subject in and of itself, and there are other offsets you can use including G54-G60 which can store work offsets.  Again, Google is your friend if you want to find out more.

Now you can return to the main screen, and press the Special Position 1 button, and your machine should return to the home position. Press Special Position 2, and your machine will return to your other set point. Of course you can set your G28 and G30 points to anywhere on your machine that you find convenient. You can also zero your position anywhere you like and call it your work zero position.

Note that once the workpiece is positioned on the table, you can manually move the machine to the corner of the workpiece and zero out the machine at this point (press disconnect/reconnect). This will zero the machine at the start of your work, and wherever the machine ends up if you press the User Position 1 button the machine will return to this zero point, no matter where it is. This is a very handy function.

Note: Hitting the E-Stop while the machine is running will cause it to get stupid and lose its position information. Run a Home Cycle and set up as above if this happens. You should not have to reset G28 and G30, they are remembered by the Arduino, and once the machine is homed, they will work properly again. Remember to zero the machine position by hitting the disconnect/reconnect buttons immediately after doing a homing cycle.

Installing Homing Switches

I have been using the small electronic proximity sensors for homing switches on machines that I build for quite some time. They are economical, reliable, and work pretty well. They are available from many sources on eBay, Amazon, and others for almost less than what it costs for a micro switch type limit. They do require a bit more wiring than limits, simply because they require a power source to function. Let’s take a look:

This is one of the more common units available, Chinese made and branded Fotek. It has a sensing distance of about 5 mm for steel (hence the -05 in the part number), and a 3 wire connection. This unit is an NPN transistor output, which means it has an NPN transistor which pulls the output line to ground when the sensor is activated. These are available in PNP output as well, which has a PNP transistor which pulls the output to VCC when the output is active. This type is not really useful for our application. The -N suffix on the part number shown on the unit indicates that this is an NPN output type. The PL prefix in the part number indicates that this is a long body type sensor, there are long and short bodied sensors. There is actually only a couple of millimeters difference in length so this is not really important.

These sensors require a power input of 10-30 VDC to operate. Since the Arduino on a CNC machine is 5V, it is not capable of operating these sensors. You might think that you could just hook it up to your 24V motor supply, but there are a couple of problems with this. Typically, stepper driver modules have optically isolated control inputs to maintain isolation from the machine motor power supply and the Arduino. This is a Good Thing, as MS would say. If you used the motor power to run the sensors, you would be compromising this isolation since the ground from the sensors and the ground on the Arduino would have to be connected together. In addition, it may cause noise and ground loop problems if you tied motor ground and Arduino ground together. I don’t recommend doing this no matter how convenient it may seem.

I usually just use a separate 12V wall wart power supply to run the sensors. You can connect the ground from this supply to the Arduino without problems since it is an isolated supply. I have done up a diagram shown below:

There is a lot going on in the diagram that we will talk about now. As you can see, the prox sensors just have their power and ground wires tied together to the incoming 12v supply + and -. This is pretty self-explanatory. Note that the ground from the power supply/sensors is tied to the Arduino board ground as well.

Now we get into the purpose of the components shown on the diagram associated with the prox sensor outputs. The Arduino board digital inputs D9, D10, and D12 have internal pullup resistors to 5v inside the PIC chip. These are the dedicated GRBL inputs for X, Y, and Z Limits respectively. These inputs are also used for the homing function. Unfortunately, these are very high value resistors and make weak pull ups. This means that it is quite easy to induce noise onto these signal lines which can cause false triggering of the digital inputs, and hence either false limit switch alarms or false homing signals. This can be a real pain in a machine, because limit switch alarms cause you to have to reset the processor and then reset the alarm. In the case of the homing switches, it can cause problems with the homing cycle. Since this is not a Good Thing, (thanks Martha) we need to take steps to avoid problems.

It seems for some reason that the Arduino Uno is a bit more immune to this noise than the Arduino Nano. I have increasingly been using Nano’s since they are much smaller, have a cool little screw terminal wiring board that makes wiring a snap, and don’t require enclosures or shields. In either case, I find it prudent to at least put a 0.1uF capacitor from each digital in terminal to ground. This bypasses noise coupling into the digital inputs and vastly improves the noise immunity of the input. You don’t need much of a capacitance to make a drastic improvement. I highly recommend this mod, especially with Nanos. Just solder the caps onto the back of the board and tie the common terminals to ground.

If this does not do the trick, you need to take more drastic measures. This is where the external pullup resistors come in. They are kind of optional, if the caps do the trick for you, you may not need them. If you are still getting false limit alarms, you may have to add additional pullup resistors. I usually use either 4.7K ohm or 2.7K ohm resistors. Smaller value resistors will be more effective, but don’t go lower than 1K or so.

Note that these modifications are just as relevant with plain old microswitch limit switches as they are with the proximity types. Noise can haunt your limit switches just as easily as your prox sensors.

Now we get to the diodes. These are necessary with the prox sensors that I have seen because of a problem with the output NPN transistor in the unit. Normally, this should not be pulled up inside the prox sensor because this means that the NPN output will float at the power supply voltage, which in this case is 12V. Obviously, it is not good for your 5V Arduino to have 12V on its digital input pins, this could destroy the inputs, making the Arduino a paperweight. The manufacturer should not have put these pullups into the device, but they did anyway. It would have worked properly if they had not included this pullup. To avoid problems, it is necessary to add a diode to each input in series with the line from the prox sensor. The diode cathode (the end of the diode with the paint stripe on it) should be towards the sensor. This prevents 12v from the sensor from reaching the Arduino input, but allows the NPN transistor to pull the input low when active. I usually just solder these diodes in series with the lead from the sensor where it goes into the screw terminal on the Arduino. Be sure to put a bit of heat shrink over the diode to prevent shorts.

Just about any diode will work. A 1N400X, where x=1-7, is about the most common. This is just a standard 1A rectifier diode, with a forward drop of about 0.7v. A 1N5819 or equivalent Schottky diode would be better; Schottkys only have a forward voltage drop of about 0.4V, which would help in this circuit. Since the diode only conducts a few mA, a small signal diode like a 1N914 would also work.

Another way to mitigate the noise issue is to use Optocouplers.  These are a small chip with an LED on one side and a phototransistor on the other side.  This allows the chip to pass an on/off signal without any direct electrical connection.  The LED side requires several mA of current to turn on, and thus is almost completely immune to being triggered by noise.  The phototransistor side just acts like a switch.  This is a schematic representation of a limit switch isolator:

This circuit goes in between the limit switches and the Arduino inputs.  Note that the limit switch side has its own power supply connection.  This should be a separate power supply, isolated from the Arduino power.  The supply shown is 5V, but it can just as easily be 12 or even 24V.  This can supply power to electronic proximity switches like the ones shown above.  This board makes a convenient way to interface higher voltage limit switches to the 5V arduino without endangering any components.  The photo below show a completed PCB for this application.  You should be able to hunt these boards down at a place that sells Arduinos and CNC parts.

For homing switch applications, I usually try to standardize mounting of the prox sensors. The Z axis prox is usually mounted on one of the X axis wheel screws, or sometimes on the top of the carriage gantry plate. A screw and tee nut on the Z axis v-slot is usually sufficient for a target. You can see a mounting example here on a Big Ox HD Z axis. I mounted a 2 hole angle bracket on the wheel screw, and then used a limit switch mounting plate from the OB store to mount the prox sensor. Conveniently, the hole pattern on a microswitch is the same distance apart as the mounting holes on the prox sensor, so the limit switch plate is a convenient way to mount the prox sensor.

These proximity sensors, although they say they have a sensing distance of 5mm, this applies only to steel targets. If you use aluminum targets, their sensing distance is only about 2mm. This is not a big deal; they will still reliably detect an aluminum object, the just have to be mounted closer.

Below is shown a mounting for the X axis. You can see I put an 2 hole angle bracket on one of the screws on the side of the gantry plate, and then put a 1/8″ aluminum spacer to lift up the prox senor to clear the top of the gantry plate. I also bent the limit switch mount a bit to angle the sensor down. It just picks up the edge of the X axis plate when it gets close to the end of its travel at X- or the left side of the gantry. This shows the switch mounting, and also shows the gantry being detected.

For the Y axis, I again put an angle bracket on the front wheel screw on the gantry plate. The prox sensor goes on a limit switch mount, and faces forward. I then put another angle bracket on the side of the 20×80 rail to act as a target. Spacers are used to get everything to line up. Couple of notes here, if you want a bit more sensing distance, you can put a screw and tee nut in the target angle bracket, the steel will increase distance. I also like to put a piece of heat shrink over the angle bracket target, its a real ripper if you accidentally scrape your arm or hand on the sharp edge sticking out.

Of course, your machine may have different gantries, different construction, and different spots to conveniently mount the sensors. Also, all of these principles also apply to mounting microswitch type homing sensors, but they do not need diodes.

Limit switches are just mounted at the opposite ends of the axes, so each axis has a pair of switches, one at each end. The switches for each axis are wired in parallel and connected to a single Arduino input.

There are specific settings in the GRBL Settings page for your machine to enable both homing switches and Limit switches. There are a couple of other settings associated with these that define how the Limit and Homing switches function. See the Blog Entry on GRBL settings for more information.

Once all the switches are installed and tested, you need to calibrate them. The best way to do this is to manually move the gantry until it is just about to touch the end stop bumper. Then adjust the switch until it just activates at this position. That should be all there is to it. Repeat this for all 3 axes. Double check that the switches activate before the gantry hits the bumper. If it does hit the bumper, it may cause the gantry to bounce back and not activate the sensor properly.

There are other types of sensors that can be used for homing/limit switches as well. I have seen Hall Effect logic sensors used, which will sense small magnets mounted on the moving parts. These seem to work well. Of course, the old standby microswitch works for this application too.

It is also possible to make the electronic homing switches do double duty as limit switches as well.  This requires that the switches be mounted in such a way as to be able to sense a target at both extremes of axis travel.  With the Z, this is easy, just put two screw targets on the axis, one at the top and one on the bottom.

For the X axis, the switch needs to be mounted on the back facing the aluminum extrusion, so it can sense screws and tee nuts put into the v-slot at either end of the axis travel.  Similarly, this can be done in the same way to the Y axis.  In this way, you can make 3 sensors do the work of 6.

Leave a Comment