tide simulation sketch questions

The idea is to create a gyre by running six pumps for about six hours, then run six other pumps in the opposite direction. Meanwhile, the pumps that are not running need to twitch every two minutes or so-otherwise fish are likely to hide in the pump housing and get ground up.

Do I have ‘for’ right? Will this sketch likely alternate the two sets of pumps about every six hours? Will the pumps that are not running twitch one time every two minutes or so?

``````  unsigned long hoursInMs(int h)
{
return h*3600000UL;         //values will be expressed in hours

}

long minutesInMs(int m){
return m*60000L;           //values will be expressed in minutes

}

long secondsInMs(int s){
return s*1000L;            //values will be expressed in seconds
}

void setup()
{

pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
}

void loop()
{
for(int x = 0; x < 181; x++)   //let pumps 4, 5, 6, 10, 11, 12 run, and 13, 2, 3, 7, 8, 9 twitch for 6 hours or so
{
digitalWrite(4, HIGH);    //turn pump 4 on
digitalWrite(5, HIGH);    //turn pump 5 on
digitalWrite(6, HIGH );   //turn pump 6 on
digitalWrite(10, HIGH);   //turn pump 10 on
digitalWrite(11, HIGH);   //turn pump 11 on
digitalWrite(12, HIGH);   //turn pump 12 on

digitalWrite(13, LOW);    //turn pump 13 off
digitalWrite(2, LOW);     //turn pump 2 off
digitalWrite(3, LOW);     //turn pump 3 off
digitalWrite(7, LOW);     //turn pump 7 off
digitalWrite(8, LOW);     //turn pump 8 off
digitalWrite(9, LOW);     //turn pump 9 off

delay(secondsInMs(20));
digitalWrite(13, HIGH);      //make pump 13 twitch
delay (100);                 //adjust this delay for the twitch
digitalWrite(13, LOW);       //turn pump 13 off

delay(secondsInMs(20));
digitalWrite(2, HIGH);        //make pump 2 twitch
delay (100);                  //adjust this delay for the twitch
digitalWrite(2, LOW);         //turn pump 2 off

delay(secondsInMs(20));
digitalWrite(3, HIGH);        //make pump 3 twitch
delay (100);                  //adjust this delay for the twitch
digitalWrite(3, LOW);         //turn pump 3 off

delay(secondsInMs(20));
digitalWrite(7, HIGH);         //make pump 7 twitch
delay (100);                   //adjust this delay for the twitch
digitalWrite(7, LOW);          //turn pump 7 off

delay(secondsInMs(20));
digitalWrite(8, HIGH);         //make pump 8 twitch
delay (100);                   //adjust this delay for the twitch
digitalWrite(8, LOW);          //turn pump 8 off

delay(secondsInMs(20));
digitalWrite(9, HIGH);          //make pump 9 twitch
delay (100);                    //adjust this delay for the twitch
digitalWrite(9, LOW);           //turn pump 9 off
}

for(int x = 0; x < 181; x++)  //let pumps 13, 2, 3, 7, 8, 9 run, and 4, 5, 6, 10, 11, 12 twitch for 6 hours or so
{
digitalWrite(13, HIGH);    //turn pump 13 on
digitalWrite(2, HIGH);     //turn pump 2 on
digitalWrite(3, HIGH );    //turn pump 3 on
digitalWrite(7, HIGH);     //turn pump 7 on
digitalWrite(8, HIGH);     //turn pump 8 on
digitalWrite(9, HIGH);     //turn pump 9 on

digitalWrite(4, LOW);       //turn pump 4 off
digitalWrite(5, LOW);       //turn pump 5 off
digitalWrite(6, LOW);       //turn pump 6 off
digitalWrite(10, LOW);      //turn pump 10 off
digitalWrite(11, LOW);      //turn pump 11 off
digitalWrite(12, LOW);      //turn pump 12 off

delay(secondsInMs(20));
digitalWrite(4, HIGH);       //make pump 4 twitch
delay (100);                 //adjust this delay for the twitch
digitalWrite(4, LOW);        //turn pump 4 off

delay(secondsInMs(20));
digitalWrite(5, HIGH);       //make pump 5 twitch
delay (100);                 //adjust this delay for the twitch
digitalWrite(5, LOW);        //turn pump 5 off

delay(secondsInMs(20));
digitalWrite(6, HIGH);        //make pump 6 twitch
delay (100);                  //adjust this delay for the twitch
digitalWrite(6, LOW);         //turn pump 6 off

delay(secondsInMs(20));
digitalWrite(10, HIGH);        //make pump 10 twitch
delay (100);                   //adjust this delay for the twitch
digitalWrite(10, LOW);         //turn pump 10 off

delay(secondsInMs(20));
digitalWrite(11, HIGH);        //make pump 11 twitch
delay (100);                   //adjust this delay for the twitch
digitalWrite(11, LOW);         //turn pump 11 off

delay(secondsInMs(20));
digitalWrite(12, HIGH);         //make pump 12 twitch
delay (100);                    k//adjust this delay for the twitch
digitalWrite(12, LOW);          //turn pump 12 off
}
}
``````

