Limit Switch De-Bouncing Circuit?

I want to have a pair of simple 3-pin limit switches that connect to my Teensy 4.0, that would be used in conjunction with a stepper motor assembly, to detect when the stepper motor reaches a certain angle and prevent it from rotating further than desired.

The limit switch would be only used for triggering a flag upon the stepper motor shaft extension hitting it. Someone recently mentioned the fact that a de-bouncing circuit would be required for limit switches to operate properly. As far as I understand, when a limit switch is pressed, for a brief amount of time the switch may alternate between it's digital readings, allegedly resulting in incorrect readings.

However, there are certain forum posts online in which people mention that a de-bouncing circuit is in fact not needed when working with simple limit switches for applications such as these. There are also many limit switch tutorials for Arduino that do not mention any de-bouncing circuitry at all.

Is my understanding of the requirements for a de-bouncing circuit when working with limit switches correct? Does my requirement for the limit switch require a de-bouncing circuit? Is there a specific example of de-bouncing circuit that my limit switches would work best with?

Thank you for reading my post, any guidance is appreciated.

Limit switches do not deserve any debouncing. On the first contact the limit is reached and the motor should be stopped.

2 Likes

Maybe it adds confusion.... For highest safety such limit switches should be connected in such a way that the switch allows motion when not mechanically activated. When the swich brakes the circuit, it means "stop". That way a broken limit switch cable will make the logic stopping the movement.
That's the standard in industrial machines.

2 Likes

But you still need to be sure that the release of the 1st "bounce" doesn't then set the motor going again...

Stop means Stop, no reason to run in the same direction any more.

If the limit switch disables motor power directly then another µC controlled relay may break power definitely on the first contact, if a bouncing limit switch seems to cause problems.

Limit switches should be used "normally closed". The motor should stop on opening of the switch, also for added safety. Then bouncing also becomes less important.
Leo..

1 Like

That is true, but don't forget that "bouncing" also occurs when the switch is opened (un-pressed).
However, if your code is properly structured, de-bouncing in a limit switch application is not necessary.

@Railroader's suggestion is probably the safest solution since there is only one point of failure, the limit switch.

For accurate positioning, you move the stepper to the limit until the switch opens,
then slowly step back until the switch just closes again. If you do that with a step rate slower than debounce time, there is no bouncing problem.
Leo..

Hi, @Svarun123

Experiment, build a test jig and test some code.

Get out in the real world and try it!!

Tom... :smiley: :+1: :coffee: :australia:

That is a genuinelly good suggestion that I have not considered. Thank you for sharing, I'll make sure to wire up my switches in such a fashion.

So does a "properly-structured" code in this context entail setting up appropriate delays after each reading of the switch status, in order to ensure that the bouncing is over? As far as I understand, the "bouncing" of a switch occurs when, for a very brief period of time, the connection point inside the switch is very close to being connected, and the electricity arcs a little between the two points (feel free to correct me if my understanding is incorrect).

Debounce is not needed as you'll not care after the leading edge trigger. Your sw will either stop immediately, or will reverse off the sw. Either way, bounce is a non-issue.

2 Likes

One thing you can do is put a 1 uF cap across the switch. It will eat bounce.
Nick Gammon on contact switches.

But you can sense bounce-free using light, capacitance, magnetism and sound. With a piezo disk, you can tell about how hard it hit and when it lets up, release or not. Piezo disks are freaking cool! Think of a capacitor that you can charge by squeezing!

So?

1 Like

Thanks for showing me this website, this is a great source for limit switches. Virtually all information about them is presented on that site.

I have one more clarification I want to ask about;

On that website, the author presents the following de-bounce circuit schematic:

Does the exact placement of the capacitor matter here, in relation to the switch? Can the capacitor be positioned in front of the switch, instead of behind it? My intution would tell me that the positioning does not matter, but I want to be sure.

Write limit switch code that doesn't care if the switch bounces.
Don't create a problem if you don't have one.
Leo..

That's what that website that @GoForSmoke linked goes into detail about. It covers both software and hardware de-bounces, hence why I marked it as the solution. I was just asking because I was curious.

Exactly. In a design 2 buttons starts a several seconds long activity, go forward resp. go backward. By the time the triggered motion is finished, bounces are dead since long.

DO NOT place a capacitor across the switch.

Contrary to popular belief, putting a capacitor across a switch does not provide de-bouncing, it will only damage the switch contacts and the arduino I/O.

Limit switches DO NOT NEED de-bouncing.

2 Likes

While I agree that limit switches do not needing debouncing.

I would be very interested in hearing how a capacitor is damaging my I/O. This is the first I've ever heard that.

Not what I was trying to say.
I meant that if you write the stepper code correctly,
then you don't need hardware debounce or software debounce code.
Leo..

3 Likes