Hello,
I want to use a limit switch with my Arduino uno. I connected it through an cnc shield at pin 12 to the Arduino. I use the C an NC pin at the limit switch. Now the problem: The switch only works if I touch or come close the the isolated cable which is used for the signal. I added a restistor (10kΩ) but that doesn´t work. Here is my code:
Just a reminder of what others have said about limit switches: You want to use a pull-up resistor on the input pin and connect the switch using the C (common) and the NC (normally closed ) terminals to pull down. That way, when you poll the input pin, it should normally read LOW. If it reads HIGH there is a fault condition. Either the switch is activated or one of its wires has been severed.
Assuming you're using the NC terminal for input, then:
Assuming the switch common is connected to GND, you could keep the 10K series resistor as it will provide some input protection against any voltage spikes that may occur from the cable. I suggest adding a 1K pullup resistor to 5V at the switch end of the series resistor. This should provide enough wetting current for the microswitch. In this scenario, there will be about 5mA continuous current drain until the microswitch opens.
Assuming the switch common is connected to 5V, you could keep the 10K series resistor as it will provide some input protection against any voltage spikes that may occur from the cable. I suggest adding a 1K pulldown resistor to GND at the switch end of the series resistor. This should provide enough wetting current for the microswitch. In this scenario, there will also be about 5mA continuous current drain until the microswitch opens.