By doing it in for loops with blocking code that's all this program will ever do. You will need a separate arduino for your pH monitor code or lights or whatever else you want.

You might have a look at the Blink Without Delay example and write some code that turns pumps on and off at the right times without having to have it trapped running through the whole procedure without being able to do anything else.

Thanks Delta_G. I was going to dedicate an Arduino to this project. I'm pretty sure a nano will do.
I'll take a look at Blink without delay, but if this sketch gives me a tide simulation, I'm using it.

Besides, I like to not count on any one device for very much. If it got unplugged or something, it won't take down my whole system.

saltyjoe:
Besides, I like to not count on any one device for very much. If it got unplugged or something, it won't take down my whole system.

... but then, you have to ensure that the software protocols that you use to communicate between devices, are fault tolerant (have a procedure to follow if they lose connection with the other devices).

No worries there, everything I have is stand alone. But that does make me a little itchy because if I end up using a pH probe to control dosing and it got out of whack, my tank could get overdosed with kalwasser slurry. That'd be real bad.

saltyjoe:
Besides, I like to not count on any one device for very much. If it got unplugged or something, it won't take down my whole system.

This concept is not always as simple as it seems.

If one of the functions is critical its failure will take down the whole system and in some cases it may cause even more trouble if another part of the system keeps operating.

Having two devices doubles the risk of one device failing but the risk that both will fail at the same time is much lower than the risk of one device failing.

...R

Good points, thanks. Your post got me thinking about redundancy. I set half the pumps on LOW and the other half on HIGH and will use both NO and NC relays to run the pumps. That way if the Arduino gets unplugged or fails, half the pumps will still be running.

Delta_G:
You might have a look at the Blink Without Delay example and write some code that turns pumps on and off at the right times without having to have it trapped running through the whole procedure without being able to do anything else.

I looked at blink without delay-Mellis on millis. You are right, I need to get a grip on millis.

One thing that'd be really nice for the pump circulation sketch is an alert if a pump fails, gets unplugged etc. (each pump has a dedicated power supply) Maybe a red LED for each pump that fails.

Any chance you guys might point me in the right direction?

Hi,

A gyre in oceanography is any large system of rotating ocean currents, particularly those involved with large wind movements. Gyresare caused by the Coriolis effect; planetary vorticity along with horizontal and vertical friction, determine the circulation patterns from the wind curl (torque).

Meanwhile, the pumps that are not running need to twitch every two minutes or so-otherwise fish are likely to hide in the pump housing and get ground up.

How do you stop fish getting ground up in the pumps that run for 6 hours,
If you are pumping water in and out of (tide), or around (gyre), an environment, haven't you got filters over the inlet and outlets?

Tom....

saltyjoe:
One thing that'd be really nice for the pump circulation sketch is an alert if a pump fails, gets unplugged etc. (each pump has a dedicated power supply) Maybe a red LED for each pump that fails.

