CNC limit switches and opto couplers

CNC limit switch operated by machine view 2

CNC limit switches

Once I’d been using the machine for a while it became apparent that limit switches were going to be needed before I wrecked my CNC machine. Initially I thought I’d be able to just “be careful” and make sure I didn’t run the machine too far to the ends but it just didn’t work out like that and after several mishaps I gave in and fitted limit switches.

If you think you’ll be fine without them like I thought, you won’t! Believe me and just fit them before you damage your machine.

Here are a few of the examples of things that I got wrong.

I set the machine to jog 1mm while moving the Z axis moving the router up and down to be careful.

I then had to move the CNC machines Y axis back to get the router out of the way to fit the clamps so set it to jog 100mm instead of 1mm. I forgot to set it back to 1mm when moving it down so it went hurtling down into the table causing lots of damage! Incidentally I now use a different software package where you can set the jogging to different amounts on different axis. I have a page specifically for CNC software here if you need more information.

I moved the Y axis all the way to the back to get it out the way while doing some material adjustments, then pressed the wrong key on the laptop and it went even further back pushing the whole back off ripping, some wiring off as well for good measure.

Pressing the page up instead of page down and getting another major machine crash!

You get it, I should have fitted the switches earlier so my advice is as soon as you can fit the limit switches.

For me using the Arduino Uno board I wired three micro switches in for the x y and z axis. Some people use 6 switches but I thought I’d try the three switch method and if it wasn’t suitable I’d put the other three in. Basically you just put a switch at the end of each travel.

That’s as far as the X, Y and Z axis will go before hitting anything so you’ll need to experiment a bit to find suitable places to fit them.

CNC limit switch operated by machine side

Some people have fitted a micro switch on each end of axis travel so one to stop the front and one for the back, one for left and one for right and the same for up and down. Using three micro switches you just put one at each end of an axis so for instance for me that’s one micro switch positioned to switch when the CNC machines moves to the front, one positioned for the CNC machines left movement and one positioned for the routers highest or up position. In the GRBL software you set the CNC machine to move to where the switches are when you home the machine.

There’s an article article on machine homing here.

So you can get it to move forward and left and up till it switches the micro switches and then the set the machines largest movements so if you manually or through a G code program try to move it too far you cant. It’s all worked for me with no problems using just 3 micro switches so I’ve never used the 6 micro switch methods.

CNC microswitch mounting

Opto couplers or opto isolators for CNC machines

When I say no problems I mean no problems with the machine crashing into itself and causing massive damage that I used to be able to do regularly before the micro switches were installed.

There were problems with the micro switches, you might already have heard about this if you’ve looked at other CNC machine builds.

Hers the problem and solution that I used

Basically the micro switches are mounted quite some distance away from the Arduino Uno board that they connect to. They have to be as the bigger the machine the further the switches will be from each other and hence the Arduino Uno.

To simplify the explanation the stepper motors cause interference that gets picked up in the micro switch wires causing false triggering when the machine is running. Depending on how you’ve wired the switches the Arduino PCB inputs either get 0v or 5v to alter them between a high and low state.

There are some wiring configurations with a capacitor and resistor on each input to minimise the false triggering, some designs also say to use screened cables to stop the interface being picked up.

I did experiment with this and the screened cables and capacitors and resistors did make a difference but in the end I went for a different idea which made the wiring easier and more reliable in my opinion.

As you may have guessed I have more of an electronic background than mechanical, when it comes to building a CNC machine you need both!

So how did my electronic background help? Well in the understanding and being able to find something suitable on eBay. If you’ve got some electronic knowledge which I guess you must have or you going to struggle to build a CNC machine.

There are a few examples of CNC machines that have got around the problem by using opto isolators. An opto isolator is a small electronic device that has an internal LED that lights and a photo transistor type device that alters depending on if there’s light or not.

In a simple explanation the micro switch wires act as little aerials for interference caused by motors and switching and we’ve got lots going on in our CNC machines. If you put an opto isolator close to the Arduino Uno PCB and then run the long wires to the micro switches you don’t get any interference getting through.

CNC-micro-switch-opto-isolator

This is because although the long micro switch wires still pick up interference causing voltage spikes, the voltage spikes don’t have enough current to light the LED in the opto isolator so it effectively filters out the spikes causing the false triggering.

You can also get these problems with the probe as it’s very similar to the micro switches picking up interference signals, and so does the wiring to the probe.

Luckily I was able to find some opto isolator boards on Amazon, the one I found had 4 opto isolators so was perfect. It was also small and cheap and it was just a case of wiring the outputs of the opto isolators to the correct inputs on the Arduino Uno PCB and then wiring the inputs to the three micro switches and probe. It’s a lot neater than trying to wire a capacitor, resistor and associated wiring on each input and more importantly has worked perfectly since I started using it.