Debouncing issues

Hi all,

I'm using a reed switch to measure rotational speed and am trying to debounce the input. The problem that I am encountering is that at low speeds the bouncing is occurring at about 200ms. While at higher speeds the genuine input also occurs around 200ms. So if I set a debounce interval of 200ms then I cut off the high speed input.

Does anyone know of a way to debounce based on previous inputs. Seen as directly preceding a false input the time difference is large. Whereas a genuine high speed input is preceded by another high speed input.

Low speed:
14:32:55.587 -> 2.25 dT / 26.69 RPM
14:32:58.967 -> 3.36 dT / 17.84 RPM
14:32:59.264 -> 0.30 dT / 196.73 RPM
14:33:02.886 -> 3.61 dT / 16.61 RPM

High speed:
09:34:41.115 -> 0.38 dT / 157.86 RPM
09:34:41.368 -> 0.24 dT / 248.67 RPM
09:34:41.664 -> 0.30 dT / 202.06 RPM
09:34:42.072 -> 0.38 dT / 156.53 RPM

Use a Hall sensor instead. It does not require debouncing at all.

As you've not provided any code it is impossible to see if there is an obvious problem with it.
Here is my solution to debouncing, but there are plenty of others: Buttons and other electro-mechanical inputs (introduction)

Also, if you are detecting the speed of a rotating shaft one solution might be to have 2 reed switches at 90 (or so) degrees to each other, and use their output as if from a rotary encoder. There is no need to debounce a rotary encoder provided you deal with the output from it using a state based approach.

I think the second option might be what I'm looking for, that or using a hall effect sensor. The debouncing code I have been using is similar to yours:

void rotation() {
  dT = ((micros() - last_micros)/1e6);
  if(dT >= debouncing_time / 1e3 && dt <= 10) {
    Serial.println(" dT");
    last_micros = micros();

That’s microseconds you have there not milliseconds …. Have another look at your timings , there is a limit to how fast a Reed switch can operate and it won’t bounce for 200mS ! 4mS is more like it ( 4000micro seconds)

Note also that the print statement takes time to process

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.