Help debouncing input

I was rather hoping you would respond to my description by rewriting it correctly or extending it. The reason for writing it like that is to have a very clear understanding of the process that needs to be dealt with - to get the mental image of the problem onto paper (or a text editor).

Your Reply #19 leads me to think I missed an extremely important part of the problem - that the low-water signal arises even though there is plenty of water in the boiler. In fact my description was plain wrong, because I had assumed the low-water signal only happened when the water really was low. I hope this shows the value of writing it down.

If there is a false low-water signal then your suggested solution seems to be appropriate. You may need to experiment to figure out what sort of wait period is required.

May we assume you know how to code for that wait period?

...R

fancycoconut:
OH I KNOW
What needs to be done is make the pump only turn on if the pin reads low water for more than a second. So i've been thinking about this in the wrong way. I still don't know how to have this happen though. So basically, to rephrase, I need to have the pump turn on if the water is low for more than a second or two.

I can help but I need more info from you. The pump relay should turn on after 1 second of the sensor being low. That's understandable but when does it the pump turn off after it is on. How many sensors do you have? Do you have 2 sensors? One for detecting when water is full and one for detecting when it is low OR do you just have one sensor that detects both?

Robin2:
May we assume you know how to code for that wait period?

...R

I wish I knew :smiley: ! Some help would be much appreciated!

hangemhigh:
I can help but I need more info from you. The pump relay should turn on after 1 second of the sensor being low. That's understandable but when does it the pump turn off after it is on. How many sensors do you have? Do you have 2 sensors? One for detecting when water is full and one for detecting when it is low OR do you just have one sensor that detects both?

The pump should turn off when the water comes in contact with the pin again. There is only one level sensor.

Having only one level sensor will make things difficult.

Imagine the water is cold and perfectly still. When the water rises and triggers the sensor the pump will stop. But as soon as the water level falls by the tiniest amount the sensor will be uncovered and the pump will start again.

There is no method to know when there is either too little or too much water - only when her is the "right" amount.

This leads to the question, what should happen (if the water is still) when the sensor is uncovered. Maybe the pump should run for X seconds?

Supposing that my guess is correct we come to another question
What should happen if the sensor is uncovered by a bubble?

I think from your earlier posts you just want to ignore the bubbles and do nothing until the sensor has been uncovered for Y seconds.

Sorry for labouring through the logic, but if all the little pieces are not clearly understood something will go wrong.

This code should prevent the pump starting unless the sensor is uncovered for some seconds

curMillis = millis();
sensorState = digitalRead(sensorPin);
if (sensorState == LOW) {
   if (prevMillis - curMillis > ignoreBubblesMillis) {
       // start pump
   }
}
else {
  prevMillis = curMillis; 
}

...R

Robin2:
This code should prevent the pump starting unless the sensor is uncovered for some seconds

Robin, thanks for your reply. I was super busy this weekend so I only just now got to try the code. It doesn't work :confused: . With it uploaded, the relay still fires on and off if the state changes quickly. I even tried setting the time to 10 seconds and it didn't help.

fancycoconut:
With it uploaded, the relay still fires on and off if the state changes quickly. I even tried setting the time to 10 seconds and it didn't help.

That probably means there is some silly mistake - remember I had no chance to test it. Look through it carefully.

Post the complete revised program including my suggested code - without that I can only make wild guesses.

...R

Robin2:
Post the complete revised program including my suggested code - without that I can only make wild guesses.
...R

Here ye are!

workinprogress6_with_new_fill.ino (14.2 KB)

I see the line

digitalWrite(inletRelay, HIGH);

all over the place. That seems to make a nonsense of the attempt at timing in the fill() function

I had assumed that the fill() function is the only place where the pump is turned on.

I think a broader explanation of the whole process is required.

...R