Help adding 3 more on/off switches so that I can control 4 LEDs This code is working fine to switch on/off one LED. Can anyone help me add 3 more on/off buttons so that I can control 4 LEDs?

#include &lt;String.h&gt;
#include &lt;SPI.h&gt;
#include &lt;Ethernet.h&gt;

byte mac[] = {
  0xDE , 0xAD , 0xBE , 0xEF , 0xFE , 0xED
};
byte ip[] = {
  192 , 168 , 2 , 20
};
byte gateway[] = { 
  192 , 168 , 2 , 1
};
byte subnet[] = { 
  255 , 255 , 255, 0
};
EthernetServer server(80);
String richiesta;
int pinLed = 9;

void setup() {
  Ethernet.begin(mac,ip,gateway,subnet);
  pinMode(pinLed,OUTPUT);
  Serial.begin(9600);
  richiesta = "";
}

void loop() {
  EthernetClient client = server.available();
  if(client) {
    Serial.println("Tujse na ho payega");
    while(client.connected()) {
      if(client.available()) {
        char c = client.read();
        richiesta.concat(c);
        if(c == '\n') {
          Serial.print(richiesta);
          if(richiesta.indexOf("Led=1")&gt;0) {
            Serial.println("Pin will be high");
            digitalWrite(pinLed,HIGH);
          } else {
            Serial.println("Pin will be low");
            digitalWrite(pinLed,LOW);
          }
          client.println("HTTP/1.1 200 ok");
          client.println("Content-Type: text/html");
          client.println();
          client.println("&lt;head&gt;&lt;title&gt; Home Automation&lt;/title&gt;&lt;/head&gt;");
          client.print("&lt;body&gt; &lt;a href='/?Led=1'&gt;ButtonOn &lt;/a&gt; &lt;a href='/?Led=0'&gt;Buttonoff &lt;/a&gt;&lt;/body&gt;");
          client.stop();
          richiesta = "";
        }
      }
    }
  }
}
Use arrays, one for switches, one for leds. I don't see the code for leds in your code.

Note that you need 8 pins (4 for switches, 4 for leds).

Initialize them, e.g.

int switchPins[] = { 2, 3, 4, 5 }; 

Same for leds

int ledPins[] = {6, 7, 8, 9};


To access them, use a for loop:

for (int iLed = 0; iLed &lt; 4; i++)
{
   digitalWrite(ledPins[iLed], HIGH);
}


Because 4 might be used a lot, consider them making const or define:

#define NR_OF_LEDS 4

for (int iLed = 0; iLed &lt; NR_OF_LEDS; i++)
{
   digitalWrite(ledPins[iLed], HIGH);
}


or use the length of the array

for (int iLed = 0; iLed &lt; sizeof(ledPins) / sizeof(int); i++)
{
   digitalWrite(ledPins[iLed], HIGH);
}