Kill switch too sensitive

I'm building a CNC mill and am trying to set up an emergency kill switch. I have a pushbutton going to D2 and a routine watching it via attachInterrupt(). In case it's relevant, my board is a Duemilanove with a 328 upgraded to OptiBoot.

The pushbutton is connected to the Arduino via about 10" of one twisted pair from an old Cat5 cable. I first tried using the internal pullup but I was getting spurious interrupts whenever the Dremel spindle started or stopped.

Tonight I switched to a physical 10K resistor wired as a pulldown and changed the code to attachInterrupt(0, RISING). That seems to have eliminated 99% of the problems, but I'm still getting an occasional false positive from the switch when the steppers and Dremel are running.

Does anyone have a hardware fix for this? I think I can solve it with a counter inside the interrupt routine (e.g. the kill button must be pressed for 20ms) but learning new things is always good.

Thanks as always.

There are a number of possibilities:

  1. Use a normally-closed pushbutton instead of a normally-open one. The closed switch will prevent capacitive noise pickup in the pushbutton cable. You are already using twisted pair, so you shouldn't be getting any inductive noise pickup in the pushbutton cable. Using a normally closed pushbutton also protects against the pushbutton wiring going open circuit, which is probably more likely then it going short circuit.

  2. Reduce the pullup or pulldown resistor further, to 1K or 470 ohms.

  3. If all else fails, connect a capacitor (1000pF should do) in parallel with the pushbutton.

Thanks dc42. The pushbutton has both NO and NC posts so I'll rewire it NC and invert the code logic. If that doesn't work I'll try #2 and/or #3.

I would call this a "stop button" rather than "emergency button" (or "kill switch"). A kill switch would just cut the power to the cnc. The kill switch should never fail.

I'll second florinc. If you life or health may depend on it, wire the switch so that it physically cuts the power line.

Thank you both for your concern. In this case, it's just a small Dremel CNC mill with a cut area of 8" x 6" and vertical movement of 2.5". The stepper motors drive threaded rod so I have to spin them rapidly to get significant movement, so they don't have much torque. I'm not even sure they would be capable of generating enough sheer force to break the router bit.

You're probably correct the name would be better as "stop" than "kill switch". I have the power supply for the steppers and the Dremel plugged in to a power strip mounted to the front of the mill, so that is probably better described as the true kill switch.

Back to the original problem -- I rewired the button as NC yesterday and that actually made the problem much worse. I'm going to experiment with capacitors and resistors today.

magagna: Back to the original problem -- I rewired the button as NC yesterday and that actually made the problem much worse. I'm going to experiment with capacitors and resistors today.

That suggests to me that there is either a problem with your ground wiring (if you are using an NC pushbutton to ground with a pulldown resistor) or the +5v wiring (if you are using an NC pushbutton to +5v). Or possibly the +5v supply is being affected by motor noise. My recommendation would be an NC pushbutton to ground, but connect the ground side of the pushbutton direct to one of the Arduino ground pins, and use a different ground pin to connect Arduino power and any output devices.

Thanks DC42! I did exactly as you recommended -- rewired with one leg of a NC button to the D2 pin, the other leg to Arduino ground, and using the internal pullup it's been running a test pattern for 15 minutes now with zero issues.

I'm glad my suggestion worked.

I've lost count of the times I've suggested using separate grounds for inputs and power/outputs, although more usually the problem reported by the OP is that analogRead() calls return inconsistent results. The issue here is that a common ground wire has inductance. When the current flowing through that common ground wire changes sharply (perhaps because a motor or a bank of leds are being switched), a voltage is induced across that ground wire, which feeds back to the inputs. In your case it was through the NC pushbuttons, but it can also be fed back through analog sensing devices.

Try shielding the cable to the switch, and ground the shield at ONLY ONE END, preferably the Arduino end. Block the noise so it can't get into the cable. And move the cable away from the power cord to the Dremel motor. Parallel cable WILL pick up strong pulses even if they are twisted pairs.

Thanks guys. I ran the mill for over 4 hours today and had zero errors with the stop button.

DC42 - I've read about it regarding analog ports, but I think because I come from a software background I often forget that at the physical level the zeros and ones are not always perfectly shaped.

Kf2qd - you're right, I think I had the coiled Dremel power cord too close to the logic boards & wires. This seems to have solved an infrequent, but annoying, problem where the system would lock up mid run