Arduino has some strange reactions

Another few things that are important to indicate:

  • Adding RC Suppressors do help a lot, one across the contactor coil and one each across the solenoid load directly at the load. The frequency of mysterious events drops significantly, almost enough to say screw it and go with the system as is. Yet the false triggers still make me want to find the issue at hand.

  • The two ac loads in my system, a contactor and ac solenoids can function what appears to be perfectly if they are used individually. That is to say, with rc suppressors in place, if I only engage the contactor, or only switch the solenoid, one or the other, there are no problems apparent. It's the combination of the two that causes problems. Again, not nearly as much with the RC networks.

I've rewritten the code slightly, and enclosed it below. I've checked the DC supply to the arduino with my scope and only see a clean dc supply with no significant drops/ripple in the supply. I'm open to suggestions on perhaps probing the I/O to see what's actually happening. I would still really like to know how the arduino is having these seemingly random events, even with suppressing the ac loads. Thank you.

/*
  Water Controller
 
 This system controls water flow with 1 pump, 3 Water Solenoids, 2 water tanks, 2 water level float switches, and 2 manual switches. 
 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 hold the others until the first one is high again. 
 
 Sketch Created July 7, 2012
 by Brian
*/

// Digital Input Pin Constants
const int S1 = 2;    // Float Switch 1
const int S2 = 3;    // Float Switch 2
const int S3 = 4;    // Manual Switch 1 (Junction Box)
const int S4 = 5;    // Manual Switch 2 (Enclosure)
// Digital Output Pin Constants
const int K1 = 6;    // Relay K1 - Solenoid for Tank 1
const int K2 = 7;    // Relay K2 - Solenoid for Tank 2
const int K3 = 8;    // Relay K3 - Solenoid for Manual Use
const int K4 = 9;    // Relay K4 - Water Pump Relay
// Delay Times
const int DT1 = 3000;  // Solenoid/Debounce Delay Time
const int DT2 = 20;     // Manual Switch Delay Time for Debounce
// Variables that will Change
int curS;

void setup() {
 // Initialize the pins, define digital I/O Pin Usage
   //Inputs
  pinMode(S1, INPUT);
  pinMode(S2, INPUT);
  pinMode(S3, INPUT);
  pinMode(S4, INPUT); 
   //Outputs
  pinMode(K1, OUTPUT);
  pinMode(K2, OUTPUT);
  pinMode(K3, OUTPUT);
  pinMode(K4, OUTPUT);
  digitalWrite(S1, HIGH);
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  digitalWrite(S4, HIGH);
  Serial.begin(9600);
  Serial.println(F("System On"));
}

void loop() {
// Begin Water Tank 1 Logic
  if (digitalRead(S1) == LOW && curS == 0) 
  {
    Serial.println(F("Water Tank 1 Low"));
    digitalWrite(K1, HIGH);
    Serial.println(F("Solenoid 1 Open"));
    delay(DT1);
    digitalWrite(K4, HIGH);
    Serial.println(F("Pump On"));
    Serial.println(F("Filling Water Tank 1"));
    curS = S1;  
  }
  else if (digitalRead(S1) == HIGH && curS == S1) 
  {
    Serial.println(F("Water Tank 1 Full"));
    digitalWrite(K4, LOW);
    Serial.println(F("Pump Off"));
    delay(DT1);
    digitalWrite(K1, LOW);
    Serial.println(F("Solenoid 1 Closed"));
    curS = 0;
  }
// Begin Water Tank 2 Logic
  if (digitalRead(S2) == LOW && curS == 0) 
  {
    Serial.println(F("Water Tank 2 Low"));
    digitalWrite(K2, HIGH);
    Serial.println(F("Solenoid 2 Open"));
    delay(DT1);
    digitalWrite(K4, HIGH);
    Serial.println(F("Pump On"));
    Serial.println(F("Filling Water Tank 2"));
    curS = S2;
  }
  else if (digitalRead(S2) == HIGH && curS == S2) 
  {
    Serial.println(F("Water Tank 2 Full"));
    digitalWrite(K4, LOW);
    Serial.println(F("Pump Off"));
    delay(DT1);
    digitalWrite(K2, LOW);
    Serial.println(F("Solenoid 2 Closed"));
    curS = 0;
  }  
// Begin Manual Switch 1 Logic
  if (digitalRead(S3) == LOW && curS == 0) 
  {
    Serial.println(F("Misc. Water Valve Open"));
    digitalWrite(K3, HIGH);
    delay(DT2);
    curS = S3;  
  }
  else if (digitalRead(S3) == HIGH && curS == S3) 
  {
    Serial.println(F("Misc. Water Valve Closed"));
    digitalWrite(K3, LOW);
    delay(DT2);
    curS = 0;
  } 
// Begin Manual Switch 2 Logic
  if (digitalRead(S4) == LOW && curS == 0)
  {
    Serial.println(F("Manual Pump Switch On"));
    digitalWrite(K4, HIGH);
    curS = S4;
    delay(DT2);
  }
  else if (digitalRead(S4) == HIGH && curS == S4)
  {
    Serial.println(F("Manual Pump Switch Off"));
    digitalWrite(K4, LOW);
    delay(DT2);
    curS = 0;
  }
}