One solution may be to put an optical detector close to each pump shaft and a bit of black and white paint on the shaft. The Arduino could detect the time between pulses and cause an alert if it is too long. I recently got some QRE1113 reflective optical detectors which are very small and easy to connect to an Arduino. Sparkfun makes a breakout board for them.

...R

saltyjoe:
The idea is to create a gyre by running six pumps for about six hours, then run six other pumps in the opposite direction. Meanwhile, the pumps that are not running need to twitch every two minutes or so-otherwise fish are likely to hide in the pump housing and get ground up.

Do I have 'for' right?

I don't think so. Tide flow rate is NOT the same all day through.

The water flow rate during a tide is rather following a sine curve:

High tide: water flow rate = zero
Low tide : water flow rate = zero
half time between high and low tide: water flow rate = maximum

Tom, the (submerged) pumps have open outlets where water blasts out and a 'screened' inlet area-nothing big can get pulled in. When a pump sits idle for six hours, a fish could decide to enter the outlet and hide out. When the pump fires up, that fish is puree. That's what the twitch is for.

Robin, since the pumps are submerged in saltwater and the shafts are pretty well tucked away when running, optical detectors might be a tough solution.

jurs, what I meant about having 'for' right was, will the 'for' function work as written.
I know it's nowhere near a perfect tidal simulation. But it's better than running pumps in a single pattern.

saltyjoe:
Robin, since the pumps are submerged in saltwater and the shafts are pretty well tucked away when running, optical detectors might be a tough solution.

That presents a challenge. However I doubt if there is salt water inside the pump motor and maybe there is scope for putting a sensor inside it.

It may be an option to monitor the motor current - either for zero current or stall current. Some motor drivers have an error output, but maybe you are just using relays.

I don't know if it would work in water but I had a boat air heater which shut of power to the fan at intervals and measured the back EMF to test if the fan was running properly. It could be that water would present too much resistance and cause the pump to stop.

...R

saltyjoe:
The idea is to create a gyre

They say it's a sad day when you don't learn anything; I had to look gyre up to see what that is.

jurs:
The water flow rate during a tide is rather following a sine curve:

High tide: water flow rate = zero
Low tide : water flow rate = zero
half time between high and low tide: water flow rate = maximum

That’s what I was going to suggest too. However, I think that six pumps are enough to do a rough sampling of a sine wave, and hopefully the sampling will turn out to be smooth enough that the fish won’t notice!

My understanding is that the water level at any moment is the value of a sine function plotted against a 12-hour circle, with angle zero starting midway between low tide and high tide, rising (with high tide at pi/4, low tide at 3xpi/4, of course). Since the rate of change of sine is cosine, I would divide the cosine between 1 and 0 (the first quarter turn) in 6 parts. Since the angles correspond to time, the arccosine will give the duration of each pumping configuration. I wouldn’t let the arduino handle the calculations, but I would rather hard-code a look-up table.

pi/2 corresponds to 3 hours, or 180 minutes (every degree being 2 minutes of time if you don’t like radians) So, for how long does one single pump work?

T1 = ( acos(5/6) ) x (180 / pi) x 2 = 67 minutes, that’s how long one single pump stays on.

What about two pumps together? T2 = ( acos(4/6) ) x (180 / pi) x 2 = 96, so two pumps together will work (96 - 67) = 29 minutes, from T1 to T2. Then, the 3rd pump will turn on and so on until there are six of them pumping away. Notice how the time for each configuration grows shorter as we approach full power.

Then, the pumps turn off one at a time, and then we are at high tide, six hours later, when that one single pump is just finishing it’s duty. At this point, this single pump reverses (time for the ebb to start!), and there we go again in the opposite direction, pump after pump.

That was long to explain, but it only takes a few minutes to write a script in any language that will print a table.

It’s not perfectly clear to me whether we have got 6 or 12 pumps and whether the pumps can or cannot be reversed. The more the pumps, of course, the better the approximation.

I’m mo math expert, but I hope my approach makes some sense…

Hi,

Tom, the (submerged) pumps have open outlets where water blasts out and a 'screened' inlet area-nothing big can get pulled in.

Filter on the outlet?

Tom...