Arduino Pins all go low after serial port closes

Hi,

I’m new to the forum and have been stumped by this problem for a while now. I’m trying to control the state of a few digital pins from the serial port on the Arduino. My issue is that when I close the serial port on the host machine that is feeding the commands to the Arduino, all of the Arduino’s pins go low. Can anyone assist or maybe have an answer as to why this happens ? I have posted some sample code below.

-John

int Line[5] = {0,0,0,0};
int input = 0;

void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
pinMode(5, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
print();
}

void print() {
int loop = 1;
Serial.print(“Relay Control\n”);
while (loop <= 4) {
Serial.print("Line “);
Serial.print(loop);
Serial.print(”: ");
Serial.println(Line[loop]);
loop = loop + 1;
}
}

int check(int in) {
int pin = in + 1;
if (Line[in] == 0) {
digitalWrite(pin, LOW);
return 1;
}
else {
if (Line[in] == 1) {
digitalWrite(pin, HIGH);
return 0;
}
}
}

void loop() {
if (Serial.available() > 0) {
input = Serial.read();
input = input - 48;
Line[input] = check(input);
print();
}
}

Arduino is reset when the serial monitor is opened or closed.

Thanks for the response, I had that suspicion. Now to find a way around it.

-John

You can disable the auto reset feature: http://wp.yellowkazoo.com/?p=177

Google