Help with my project

I have two aquariums. I want to exchange water between the two to keep the parameters the same. I'm using ATMega386P with Arduino 1.8.5. I have a GuitarCenter DJ strip connected to two pumps that will transfer water from one tank to the other through icemaker tubing. I'm using Tom's Aqualifter pumps for the transfer. Since I can't depend on both pumps running at the same volume I have a float switch in each tank to detect a high level at witch point it will shut down one of the pumps. It will run for awhile and then "hang" with no response from the float switches. I tried the Watchdog but it makes no difference.

I'm feeding the Arduino with 12 volts through a 7805 for 5 volts because I need the 12 volts for the DJ strip.

/*
 Water Transfer between two tanks
 Harry Hooper - 5/11/19
*/
#include <wdt.h>  // watchdog

#define doggieTickle() resetTime = millis();  // This macro will reset the timer

#define FragFloat 5
#define FragHiLED 7
#define FragPump 13
#define SysFloat 6
#define SysHiLED 8
#define SysPump 12

void(* resetFunc) (void) = 0; //declare reset function @ address 0 - part of watchdog

int floatstate = 0; // status of float valves

unsigned long resetTime = 0;

void setup() {
 // initialize the digital pins
 pinMode(FragFloat, INPUT_PULLUP);
 pinMode(FragHiLED, OUTPUT);
 pinMode(FragPump, OUTPUT);
 pinMode(SysFloat, INPUT_PULLUP);
 pinMode(SysHiLED, OUTPUT);
 pinMode(SysPump, OUTPUT);
 watchdogSetup();
}

void loop() {
 floatstate = 0;
 floatstate = digitalRead(SysFloat);
 if (floatstate == HIGH)
 {
   digitalWrite(FragPump, HIGH);   // Frag Pump on
   digitalWrite(SysHiLED, LOW);  // Red system high LED off
 }
 else
 {
   digitalWrite(FragPump, LOW);    // Frag Pump off
   digitalWrite(SysHiLED, HIGH);  // Red system high LED on
 }
 doggieTickle();  // reset the timer.

 floatstate = 0;
 floatstate = false;
 floatstate = digitalRead(FragFloat);
 if (floatstate == HIGH)
 {
   digitalWrite(SysPump, HIGH);   // Sys Pump on
   digitalWrite(FragHiLED, LOW);  // Red system high LED off
 }
 else
 {
   digitalWrite(SysPump, LOW);    // Sys Pump off
   digitalWrite(FragHiLED, HIGH);  // Red system high LED on
 }
 doggieTickle();  // reset the timer.
}

///////////////////////////////////////////////////////////
void watchdogSetup()
///////////////////////////////////////////////////////////
{
 cli();  // disable all interrupts
 wdt_reset(); // reset the WDT timer
 MCUSR &= ~(1 << WDRF); // because the data sheet said to
 /*
   WDTCSR configuration:
   WDIE = 1 :Interrupt Enable
   WDE = 1  :Reset Enable - I won't be using this on the 2560
   WDP3 = 0 :For 1000ms Time-out
   WDP2 = 1 :bit pattern is
   WDP1 = 1 :0110  change this for a different
   WDP0 = 0 :timeout period.
 */
 // Enter Watchdog Configuration mode:
 WDTCSR = (1 << WDCE) | (1 << WDE);
 // Set Watchdog settings: interrupte enable, 0110 for timer
 WDTCSR = (1 << WDIE) | (0 << WDP3) | (1 << WDP2) | (1 << WDP1) | (0 << WDP0);
 sei();
}

I know this is the not format for including code but I can't find the right place to do it. Any help would be much appreciated.

Do not need to use the ‘Watch dog” for this, in-fact this is not the purpose of it.

Just use software timers.

For timing use a technique called Blink Without Delay, BWD.
When using BWD, your sketch can run other code during the delay time.
Read Robin2’s discussion:
https://forum.arduino.cc/index.php?topic=223286.0

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

Your problem is the strategy. Both pumps will stop when the water level is ok in both. When that happends, use the combined status of the level in the 2 tanks to start one pump for some limited amount of time.

A second suggestion. When Your system stops, add some water to one of the aquariums in order to create an imbalance! That way it will be impossible for any equvilibrium to occur.
Or, lower one of the sensors a little bit.

harryehooper:
I know this is the not format for including code but I can't find the right place to do it. Any help would be much appreciated.

Well, you could read the forum instructions.

Then you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window. Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window. But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read. I think you may have, but I'm not sure.

If you do not post it as "code" it can be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper. People can usually see the mistakes directly and do not want to have to actually load it in their own IDE. And that would also assume they are using a PC and have the IDE running on that PC.

Also tidy up your blank space. Do use blank lines, but only between complete functional blocks.

@Paul__B
You are perfectly right, telling how to do. Sometimes I do that, some times I step over it, being frustrated. Ok, I was making the same mistakes in the beginning.
Today I was fortunate to use the Pc having more space to read the code. For smartphone members using the code tags is mandatory.

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Have you tried running your project without the strip?

Thanks.. Tom.. :slight_smile:

I'm using a PWM pin as an input for one of the float valves. Could that be the problem?

Also, I wonder if when the 12V signal to the relay strip actuates that it draws enough current to "starve" the 5V going to the Arduino causing it to hang?

How are the float switches connected? If the water level is BELOW the switch, what is the state of the input pin, HIGH or LOW?
I assume the Sys pump is in the Sys tank and when running, lowers the Sys level and raises the Frag level, is that correct?
Have you thought of running a siphon hose between the tanks so levels would automatically equalize? (IF the tanks are the same height above ground).

If the water is below the float switch it will read HIGH since they are declared with INPUT_PULLUP. When the water moves the switch it goes to LOW.

A HIGH reading on either float switch will cause the pump from the other tank to stop pumping into it.

Ideally both pumps will run constantly but I don't trust both to continue to pump at the same rate. If so it would be just a matter of plugging the pumps in and leaving it alone. I want to be able to detect a high water level and stop the pump long enough for the other pump to "catch up".

It's not just a matter of equalizing the water levels. One tank has excess nutrients and the other has less nutrients. If I can constantly have them exchanging water they both will be will in tolerances.

If the water is below the float switch it will read HIGH since they are declared with INPUT_PULLUP. When the water moves the switch it goes to LOW.

That's assuming the switches are normally OPEN and CLOSE on a rise in level, is that correct?
So, if the water rises above the switch it goes LOW, but you say:

A HIGH reading on either float switch will cause the pump from the other tank to stop pumping into it.

Sounds backward to me. :confused: Draw me a pitcher :slight_smile:

Put a large diameter tube between the two tanks in an inverted “U” shape .
Then with a smaller tube pushed inside suck the air out .
The two tanks are now connected and whatever will find its way back and forth through the water in the U

JCA79B:
That's assuming the switches are normally OPEN and CLOSE on a rise in level, is that correct?
So, if the water rises above the switch it goes LOW, but you say:
Sounds backward to me. :confused: Draw me a pitcher :slight_smile:

You can invert the float on the switch so it will read closed either in the up or down position, whichever you want. The switches are working correctly.