PIR sensor and gsm shield problem???

when my gsm shield is off my pir sensor work fine but when i turn gsm shield on PIR sensor doesnt work can anyone help me? this is my code

//#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include "gsm.h"
//#include "string.h"

#define DEBUG_CODE_ON
#define DEBUG_ACTION_ON

SMSGSM sms;


boolean started=false;
boolean startSMS=false;
char smsbuffer[160];
char n_in[16];
char n_ref[12];
char  msg[1];
char pompe_on[160] = "Pompeon";
char pompe_off[160] = "Pompeoff";
char vanne_on[160] = "Vanneon";
char vanne_off[160] = "Vanneoff";
int swtch=13;
int PIRSensor=2;
int incomingByte;
int val = 0;   


void setup() 
{
  
  // digit
  pinMode(swtch, OUTPUT);
 pinMode(PIRSensor, INPUT);

  //Serial connection.
  Serial.begin(9600);
  
  Serial.println("GSM Shield testing.");

  // GSM START
  if (gsm.begin(9600))
  {
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");
  
  if(started){
    #ifdef DEBUG_CODE_ON
    Serial.println("mise en ligne");
    #endif
    
    gsm.SimpleWriteln("AT+CMEE=2");
    delay(5000);
    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CMEE=2");
    gsm.WhileSimpleRead();
    #endif
//
// PIN CODE
//
    #ifdef DEBUG_CODE_ON
    Serial.println("PIN CODE");
    #endif

 
//if (gsm.SendATCmdWaitResp("AT+CPIN ?", 1000, 100, "READY", 5) != 1 ) 
//      {
      gsm.SimpleWriteln("AT+CPIN=2343");
      delay(5000);
      #ifdef DEBUG_CODE_ON
      Serial.print("AT+CPIN=####");
      gsm.WhileSimpleRead();
      #endif
//      }

//
// INIT FOR SEND SMS
//
    gsm.SimpleWriteln("AT+CLIP=1");
    delay(500);
    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CLIP=1");
    gsm.WhileSimpleRead();
    #endif

   
    gsm.SimpleWriteln("AT+CSCA ?");
    delay(5000);
    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CSCA ?");
    gsm.WhileSimpleRead();
    #endif
       
    gsm.SimpleWriteln("AT+CMGF=1");
    delay(5000);
    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CMGF=1");
    gsm.WhileSimpleRead();
    #endif

//
// CMD LOW
//
    #ifdef DEBUG_ACTION_ON
    Serial.println("INIT PUMP");
    #endif
    digitalWrite(swtch, LOW);
    
   

  }
  
  

};



}
void loop() 
{ if(digitalRead(PIRSensor)==HIGH){   // read the input pin
  digitalWrite(swtch, HIGH);      // sets the LED to the button's value
  delay(1000);    
digitalWrite(swtch, LOW);   // delay in milisecond. 3000 = 3 second
  }
  if(started){
    
 
  }
};
char pompe_on[160] = "Pompeon";
char pompe_off[160] = "Pompeoff";
char vanne_on[160] = "Vanneon";
char vanne_off[160] = "Vanneoff";

Is there some reason you create 160 byte arrays to hold a maximum of 9 bytes each?

I don't know how much SRAM the SoftwareSerial, gsm and sms libraries use, but you are wasting a heck of a lot of a very limited resource.

no there is no special reason to use this much of byte by the way how much i should use? because sometime gsm respond very late and why pir sensor not working.....?

no there is no special reason to use this much of byte by the way how much i should use?

You trust the compiler to generate code that sends SMSs, but you don’t trust it to count the number of initializers you provide? You need to get over that distrust. Leave the empty, and let the compiler figure out the needed size.

no there is no special reason to use this much of byte by the way how much i should use?

You have a major flaw in your code. Go fix that. Test it, and come back and let us know the results.

If you still have a problem, we’ll look at the code again.

please check this code when i turn on gsm shield led also turn on and keep on and still PIR sensor not working :frowning:

//#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include "gsm.h"
//#include "string.h"

#define DEBUG_CODE_ON
#define DEBUG_ACTION_ON

SMSGSM sms;


boolean started=false;
boolean startSMS=false;
char smsbuffer[8];
char n_in[16];
char n_ref[12];
char  msg[1];
char pompe_on[] = "Pompeon";
char pompe_off[] = "Pompeoff";
int swtch=13;
int PIRSensor=2;
int incomingByte;
int val = 0;   


