Well, needless to say I have some gremlins in the panel that I need to work out. I took the time to go back and print in all of my I/O so that I could get a better idea on the serial bus what it was doing, or what it was being told to do. To keep it simple, on a low voltage, and logic level this works perfectly. With just the arduino and a sainsmart 4 relay board, usb cable, it does exactly what I intend.
The problem however is that in the small control box I also have also have an AC transformer for some solenoids, as well as a large AC contactor, ac bus and I'm switching larger relays with the sainsmart board with AC loads. I did my best to keep everything away from each other but inevitably in a small panel there is only so much you can do to not cross LV/HV wiring.
Anyhow, my first question when reading the serial bus and this happens quite randomly, but the arduino seems to restart for the lack of better terms when I am switching off a high voltage output. But it happens completely randomly and with no rhyme or reason. I did notice however is that the serial bus shows this:
Exhibit A: A snippet of the code it's running including a snippet from the setup to show the serial start
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("System Initialized");
}
// Begin Water Tank 1 Logic
if (digitalRead(S1) == LOW && curS == 0)
{
Serial.println("Water Tank 1 Low");
digitalWrite(K1, HIGH);
Serial.println("Solenoid 1 Open");
delay(3000);
digitalWrite(K4, HIGH);
Serial.println("Pump On");
Serial.println("Filling Water Tank 1");
curS = S1;
}
else if (digitalRead(S1) == HIGH && curS == S1)
{
Serial.println("Water Tank 1 Full");
digitalWrite(K4, LOW);
Serial.println("Pump Off");
delay(3000);
digitalWrite(K1, LOW);
Serial.println("Solenoid 1 Closed");
curS = 0;
}
Exhibit B: The serial Monitor
Water Tank 1 Low
Solenoid 1 Open
Pump On
Filling Water Tank 1
Water TùSystem Initialized
^^ What would cause this last line?
What drew me to this was that sometimes when switching one output off, it would turn another one on, but again randomly. When I got my meter out and checked the input driving the output turned on randomly, it wasn't being driven low, even though the output was being driven by the arduino, being high. Weird to say the least, I think these two issues could be related.
Thanks for your help.