De-bounce and detect Input pump run-times

Hello, I am using a Nano to detect the duration a 5vdc pump runs. On Port D4 I have a 10K resistor to Ground to pull it down.

When the pump turns on it feeds 5vdc to D4 and I need record that start, then when it turns off, calculate the seconds between and I can kind of do that.

But, I am having trouble with bounce at both turn-on and turn-off.

The Libraries I have tried (Bounce2, InputBounce etc) do not seem to be set up for when the Port is normally LOW.

I tried using a 1uF cap (Nick Gannon) but it seems to make no difference, but I may have it wired wrong.

Can anyone please suggest a Library that will handle "Duration" between LOW-HIGH-LOW states with de-bounce, or provide a pointer to some code snippets for me to try?

I'd rather use software de-bounce as the Nano is already soldered into a system and I can just solder to the top of D4 rather then add in more components.

Not a library but my tutorial on debouncing inputs can deal with change from low to high and high to low. I have included examples for several scenarios, you should be able to adapt one to what you are doing.

Bounce2 should work. You set start time at .rose() and the end time at .fell().

if (input.rose())
  {
    buttonPressStartTimeStamp = millis();
  }

  
  if (input.fell())
  {
    buttonPressDuration = (millis() - buttonPressStartTimeStamp); 
  }

Please post what you tried but "didn't work".

1 Like

My tutorial on Debouncing Switches in Arduino handles high and low normal states

Would just wiring a capacitor to the pin do the trick?

-jim lee

Bounce2 is very flexible and configurable. See its README and source code.

It has several constituent classes that you can inherit from or incorporate into your own classes. This allows you to create just about any functionality you want.

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