Arduino issues using ethernet shield with sonar sensor

Hi , i got an issue using the arduino with the ethernet shield and sonar sensor , when i use the ethernet shield alone to turn on - off leds using the netio app it works great with no problems but when i add a function to detect motion with the sonar and turn the led , the networking part stops working , i just got destination unreachable , tested shield and sonar using the same enviroment (router , ports)

Im using this code

#include <SPI.h>
#include <Ethernet.h>
#define DEBUG 0 
#define trigPin 12
#define echoPin 13
//int Buzzer = 9;

byte mac[] = { 0xDA, 0xA2, 0xDA, 0x00, 0x4A, 0x10 };   
IPAddress ip(192,168,100,20);                  
IPAddress gateway(192,168,100,1);

#define BUFSIZ 64
EthernetServer teserver(1479);  

void setup(){
  Serial.begin(9600);   
  Ethernet.begin(mac, ip, gateway);
  pinMode(2, OUTPUT);     
  digitalWrite(2, LOW); 
  pinMode(3, OUTPUT);     
  digitalWrite(3, LOW);
  pinMode(4, OUTPUT);     
  digitalWrite(4, LOW);
  pinMode(5, OUTPUT);     
  digitalWrite(5, LOW);
  pinMode(6, OUTPUT);     
  digitalWrite(6, LOW);
  pinMode(7, OUTPUT);     
  digitalWrite(7, LOW); 
  pinMode(8, OUTPUT);     
  digitalWrite(8, LOW); 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  //pinMode(Buzzer, OUTPUT);
  delay(1000);           
  teserver.begin();  
  delay(1000);          
}

void loop()
{

  luces();
  sensor();
}                
 
void luces()
{
       
      int index = 0;                                             
      char Remote[BUFSIZ];
      EthernetClient client = teserver.available();
      if (client) {  
            if (client.connected()) {
                  while (client.available()) {
                          char c = client.read();
                          if (c != '\n' && c != '\r') {           
                                    Remote[index] = c;
                                    index++;
                                    if (index >= BUFSIZ) 
                                      index = BUFSIZ -1;
                                    continue;
                                  }            
                          Remote[index] = 0;
                  }
        
                  //if(DEBUG){
                          //   Serial.println(" "); 
                          //   Serial.print("string recieved from phone: ");   
                          //   Serial.println(Remote);  
                 // }
                   if (strstr(Remote, "ctmaster_on")) {                           
                         client.println("OK");
                         digitalWrite(2, HIGH );
                         //if(DEBUG)Serial.println("> turned led2 on!");             
                   }
                      
                   if (strstr(Remote, "ctmaster_off")) {                         
                         client.println("OK");
                         digitalWrite(2, LOW );
                         //if(DEBUG)Serial.println("> turned led2 off!");             
                   }
      
                   if (strstr(Remote, "ctinvitado_on")) {                            
                         client.println("OK");
                         digitalWrite(3, HIGH );
                         //if(DEBUG)Serial.println("> turned led3 on!");             
                   }
                      
                   if (strstr(Remote, "ctinvitado_off")) {                           
                         client.println("OK");
                         digitalWrite(3, LOW );
                         //if(DEBUG)Serial.println("> turned led3 off!");             
                   }
                   
                   if (strstr(Remote, "sala_on")) {                           
                         client.println("OK");
                         digitalWrite(4, HIGH );
                         //if(DEBUG)Serial.println("> turned led4 on!");             
                   }
                      
                   if (strstr(Remote, "sala_off")) {                           
                         client.println("OK");
                         digitalWrite(4, LOW );
                         //if(DEBUG)Serial.println("> turned led4 off!");             
                   }
                      
                   if (strstr(Remote, "comedor_on")) {                            
                         client.println("OK");
                         digitalWrite(5, HIGH );
                         //if(DEBUG)Serial.println("> turned led5 on!");             
                   }
                      
                   if (strstr(Remote, "comedor_off")) {                          
                         client.println("OK");
                         digitalWrite(5, LOW );
                         //if(DEBUG)Serial.println("> turned led5 off!");             
                   }
                               
                   if (strstr(Remote, "luzfrontal_on")) {                           
                         client.println("OK");
                         digitalWrite(6, HIGH );
                         //if(DEBUG)Serial.println("> turned led6 on!");             
                   }
                      
                   if (strstr(Remote, "luzfrontal_off")) {                           
                         client.println("OK");
                         digitalWrite(6, LOW );
                         //if(DEBUG)Serial.println("> turned led6 off!");             
                   }
                                      
                   if (strstr(Remote, "luzpatio_on")) {                           
                         client.println("OK");
                         digitalWrite(7, HIGH );
                         //if(DEBUG)Serial.println("> turned led7 on!");             
                   }
                      
                   if (strstr(Remote, "luzpatio_off")) {                         
                         client.println("OK");
                         digitalWrite(7, LOW );
                         //if(DEBUG)Serial.println("> turned led7 off!");             
                   }
                   
                   if (strstr(Remote, "all_off")) {                           
                         client.println("OK");
                         digitalWrite(2, LOW );
                         digitalWrite(3, LOW );
                         digitalWrite(4, LOW );
                         digitalWrite(5, LOW );
                         digitalWrite(6, LOW );
                         digitalWrite(7, LOW );
                         //if(DEBUG)Serial.println("> apagar todas las luces!");             
                   }
                   if (strstr(Remote, "night_on")) {                           
                         client.println("OK");
                         digitalWrite(5, HIGH );
                         digitalWrite(6, HIGH );
                         digitalWrite(7, HIGH );
                         //if(DEBUG)Serial.println("> luces de noche!");             
                   }
                              
            }    
      } 
}

void sensor()
{
  int duration, cm;
  pinMode(trigPin, OUTPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
 
  cm = duration / 29 / 2;

  if (cm < 20)
  {
    digitalWrite(8, HIGH );
    //tone(Buzzer, 400);
   }
   else
   {
     digitalWrite(8,LOW);
     //noTone(Buzzer);
   }
  //Serial.print(cm);
  //Serial.print("cm");
  //Serial.println();      
  //delay(1000);
}

thanks in advance for any help on this , im doing a project for college grad and im stuck on this part
Fernando

The ethernet shield uses pins 12 and 13...

Also 10 and 11, for that matter. and 4 for the SD card

(EDIT.... pins 10-13 are SPI pins, not just the E'net card, btw)

Thanks for your reply , so PINS 10 to 13 cannot be used for any other LED , sensor , etc?
i got to connect 1 more sensors ,a servo and a dc motor, with the current config Icannot do it ?

Apologies for so many questions but im new on this and would be cool to have all this concepts clear

Thanks in advance

Yep that's about the gist of it. But remember that the 6x analog pins over on the other side can be used as digital pins too.

thanks JimboZA you made my day , im going to search for how to set the analog pins and test

Reference page says:

The analog input pins can be used as digital pins, referred to as A0, A1, etc.

So you just do a pinMode(A3, INPUT); and digitalRead(A3); for example.