I want to have a pin on for 10 seconds before it is considered on

in the following code I want to have dc_producttank_tank High signal to be on for at least 10 seconds before it considers it as actually is high. I have electronic noise that trips the sensor and I want to make sure the sensor is actually is tripped before the program turns the system off. What should I program in to make this so?

if ((DryContactValues[dc_producttank_high] == HIGH) && (DryContactValues[dc_ciptank_high] == LOW))
{
Serial << F(“Product tank full, system shutting down.\n”);
state_currentmode = mode_shutdown;

You need to record when the pin transitions to HIGH (or LOW, whichever means "on"). Then, you look at now (millis()) vs. then (also captured using millis()) to determine how long the pin has been on. Be sure to clear the on time when the pin goes off.

In other words, a 10 second debounce !

Hi,
I had a similar issue and was pointed to the Elapsed timing library (Much easier then millis)
Example

If (pin == HIGH)
{
t1.reset();
}

if(t1.intervalMs() > 10000)
{
do something;
}

Nick Gammon has created this library and you can check out his site at nickgammon.com (hard to site find stuff thou)
I used it to check when a battery went above a certain level it began a 30sec timer at the end of the time it checks that it is still above the voltage and acts accordingly. you need to add variable to change states, below is the code I used

#include <Elapsed.h> // Library for Timers

static Elapsed t1, t2, t3, t4, t5, t6, t7; // Timers for the many timing demands ( You only need one )

void loop() {

if (AuxVolts >= 13 && !Press1 && Act1 != HIGH)
{
Act1 = HIGH;
Act = LOW;
Press1 = true;
t7.reset();
}

if (Press1 && t7.intervalMs() > 7500 && AuxVolts >= 13)
{
Press1 = false;
digitalWrite(AuxRelay, HIGH);
}
else if (AuxVolts <= 13)
{
t7.reset();
}

Hope this helps !

BlackSnake:
Nick Gammon has created this library and you can check out his site at nickgammon.com (hard to site find stuff thou)

That Nick Gammon is an artist.

Try: Gammon Forum : Electronics