A few things and thanks for your suggestions. One, for some reason I can't get the arduino to output correctly. It will only switch relay K1. And even when it was working, as stated above, if you hit switch 1, it turns it on. Then when you press switch 2 at the same time, it turns it off. (both outputs)
So perhaps this code is not the way I want to go. I don't quite understand how to apply the switch case to my scenario, knowing my logic says no 2 solenoids can be open at the same time. I've enclosed my latest code below. Thanks again for all your help.
/*
Water Controller
This system controls water flow with 1 pump, 2 water tanks, 2 water level float switches, and 1 manual switch. Conditions are set
so that the pump is only feeding one source at any given time, to not choke the water supply or overload the pump. Only the manual switch
can activate it's solenoid to bring water in as it is feeding from one of the tanks. If two switches are low at the same time the system
will reject the others until the first one is high again.
Created May 5, 2012
by Brian Sheldon
*/
// Digital I/O Pin Constants
int S1 = 2; // Float Switch 1
int S2 = 3; // Float Switch 2
int S3 = 4; // Manual Switch 1
int K1 = 8; // Relay K1 - Solenoid for Tank 1
int K2 = 9; // Relay K2 - Solenoid for Tank 2
int K3 = 10; // Relay K3 - Solenoid for Manual Use
int K4 = 11; // Relay K4 - Water Pump Relay
void setup() {
// Initialize the pins, define digital I/O Pin Use
pinMode(S1, INPUT);
pinMode(S2, INPUT);
pinMode(S3, INPUT);
pinMode(K1, OUTPUT);
pinMode(K2, OUTPUT);
pinMode(K3, OUTPUT);
pinMode(K4, OUTPUT);
digitalWrite(S1, HIGH);
digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
}
void loop()
{
// Begin Water Tank 1 Logic
// If Switch 1 is Low, Water Low, First check if no other switches are LOW
if (digitalRead(S1) == LOW && digitalRead(S2) == HIGH && digitalRead(S3) == HIGH)
{
digitalWrite(K1,HIGH);
digitalWrite(K4,HIGH);
}
else
{
digitalWrite(K1,LOW);
digitalWrite(K4,LOW);
}
// Begin Water Tank 2 Logic
// If Switch 2 is Low, Water Low, First check if no other switches are LOW
if (digitalRead(S2) == LOW && digitalRead(S1) == HIGH && digitalRead(S3) == HIGH)
{
digitalWrite(K1,HIGH);
digitalWrite(K4,HIGH);
}
else
{
digitalWrite(K1,LOW);
digitalWrite(K4,LOW);
}
// Manual Switch 3 Logic
// If Switch 3 is Low, Water Low, First check if no other switches are LOW
if (digitalRead(S3) == LOW && digitalRead(S2) == HIGH)
{
digitalWrite(K3,HIGH);
digitalWrite(K4,HIGH);
}
else
{
digitalWrite(K3,LOW);
digitalWrite(K4,LOW);
}
}