// Pir Sensor
 int PIR= 7; // Pir Sensor
 int LED= 12;   // LED 
 
 void setup(){
 pinMode(PIR, INPUT);
 pinMode(LED, OUTPUT);
 digitalWrite(LED, LOW) ; 
}

void loop() {

int val= digitalRead(PIR);
  
  if (val == 1) { 
  digitalWrite(LED, HIGH) ; 
  } 

if (val==0) {                
 digitalWrite(LED, LOW) ;   
 } 
  
 delay(1000) ;
}

 

// Pir Sensor
 int inputPin= 7; // Pir Sensor
 int outPin= 12;   // LED 
 long T1, T2, Del ;
 int n, c, val ;
  
 void setup(){
 Serial.begin(9600) ;
 pinMode(inputPin, INPUT_PULLUP);
 pinMode(outPin, OUTPUT);
}

void loop() {
 val= digitalRead(inputPin);
  Serial.print(" val = ") ;
  Serial.println(val) ;

 if (val == 1) {  
    if ( c==0 ) { 
      T1 = millis() ;  
      }       
  digitalWrite(12, HIGH) ; 
   c++ ;
   n= 0 ;
  } // end of (val == 1)

if (val==0) {       
      if (n==0) {
       T2 = millis() ;
       Del = T2-T1 ;
       Serial.print("   Del= ") ;
       Serial.println(Del) ;   
      }          
 digitalWrite(12, LOW) ;   
 c=0 ; 
 n++ ;
 } // end of (val == 0)    
 delay(1000) ;
} // ====== end of loop =========