Mega 2560 + RFID + Ehternet stop working

Hello i have a Mega 2560 with RFID and ethernet shield W5100. The mega is one allarm system and when start a siren the system send one http request to ifttt.com.

Some time the ethernet shield stop working and I have not response from ping command.

I try to change the ethernet shied with a new, but the problem is the same.

Can you help me? Thanks

Most ethernet shields need specific pins.
make sure they are no interfering with communications.

Also post the sketch you are using but please use code tags ( </> ) as the forum can chew up code without them.

Ok, this is the fist part of code:

#include <SPI.h>
#include <Ethernet.h>
#include <MFRC522.h>
#define SS_PIN 49 
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN);  
String ApprovedCard[] = { "123456", "000000", "1565489" };
boolean SystemState = false;

boolean boolSensor1 = false;
boolean boolSensor2 = false;
boolean boolSensor3 = false;
boolean boolSensor4 = false;
boolean boolSensor5 = false;
boolean boolSensor6 = false;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 100);
IPAddress subnet(255, 255, 255, 0);
IPAddress gateway(192, 168, 0, 1);
IPAddress dnServer(192, 168, 0, 1);
EthernetClient client;
-------------

int Rele1 = 40;	
int Rele2 = 41;	
int Rele3 = 42;	
int Rele4 = 43;
int Rele5 = 44;	
int Rele6 = 45;	
int Rele7 = 46;	
int Rele8 = 47;	

int Sensor1 = 30; 
int Sensor2 = 31; 
int Sensor3 = 32; 
int Sensor4 = 33; 
int Sensor5 = 34; 
int Sensor6 = 26; 

int ledRed = 6;
int ledGreen = 5;
int ledBlu = 4;
int Buzzer = 7;
int AllarmCounter = 0;

String MSGSensor1 = "Sensor1";
String MSGSensor2 = "Sensor2";
String MSGSensor3 = "Sensor3";
String MSGSensor4 = "Sensor4";
String MSGSensor5 = "Sensor5";
String MSGSensor6 = "Sensor6";

