SOLVED-- HELP: Closing Serial Monitor will close the Digital pin output


I am quite new for Arduino. Currently I am doing a projet that is to use Arduino Ethernet Shield and Duemilanove 328 as webserver to control 8 relays (used 4 LEDs for testing) and 1 mini servo.

4 LEDs are attached to pin 2-8 and A0, mini servo is attached to pin 9. The sketch is made up from several projects found from internet. But, anyway, finally it works. Serial Port will print the dynamic IP. Then put the ip to browser, I can control the LEDS on/off and swivel the servo.

The problem is : the LEDs will be off and servo will turn an angle if I close the Serial Monitor Even the servo will move and 4 leds close to RJ45 socket will off for less 1s then on when I move the cursor over Tools. Does anyone know this problem? I made video in Youtube, please have a look.

I don’t think this is the sketch’s problem, but I will put here, sorry for my poor programming skills.


#include <Ethernet.h>
#include <SPI.h>
#include <Servo.h>
boolean reading = false;

  byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xBD };

  EthernetServer server = EthernetServer(80); //port 80

String inString = String(35);
Servo radio; // creat subject to control the radio
String Vhf1;
String Vhf2;
String Vhf3;
String Vhf4;
String Uhf1;
String Uhf2;
String Uhf3;
String Uhf4;
int VHF1 = 14;  // Analog input used as Digital I/O   A0=14..........A5=19
int VHF2 = 2; 
int VHF3 = 3; 
int VHF4 = 4; 

int UHF1 = 5; 
int UHF2 = 6; 
int UHF3 = 7; 
int UHF4 = 8; 

String value1="on";
String value2="on";
String value3="on";
String value4="on";
String value5="on";
String value6="on";
String value7="on";
String value8="on";

String data;
void setup(){
  radio.attach(9); //attach pin 9 to servo to control radio

  //Pins 10,11,12 & 13 are used by the ethernet shield
    pinMode(VHF1, OUTPUT);
    pinMode(VHF2, OUTPUT);
    pinMode(VHF3, OUTPUT);
    pinMode(VHF4, OUTPUT);
    pinMode(UHF1, OUTPUT);
    pinMode(UHF2, OUTPUT);
    pinMode(UHF3, OUTPUT);
    pinMode(UHF4, OUTPUT);

  //Ethernet.begin(mac, ip, gateway, subnet); //for manual setup



void loop()
  EthernetClient client = server.available();
    // an http request ends with a blank line
    boolean current_line_is_blank = true;
    while (client.connected()) {
      if(client.available()) {
        char c =;
        // if we've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so we can send a reply
        if (inString.length() < 35) {
        if (c == '\n' && current_line_is_blank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("<html><body><form method=get>");
          client.println("&nbsp;&nbsp;&nbsp;&nbsp;<font size=\"7\">Ground Station</font>
<b><font size=\"4\">Radio On/Off</font></b>
<button name=\"radio\" value=\"5\">Push</button>");
          if (inString.indexOf("radio")> 0 ){
            Serial.println("radio on");

&nbsp;&nbsp;&nbsp;&nbsp;<font size=\"6\">Polarisation Switch Controller</font>
<b><i><font color=red><font size=\"5\">Warning: Only ONE switch can be ON for each band</font></font></i></b>
<b><font size=\"4\">VHF</font></b>
         //for(int i=1;i < (4 + 1) ;i++){ 
           //Vhf = String("VHF") + i;
           Vhf1 = String("VHF1") ;
           Vhf2 = String("VHF2") ;
           Vhf3 = String("VHF3") ;
           Vhf4 = String("VHF4") ;
          if(inString.indexOf(Vhf1+"=on")>0 ){
            //digitalWrite(VHF[i], HIGH);
            digitalWrite(VHF1, HIGH);
            value1 = "off"; 
          }else if(inString.indexOf(Vhf1+"=off")>0 ){          
            //digitalWrite(VHF[i], LOW);
            //value[i] = "on";
            digitalWrite(VHF1, LOW);
            value1 = "on";
          if(inString.indexOf(Vhf2+"=on")>0 ){
            //digitalWrite(VHF[i], HIGH);
            digitalWrite(VHF2, HIGH);
            value2 = "off"; 
          }else if(inString.indexOf(Vhf2+"=off")>0  ){          
            //digitalWrite(VHF[i], LOW);
            //value[i] = "on";
            digitalWrite(VHF2, LOW);
            value2 = "on";
          if(inString.indexOf(Vhf3+"=on")>0 ){
            //digitalWrite(VHF[i], HIGH);
            digitalWrite(VHF3, HIGH);
            value3 = "off"; 
          }else if(inString.indexOf(Vhf3+"=off")>0  ){          
            //digitalWrite(VHF[i], LOW);
            //value[i] = "on";
            digitalWrite(VHF3, LOW);
            value3 = "on";
          if(inString.indexOf(Vhf4+"=on")>0 ){
            //digitalWrite(VHF[i], HIGH);
            digitalWrite(VHF4, HIGH);
            value4 = "off"; 
          }else if(inString.indexOf(Vhf4+"=off")>0  ){          
            //digitalWrite(VHF[i], LOW);
            //value[i] = "on";
            digitalWrite(VHF4, LOW);
            value4 = "on";
           Uhf1 = String("UHF1") ;
           Uhf2 = String("UHF2") ;
           Uhf3 = String("UHF3") ;
           Uhf4 = String("UHF4") ;
          if(inString.indexOf(Uhf1+"=on")>0 ){
            //digitalWrite(VHF[i], HIGH);
            digitalWrite(UHF1, HIGH);
            value5 = "off"; 
          }else if(inString.indexOf(Uhf1+"=off")>0 ){          
            //digitalWrite(VHF[i], LOW);
            //value[i] = "on";
            digitalWrite(UHF1, LOW);
            value5 = "on";
<input type=submit name="+Vhf1+" value="+value1+">Horizontal");
<input type=submit name="+Vhf2+" value="+value2+">Vertal");
<input type=submit name="+Vhf3+" value="+value3+">RHCP ");
<input type=submit name="+Vhf4+" value="+value4+">LHCP");

<b><font size=\"4\">UHF</font></b>
<input type=submit name="+Uhf1+" value="+value5+">Horizontal ");
<input type=submit name="+Uhf2+" value="+value6+">Vertal ");
<input type=submit name="+Uhf3+" value="+value7+">RHCP ");
<input type=submit name="+Uhf4+" value="+value8+">LHCP");
        if (c == '\n') {
          // we're starting a new line
          current_line_is_blank = true;
        } else if (c != '\r') {
          // we've gotten a character on the current line
          current_line_is_blank = false;
    // give the web browser time to receive the data
    inString = "";

Does the Arduino behave properly if you power it through the power jack and not the USB?

You might try disabling RESET by putting a 120 Ohm resistor between +5 and reset so the serial port can't reset the Arduino. The serial port still works, it just won't force a reset when you connect.

Note if you do this you have to manually press the reset to upload code.

kf2qd: thank you very much! I just tried to power Arduino with the power jack, it works properly. But once I plugged USB then the problem comes again. I will add a resistor to disable the RESET, because I need to use Serial Monitor to check the IP every time :)

GM: thank you for your kind remind :)