void setup() 
{
  
  // digit
  pinMode(swtch, OUTPUT);
 pinMode(PIRSensor, INPUT);

  //Serial connection.
  Serial.begin(9600);
  
  Serial.println("GSM Shield testing.");

  // GSM START
  if (gsm.begin(9600))
  {
    Serial.println("\nstatus=READY");
    started=true;  
  }
  else Serial.println("\nstatus=IDLE");
  
  if(started){
    #ifdef DEBUG_CODE_ON
    Serial.println("mise en ligne");
    #endif
    
    gsm.SimpleWriteln("AT+CMEE=2");
    delay(5000);
    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CMEE=2");
    gsm.WhileSimpleRead();
    #endif
//
// PIN CODE
//
    #ifdef DEBUG_CODE_ON
    Serial.println("PIN CODE");
    #endif

 
//if (gsm.SendATCmdWaitResp("AT+CPIN ?", 1000, 100, "READY", 5) != 1 ) 
//      {
      gsm.SimpleWriteln("AT+CPIN=2343");
      delay(5000);
      #ifdef DEBUG_CODE_ON
      Serial.print("AT+CPIN=####");
      gsm.WhileSimpleRead();
      #endif
//      }

//
// INIT FOR SEND SMS
//
    gsm.SimpleWriteln("AT+CLIP=1");
    delay(500);
    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CLIP=1");
    gsm.WhileSimpleRead();
    #endif

   
    gsm.SimpleWriteln("AT+CSCA ?");
    delay(5000);
    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CSCA ?");
    gsm.WhileSimpleRead();
    #endif
       
    gsm.SimpleWriteln("AT+CMGF=1");
    delay(5000);
    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CMGF=1");
    gsm.WhileSimpleRead();
    #endif

//
// CMD LOW
//
    #ifdef DEBUG_ACTION_ON
    Serial.println("INIT PUMP");
    #endif
    digitalWrite(swtch, LOW);
    
   

  }
  
  

};
void PIRsensor(){
    if(digitalRead(PIRSensor)==HIGH){   // read the input pin
  digitalWrite(swtch, HIGH);      // sets the LED to the button's value
  delay(1000);    
digitalWrite(swtch, LOW);   // delay in milisecond. 3000 = 3 second
  }


}
void loop() 
{ 
  if(started){
    if(digitalRead(PIRSensor)==HIGH){   // read the input pin
  digitalWrite(swtch, HIGH);      // sets the LED to the button's value
  delay(1000);    
digitalWrite(swtch, LOW);   // delay in milisecond. 3000 = 3 second
  }
 
  }
  /*
 
if(started)
    {
      
      
    
//    
// READ SMS
//
    #ifdef DEBUG_ACTION_ON
     Serial.println("Wait Read sms");
    #endif

    if(gsm.readSMS(smsbuffer, 16, n_in, 12))
    {
      #ifdef DEBUG_ACTION_ON
      Serial.println(n_in);
      Serial.println(smsbuffer);
      #endif
      startSMS=true;
      //
      // filter num gsm
      //
      /*
      if (memcmp(n_in,n_ref,11)==0)
      {
        #ifdef DEBUG_ACTION_ON
        Serial.println("Sender ok");
        #endif
        // ok
        startSMS=true;
      }
      */
      /*
    }
    
  
   //  
   // Action
   //
     if (startSMS){

  //
  // pump 
  //


    if (memcmp(smsbuffer,pompe_on,7)==0) 
    {
      digitalWrite(swtch, HIGH); 
      #ifdef DEBUG_ACTION_ON
      Serial.println("Pump On"); 
      #endif
    }
    
    if (memcmp(smsbuffer,pompe_off,7)==0) 
    {
      
       digitalWrite(swtch, LOW); 
       delay (100);
       PIRsensor();
     
      #ifdef DEBUG_ACTION_ON
      Serial.println("Pump Off");
      #endif
       
    }
 
  

//
// valve
//



    



     startSMS=false;
     // clear SMS
     gsm.SimpleWriteln("AT+CMGL=\"REC UNREAD\",0");

     }

      }
      delay(500);
 
*/
};
  pinMode(swtch, OUTPUT);

What kind of switch are you writing to?

    #ifdef DEBUG_CODE_ON
    Serial.println("mise en ligne");
    #endif

    #ifdef DEBUG_CODE_ON
    Serial.print("AT+CMEE=2");
    gsm.WhileSimpleRead();
    #endif

I refuse to guess how you have defined this variable.

  }
  
  

};

Are all these blank lines really necessary? Why is there a ; lurking there?

Is all that commented out code related to your problem, or not? If not, DELETE IT!. It's impossible to tell what is supposed to be being executed, and what isn't. Perhaps you've noticed that the code you post here is not colored the same way it is in the Arduino IDE.

I don't see where you do or do not turn the gsm shield on.

Have you written a simple sketch to verify that the PIR sensor is connected correctly, and reading the appropriate pin returns the expected values?

when i put code like this when i turn on my gsm shield PIR sensor is not working.

#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include "gsm.h"
#include "string.h"
#define DEBUG_CODE_ON
#define DEBUG_ACTION_ON
SMSGSM sms;
boolean started=false;
boolean startSMS=false;
char smsbuffer[8];
char n_in[8];
char pompe_on[] = "Pompeon";
char pompe_off[] = "Pompeoff";
int led=13;
int PIRSensor=2;
void setup() 
{  
  // digit
  pinMode(led, OUTPUT);
 pinMode(PIRSensor, INPUT);
  //Serial connection.
  Serial.begin(9600);  
  Serial.println("GSM Shield testing.");
  // GSM START
  if (gsm.begin(9600))
  {
    Serial.println("\nstatus=READY");
    started=true;  
  }
}
void loop() 
{ 

  if(started){
    if(digitalRead(PIRSensor)==HIGH){   // read the input pin
      digitalWrite(led, HIGH);      // sets the LED to the button's value
      delay(1000);    
      digitalWrite(led, LOW);   // delay in milisecond. 3000 = 3 second
    }
 
  }
}

but when i put this code like this then if gsm shield is off PIR sensor is working but not working when gsm shield is on

void loop() 
{ 
   if(digitalRead(PIRSensor)==HIGH){   // read the input pin
      digitalWrite(led, HIGH);      // sets the LED to the button's value
      delay(1000);    
      digitalWrite(led, LOW);   // delay in milisecond. 3000 = 3 second
    }

  if(started){
 
 
  }

}

How are you powering everything? The gsm shields require quite a lot of current, as I recall.

what u mean powering everything? i hav connected gsm shield with arduino uno and connected with laptop using cable

what u mean powering everything? i hav connected gsm shield with arduino uno and connected with laptop using cable

If you wish to be taken seriously here, you will quit using text-speak. The usual recommendation is to add an external power supply to power the GSM shield. It draws more power than the Arduino or USB cable can supply.