void setup() {
	Serial.begin(9600); // Initialize serial communications with the PC
	SPI.begin();      // Init SPI bus
	mfrc522.PCD_Init(); // Init MFRC522 card 

	Ethernet.begin(mac, ip, dnServer, gateway, subnet);
	Serial.print("IP = ");
	Serial.println(Ethernet.localIP());
	delay(1000); 
	Serial.println("connecting...");

	pinMode(ledRed, OUTPUT);
	pinMode(ledGreen, OUTPUT);
	pinMode(ledBlu, OUTPUT);
	pinMode(Buzzer, OUTPUT);

	pinMode(Sensor1, INPUT);
	pinMode(Sensor2, INPUT);
	pinMode(Sensor3, INPUT);
	pinMode(Sensor4, INPUT);
	pinMode(Sensor5, INPUT);
	pinMode(Sensor6, INPUT);

	pinMode(Rele1, OUTPUT);
	pinMode(Rele2, OUTPUT);
	pinMode(Rele3, OUTPUT);
	pinMode(Rele4, OUTPUT);
	pinMode(Rele5, OUTPUT);
	pinMode(Rele6, OUTPUT);
	pinMode(Rele7, OUTPUT);
	pinMode(Rele8, OUTPUT);

	PowerOFFled(ledRed);
	PowerONled(ledGreen);
	PowerOFFled(ledBlu);

	analogWrite(Buzzer, 0);

	PowerOFFRele(Rele1);
	PowerOFFRele(Rele2);
	PowerOFFRele(Rele3);
	PowerOFFRele(Rele4);
	PowerOFFRele(Rele5);
	PowerOFFRele(Rele6);
	PowerOFFRele(Rele7);
	PowerOFFRele(Rele8);

	Serial.println("system Ready!");
	GetHttpRequest("/trigger/allarmOn/with/key/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
	ActiveSystem();
}

void loop() {
  if(SystemState){
	if(digitalRead(Sensor1) == LOW && boolSensor1 == true){Allarm(0,MSGSensor4);}     //Allarm, delay 0sec
	if(digitalRead(Sensor2) == LOW && boolSensor2 == true){Allarm(0,MSGSensor4);}     //Allarm, delay 0sec
	if(digitalRead(Sensor3) == LOW && boolSensor3 == true){Allarm(0,MSGSensor4);}     //Allarm, delay 0sec
	if(digitalRead(Sensor4) == LOW && boolSensor4 == true){Allarm(0,MSGSensor4);}     //Allarm, delay 0sec
	if(digitalRead(Sensor5) == LOW && boolSensor5 == true){Allarm(0,MSGSensor4);}     //Allarm, delay 0sec
	if(digitalRead(Sensor6) == LOW && boolSensor6 == true){Allarm(15,MSGSensor4);}    //Allarm, delay 15sec
  }
  ReadNFC();
}

this is the second part:

void SetSystemState(){
  if(SystemState){
  DeactiveSystem();
  }else{
    ActiveSystem();
  }
}

void ActiveSystem () {
	AllarmCounter = 0;
	SystemState = true;
	PowerOFFled(ledGreen);
  
	PowerONRele(Rele3); 
	delay(300);
	PowerOFFRele(Rele3);
  
  for (int i =0; i< 75; i++) {
    delay(500);
	ChangeState(ledRed);
    delay(500);
    Serial.println(i);
    
    ReadNFC();
    if(!SystemState){
		return;
    }
	
  }  
	PowerONRele(Rele1);
    
  	PowerONRele(Rele6); 
	PowerONRele(Rele7); 
	PowerONRele(Rele8); 
	delay(300);
	PowerOFFRele(Rele6);
	PowerOFFRele(Rele7);
	PowerOFFRele(Rele8);
	delay(600);
	PowerONRele(Rele6); 
	PowerONRele(Rele7); 
	PowerONRele(Rele8); 
	delay(300);
	PowerOFFRele(Rele6);
	PowerOFFRele(Rele7);
	PowerOFFRele(Rele8);
  
  CheckSensorState();
  PowerONled(ledRed);
  GetHttpRequest("/trigger/allarmOn/with/key/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  Serial.println("System Actived!");
}

void DeactiveSystem () {
  SystemState = false;
  PowerOFFled(ledRed);
  PowerOFFRele(Rele1);
  
    PowerONRele(Rele2); 
	delay(300);
	PowerOFFRele(Rele2);
  
  
  GetHttpRequest("/trigger/allarmOff/with/key/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
  Serial.println("System Deactived!");
  
  int var = 0;
	while(var < AllarmCounter){
		delay(200);
		PowerONled(ledGreen);
		analogWrite( Buzzer, 20);
		delay(200);
		PowerOFFled(ledGreen);
		analogWrite( Buzzer, 0);
		ReadNFC();
		delay(200);
		var++;
	}
  AllarmCounter = 0;
  PowerONled(ledGreen);
}

void Allarm(int strDelay, String strSensor) {
  Serial.println(strSensor);
  for (int i =0; i< strDelay; i++) {
    Serial.println(i);
    delay(250);
	ReadNFC();
	delay(250);
	ReadNFC();
	delay(250);
	ReadNFC();
	delay(250);
    if(!SystemState){
		return;
    }
  }
  Siren(10);
}


void Siren(int strTime) {
	GetHttpRequest("/trigger/allarm/with/key/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
 	Serial.println("Sirena ON");
	AllarmCounter++;
	Serial.println(AllarmCounter);
	for (int i =0; i< strTime; i++) {
		ChangeState(ledRed);
		analogWrite( Buzzer, 20);
		delay(250);
		ChangeState(ledRed);
		analogWrite( Buzzer, 0);
		delay(250);
		
		ReadNFC();
		delay(400);
	  
		if(!SystemState){
		  Serial.println("Sirena OFF");
		  //PowerOFFRele(Rele5);
		  return;
		}
	}
  //PowerOFFRele(Rele5);
  Serial.println("Sirena OFF");
  Serial.println("System Active!");
}


void ChangeState(int portNumber){
	if(digitalRead(portNumber) == HIGH){
		digitalWrite( portNumber, LOW); 
	}else{
		digitalWrite( portNumber, HIGH);
	}
}

void PowerOFFled(int portNumber){
    digitalWrite( portNumber, HIGH); 
}

void PowerONled(int portNumber){
    digitalWrite( portNumber, LOW); 
}

void PowerONRele(int portNumber){
    digitalWrite( portNumber, LOW); 
}

void PowerOFFRele(int portNumber){
    digitalWrite( portNumber, HIGH); 
}

void ReadNFC(){
	//Serial.println("Read NFC");
	// Look for new cards
	if ( ! mfrc522.PICC_IsNewCardPresent()) {
	return;
	}
	// Select one of the cards
	if ( ! mfrc522.PICC_ReadCardSerial()) {
	return;
	}
	// Dump debug info about the card. PICC_HaltA() is automatically called.
	//mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
	String IDCard ="";
	for (byte i = 0; i < mfrc522.uid.size; i++){
	IDCard+= String (mfrc522.uid.uidByte[i],HEX);
	}
	IDCard.toUpperCase();
	Serial.print("Code: ");
	Serial.println(IDCard);
	VerifyCode(IDCard);
	delay(100); 
}


void VerifyCode(String keycode){
  boolean Approved = false;
  for (int i =0; i< sizeof(ApprovedCard); i++) {
    if(keycode == ApprovedCard[i]) {
      Approved = true;
      break;
    }
  }
  if(Approved){
		PowerONled(ledRed);
		analogWrite(Buzzer, 20);
		PowerOFFled(ledGreen);
		delay(700);
		analogWrite(Buzzer, 0);
		PowerONled(ledGreen);

		SetSystemState();
	}else{ 
		for (int i =0; i< 4; i++) {
			analogWrite(Buzzer, 20);
			ChangeState(ledRed);
			delay(100);
			analogWrite(Buzzer, 0);
			ChangeState(ledRed);
			delay(100);
		}
		Serial.println("Code or TAG invalid");
	}
}

void CheckSensorState(){
    if(digitalRead(Sensor1) == HIGH){boolSensor1 = true,Serial.println("boolSensor1 ok!");} else {boolSensor1 = false,Serial.println("boolSensor1 not actived!");}
    if(digitalRead(Sensor2) == HIGH){boolSensor2 = true,Serial.println("boolSensor2 ok!");} else {boolSensor2 = false,Serial.println("boolSensor2 not actived!");}
    if(digitalRead(Sensor3) == HIGH){boolSensor3 = true,Serial.println("boolSensor3 ok!");} else {boolSensor3 = false,Serial.println("boolSensor3 not actived!");}
    if(digitalRead(Sensor4) == HIGH){boolSensor4 = true,Serial.println("boolSensor4 ok!");} else {boolSensor4 = false,Serial.println("boolSensor4 not actived!");}
    if(digitalRead(Sensor5) == HIGH){boolSensor5 = true,Serial.println("boolSensor5 ok!");} else {boolSensor5 = false,Serial.println("boolSensor5 not actived!");}
    if(digitalRead(Sensor6) == HIGH){boolSensor6 = true,Serial.println("boolSensor6 ok!");} else {boolSensor6 = false,Serial.println("boolSensor6 not actived!");}
	Serial.println("check sensors finish");
}

void GetHttpRequest(String strUrl){
	if (client.connect("maker.ifttt.com", 80)) {
		client.println("GET " + strUrl + " HTTP/1.1");
		client.println("Host: maker.ifttt.com");
		client.println("Connection: close");
		client.println();
		int i = 0;
		while (!client.available()) {			
			delay(10);
			i++;
			if(client.available() || i == 300) break;
		}
		if (client.available()) {
			while(client.available()){
				char c = client.read();
				//Serial.print(c);
			}
		}
	} else {
		//Serial.println("Connection to: maker.ifttt.com failed!!!");
	}
	if (!client.connected()) {
		//Serial.println();
		//Serial.println("disconnecting.");
		client.stop();
	}
	while(Serial.available()){Serial.read();}									  
}

help me please :confused: !