ETHERNET CONTROLLED SWITCH

hi,
i was trying to make a web controlled switch using ethernet shield. initially the switching works… but when i try to turn on the other switches, automatically the first switch turns off,
i am tryin to conrtol 3 relays using simple check box…
the code is attached below…
anyone plz help!!

#include <SPI.h>
#include <Ethernet.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10, 0, 0, 20); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

String HTTP_req;          // stores the HTTP request
boolean SWITCH_status = 0;   // state of SWITCH, off by default
boolean SWITCH_status3 = 0;
boolean SWITCH_status5 = 0;
void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for diagnostics
    pinMode(2, OUTPUT);       // SWITCH on pin 2
    pinMode(3, OUTPUT);       // SWITCH on pin 3
    pinMode(5, OUTPUT);       // SWITCH on pin 5
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                HTTP_req += c;  // save the HTTP request 1 char at a time
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    // send web page
                    client.println("<!DOCTYPE html>");
                    client.println("<html>");
                    client.println("<head>");
                    client.println("<title>Arduino SWITCH Control</title>");
                    client.println("</head>");
                    client.println("<body>");
                    client.println("<h1><center>WEB SWITCH</center></h1>");
                    client.println("<p><center>CLICK TO TURN THE SWITCH ON OR OFF</center></p>");
                    client.println("<form method=\"get\">");
                    ProcessCheckbox(client);
                    ProcessCheckbox3(client);
                    ProcessCheckbox5(client);
                    client.println("</form>");
                    client.println("</body>");
                    client.println("</html>");
                    Serial.print(HTTP_req);
                    HTTP_req = "";    // finished with request, empty string
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

// switch SWITCH and send back HTML for SWITCH checkbox
void ProcessCheckbox(EthernetClient cl)
{
    if (HTTP_req.indexOf("SWITCH2=2") > -1) {  // see if checkbox was clicked
        // the checkbox was clicked, toggle the SWITCH
        if (SWITCH_status) {
            SWITCH_status = 0;
        }
        else {
            SWITCH_status = 1;
        }
    }
    
    if (SWITCH_status) {    // switch SWITCH on
        digitalWrite(2, HIGH);
        // checkbox is checked
        cl.println("<input type=\"checkbox\" name=\"SWITCH2\" value=\"2\" \
        onclick=\"submit();\" checked>SWITCH2");
    }
    else {              // switch SWITCH off
        digitalWrite(2, LOW);
        // checkbox is unchecked
        cl.println("<input type=\"checkbox\" name=\"SWITCH2\" value=\"2\" \
        onclick=\"submit();\">SWITCH2");
    }
}


void ProcessCheckbox3(EthernetClient cl3)
{
    if (HTTP_req.indexOf("SWITCH3=3") > -1) {  // see if checkbox was clicked
        // the checkbox was clicked, toggle the SWITCH
        if (SWITCH_status3) {
            SWITCH_status3 = 0;
        }
        else {
            SWITCH_status3 = 1;
        }
    }
    
    if (SWITCH_status3) {    // switch SWITCH on
        digitalWrite(3, HIGH);
        // checkbox is checked
        cl3.println("<input type=\"checkbox\" name=\"SWITCH3\" value=\"3\" \
        onclick=\"submit();\" checked>SWITCH3");
    }
    else {              // switch SWITCH off
        digitalWrite(3, LOW);
        // checkbox is unchecked
        cl3.println("<input type=\"checkbox\" name=\"SWITCH3\" value=\"3\" \
        onclick=\"submit();\">SWITCH3");
    }
}


void ProcessCheckbox5(EthernetClient cl5)
{
    if (HTTP_req.indexOf("SWITCH5=5") > -1) {  // see if checkbox was clicked
        // the checkbox was clicked, toggle the SWITCH
        if (SWITCH_status5) {
            SWITCH_status5 = 0;
        }
        else {
            SWITCH_status5 = 1;
        }
    }
    
    if (SWITCH_status5) {    // switch SWITCH on
        digitalWrite(5, HIGH);
        // checkbox is checked
        cl5.println("<input type=\"checkbox\" name=\"SWITCH5\" value=\"5\" \
        onclick=\"submit();\" checked>SWITCH5");
        
    }
    else {              // switch SWITCH off
        digitalWrite(5, LOW);
        // checkbox is unchecked
        cl5.println("<input type=\"checkbox\" name=\"SWITCH5\" value=\"5\" \
        onclick=\"submit();\">SWITCH5");
    }
}

arjunravi:
hi,
i was trying to make a web controlled switch using ethernet shield. initially the switching works… but when i try to turn on the other switches, automatically the first switch turns off,
i am tryin to conrtol 3 relays using simple check box…
the code is attached below…
anyone plz help!!

