Maker Pro
Maker Pro

Why I need a capacitor in parallel to micro limit switch

dashy1981

Jun 19, 2013
83
Joined
Jun 19, 2013
Messages
83
Hi All,

My circuit has two limit switches wired to Arduino's two digital pins which are pulled high through internal pullups.

One of the limit switch always worked while the other one did not.

I must mention, that both are at different locations.
For Limit Switch 1 : two way wire is about 4 meters.
For Limit Switch 2 : two way wire is about 6 meters.

Its the limit switch 2 which was not working. Although when checked manually with multimeter in continuity mode, I could see that switch2 works fine.

Thinking of some prob with longer length having more resistance and drop across the switch 2 wire, which might be causing logic level issues for arduino, I decided to put a 0.47uF capacitor across second switch. Voila, this worked, now arduino detects it correctly.

My question is, am I correct in my analysis and its the voltage drop across the wire is the culprit ?
How does a capacitor solves this ?

Cheers
 

Bluejets

Oct 5, 2014
6,065
Joined
Oct 5, 2014
Messages
6,065
Doubt very much that "voltage drop" has anything to do with the problem.

Show your code and your circuit diagram.

Long runs that are external to the uC and pick up noise etc. can be modded using opto's.
 

crutschow

May 7, 2021
550
Joined
May 7, 2021
Messages
550
A capacitor across switch contacts can lead to pitting and welding of the contacts due to the large instantaneous capacitor discharge current when the contacts close.
It acts like a small-scale spot welder.
 

dashy1981

Jun 19, 2013
83
Joined
Jun 19, 2013
Messages
83
Doubt very much that "voltage drop" has anything to do with the problem.

Show your code and your circuit diagram.

Long runs that are external to the uC and pick up noise etc. can be modded using opto's.
Ckt dia is difficult to reproduce as it's Arduino with grbl shield. But point is that if I reduce the length of wire it works well with software debouncing... I don't doubt well tested grbl code.
Only when distance of the switch is increased then it does not detect state change.

My query is why is it working with a small cap placed across switch. My assumption in putting the cap was to keep the default voltage stable high through cap and when switch closes cap discharges and pin reads low.

Is there any other explanation for it is what I am looking for or a better method ?
 

Bluejets

Oct 5, 2014
6,065
Joined
Oct 5, 2014
Messages
6,065
Already told you...use an opto isolator adjacent to the uC.
 

Martaine2005

May 12, 2015
4,395
Joined
May 12, 2015
Messages
4,395
Try using a heavier gauge wire if 4 meters work and 6 meters doesn’t.
You say ‘two way’. Do you mean two core wire? Which is 4 meters? So a round trip is 8 meters through the switch?

Martin
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
12,883
Joined
Nov 17, 2011
Messages
12,883
An optoisolator as recommended by @Bluejets will give the best protection against noise, overvoltage etc.

If you don't want to use one and also don't want to use a capacitor across the contacts, you can try to improve robustness by using an external pull-up resistor, e.g. 1 kΩ only (compared to 30 k ... 60 k of the internal pull-up in the µC). Lower resistance means more power dissipation when the switch is active, but higher noise immunity as more energy is needed to overcome the pull-up action of the resistor. Place the resistor directly at the Arduino's port connector (not at the switch end of the wire)

If you want to stick with the capacitor, place it next to the Arduino's input, not across the switch. When connected directly at the Arduino side, the capacitor can better filter any noise that's induced in the long wire. The wure's resistance also helps (if only a tad9 to limit the current when the contact is closed, thus reducing the issue with contact wear as indicated by @crutschow .
 
Top