How can I do this? Millis and conditions

Hello Arduino comunity, so im doing a code and I need the code do this:
Count 1 minute with millis
After count that minute, check a sensor
If sensor is minor than X value start another counter and inside that counter condition (because is millis) read a sensor and turn ON a rele until the sensor reach a value greater than X, after that restart the first counter and again again again.

I dont want the code, I just want to know if it is possible and maybe some guidance, thank you comunity

Yes, what you propose is possible.

maybe some guidance

Don't used delay() anywhere in loop().

These tutorials will be helpful

Doing several things at the same time
http://forum.arduino.cc/index.php?topic=223286.0

The basic idea is demonstrated by the Blink Without Delay example, and tutorial.

1 Like

So what happens when the minute timeout happens and the sensor is >= X? Wait another minute before checking? Or keep looking at it constantly until it's < X?

Edit: assuming the latter case:

setup:
make relay inactive
start 1 minute sensor timer

loop:
if relay is inactive and sensor timer has expired
  if sensor input < X
    make relay active
  end if
end if
if relay is active and sensor input >= X
  restart 1 minute sensor time
  make relay inactive
fi

If you only want the sensor checked for < X every minute, simply restart the sensor timer as the first step in the first outer if, just like in the second outer if.

Yes.

Read analog sensor https://docs.arduino.cc/language-reference/en/functions/analog-io/analogRead/

Less than https://docs.arduino.cc/language-reference/en/structure/comparison-operators/lessThan

Greater than https://docs.arduino.cc/language-reference/en/structure/comparison-operators/greaterThan/

Counters How to Make a Counter in Arduino | Delft Stack

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