#include <SPI.h>

#include <Ethernet.h>

// MAC address from Ethernet shield sticker under board
byte mac = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10, 0, 0, 20); // IP address, may need to change depending on network
EthernetServer server(80);  // create a server at port 80

String HTTP_req;          // stores the HTTP request
boolean SWITCH_status = 0;  // state of SWITCH, off by default
boolean SWITCH_status3 = 0;
boolean SWITCH_status5 = 0;
void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();          // start to listen for clients
    Serial.begin(9600);      // for diagnostics
    pinMode(2, OUTPUT);      // SWITCH on pin 2
    pinMode(3, OUTPUT);      // SWITCH on pin 3
    pinMode(5, OUTPUT);      // SWITCH on pin 5
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {  // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                HTTP_req += c;  // save the HTTP request 1 char at a time
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == ‘\n’ && currentLineIsBlank) {
                    // send a standard http response header
                    client.println(“HTTP/1.1 200 OK”);
                    client.println(“Content-Type: text/html”);
                    client.println(“Connection: close”);
                    client.println();
                    // send web page
                    client.println("");
                    client.println("");
                    client.println("");
                    client.println(“Arduino SWITCH Control”);
                    client.println("");
                    client.println("");
                    client.println(“

WEB SWITCH

”);
                    client.println(“

CLICK TO TURN THE SWITCH ON OR OFF

”);
                    client.println("<form method=“get”>");
                    ProcessCheckbox(client);
                    ProcessCheckbox3(client);
                    ProcessCheckbox5(client);
                    client.println("");
                    client.println("");
                    client.println("");
                    Serial.print(HTTP_req);
                    HTTP_req = “”;    // finished with request, empty string
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == ‘\n’) {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                }
                else if (c != ‘\r’) {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

// switch SWITCH and send back HTML for SWITCH checkbox
void ProcessCheckbox(EthernetClient cl)
{
    if (HTTP_req.indexOf(“SWITCH2=2”) > -1) {  // see if checkbox was clicked
        // the checkbox was clicked, toggle the SWITCH
        if (SWITCH_status) {
            SWITCH_status = 0;
        }
        else {
            SWITCH_status = 1;
        }
    }
   
    if (SWITCH_status) {    // switch SWITCH on
        digitalWrite(2, HIGH);
        // checkbox is checked
        cl.println("<input type=“checkbox” name=“SWITCH2” value=“2”
        onclick=“submit();” checked>SWITCH2");
    }
    else {              // switch SWITCH off
        digitalWrite(2, LOW);
        // checkbox is unchecked
        cl.println("<input type=“checkbox” name=“SWITCH2” value=“2”
        onclick=“submit();”>SWITCH2");
    }
}

void ProcessCheckbox3(EthernetClient cl3)
{
    if (HTTP_req.indexOf(“SWITCH3=3”) > -1) {  // see if checkbox was clicked
        // the checkbox was clicked, toggle the SWITCH
        if (SWITCH_status3) {
            SWITCH_status3 = 0;
        }
        else {
            SWITCH_status3 = 1;
        }
    }
   
    if (SWITCH_status3) {    // switch SWITCH on
        digitalWrite(3, HIGH);
        // checkbox is checked
        cl3.println("<input type=“checkbox” name=“SWITCH3” value=“3”
        onclick=“submit();” checked>SWITCH3");
    }
    else {              // switch SWITCH off
        digitalWrite(3, LOW);
        // checkbox is unchecked
        cl3.println("<input type=“checkbox” name=“SWITCH3” value=“3”
        onclick=“submit();”>SWITCH3");
    }
}

void ProcessCheckbox5(EthernetClient cl5)
{
    if (HTTP_req.indexOf(“SWITCH5=5”) > -1) {  // see if checkbox was clicked
        // the checkbox was clicked, toggle the SWITCH
        if (SWITCH_status5) {
            SWITCH_status5 = 0;
        }
        else {
            SWITCH_status5 = 1;
        }
    }
   
    if (SWITCH_status5) {    // switch SWITCH on
        digitalWrite(5, HIGH);
        // checkbox is checked
        cl5.println("<input type=“checkbox” name=“SWITCH5” value=“5”
        onclick=“submit();” checked>SWITCH5");
       
    }
    else {              // switch SWITCH off
        digitalWrite(5, LOW);
        // checkbox is unchecked
        cl5.println("<input type=“checkbox” name=“SWITCH5” value=“5”
        onclick=“submit();”>SWITCH5");
    }
}