Pumping delay questions

Hi, this is my first post and I have just started making an irrigation system for my science project.

List of items used in this system so far:

  1. Float switch
    2 .Ping (Ultrasonic distance sensor to measure water level in creek)
  2. Relay (for pumps, solenoid valve operation)

I need to install this system in natural tidal marsh region. There will be high and low tides; during low tides, there will be no water on sediment surface. I need to fill a tank to mix with salt (I am developing separate system for the salt mixing). To fill the tank, I need to pump water from near creek into the tank only when both water level is low in the tank && (and) creek is filled with water (high tides).

This will be installed in natural system, so there will be a lot of unexpected events, such as boat wake, wind, etc. And I don't my pump run during this event because water level in creek could be actually lower than my submerged pump. To make sure the pump only works during high tides, I want make Arduino program checking 'actual' water depth over some time (10 minutes?).

So, in the program, I used 'delay'. But when I used it, the system not only delays the initiation of pumping, but also it waits for the same amount of time to turn off the pump, which is not good for submerged pump.

So my question is: instead of 'delay', is there any function I can use to do similar task (wait for 'turn on' but not wait for 'turn off').

Please provide any comment, idea, or advice.



BrineTankControl_if.ino (3.3 KB)

You can use millis() for timing. Use it to record the start time of an action then check each time through loop() to see whether the required period has ended.

This is often known as the BlinkWithoutDelay method because of the example in the IDE with that name.

Look at how millis() is used to manage timing in several things at a time. If you are new to the Arduino the Thread planning and implementing a program may be useful.