I thought it may be helpful to modify your sketch to make it easier to enhance. The following version creates a sensor class and that makes it simple to add sensors.
#include <DateTime.h>
#include <DateTimeStrings.h>
#define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
#define TIME_HEADER 255 // Header tag for serial time sync message
/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 60;
int pause = 5; //the time when the sensor outputs a low impulse, this is now in seconds
class SensorClass
{
private:
char sensorID;
byte pirPin;
byte ledPin;
boolean lockLow; // flag to indicate the sensor has gone low
boolean takeLowTime;
time_t lowIn; //the time the sensor transitioned from high to low
public:
SensorClass(byte, byte, byte );
void begin();
void checkMotionDetected();
void checkMotionEnded();
};
SensorClass SensorA('A',3,12); // sensor A on pin 3, led on pin 12
SensorClass SensorB('B',2,13); // sensor B on pin 2, led on pin 13
/////////////////////////////
//SETUP
void setup(){
Serial.begin(19200); // changed to 19200 to match the baud rate of the Processing sketch
DateTime.sync(1230768000); // set jan 1 2009 as the default time
SensorA.begin(); //Sensor A
SensorB.begin(); // Sensor B
//give the sensor some time to calibrate
Serial.print("Calibrating PIR Sensors A & B | 60 Seconds ");
for(int i = 0; i < calibrationTime; i++){
Serial.print("*");
delay(10); // !!todo was 1000;
}
Serial.println(" Finished");
Serial.println("SENSOR ACTIVE");
delay(50);
}
////////////////////////////
//LOOP
void loop(){
getPCtime(); // set the time if a time sync message is available on the serial port
SensorA.checkMotionDetected();
SensorA.checkMotionEnded();
SensorB.checkMotionDetected();
SensorB.checkMotionEnded();
}
////////////////////////////
// routines to output to the serial port
void printEvent(char sensorID, char * eventStr, time_t time){
Serial.print(eventStr);
Serial.print(" on ");
Serial.print("Sensor ");
Serial.print(sensorID);
Serial.print(" at "); //output
printTimeDate(time);
Serial.println();
}
void printTimeDate(time_t time){
byte sec,min,hour,hr,day,wday,month,year;
DateTime.localTime(&time,&sec,&min,&hour,&day,&wday,&month,&year);
// the following converts 24 hour time to 12 hour time
if( hour == 0 )
hr = 12; // 12 midnight
else if( hour > 12)
hr = hour - 12 ;
else
hr = hour ;
Serial.print(hr,DEC);
printDigits(min);
printDigits(sec);
Serial.print(" ");
Serial.print( hour < 12 ? "AM" : "PM");
Serial.print(" ");
Serial.print(day,DEC);
Serial.print(" ");
Serial.print(DateTimeStrings.monthStr(month));
Serial.print(" ");
Serial.print(year + 1900,DEC);
}
void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0
Serial.print(":");
if(digits < 10)
Serial.print('0');
Serial.print(digits,DEC);
}
boolean getPCtime() {
// if time sync available from serial port, update time and return true
while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
if( Serial.read() == TIME_HEADER ) {
time_t pctime = 0;
for(int i=0; i < TIME_MSG_LEN -1; i++){
char c= Serial.read();
if( c >= '0' && c <= '9'){
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
DateTime.sync(pctime); // Sync Arduino clock to the time received on the serial port
Serial.print("Clock set at ");
printTimeDate(DateTime.now());
return true; // return true if time message received on the serial port
}
}
return false; //if no message return false
}
////////////////////////////
/// sensor class
SensorClass::SensorClass(byte ID, byte pirpin, byte ledpin ){
this->sensorID = ID;
this->pirPin = pirpin;
this->ledPin = ledpin;
this-> lockLow = true;
}
void SensorClass::begin(){
pinMode(this->pirPin, INPUT);
pinMode(this->ledPin, OUTPUT);
digitalWrite(this.pirPin, LOW);
}
void SensorClass::checkMotionDetected(){
if(digitalRead(this->pirPin) == HIGH){
digitalWrite(this->ledPin, HIGH); //the led visualizes the sensors output pin state
if(this->lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
this->lockLow = false;
Serial.println("---");
printEvent(this->sensorID, "Motion detected", DateTime.now());
delay(50);
}
this->takeLowTime = true;
}
}
void SensorClass::checkMotionEnded(){
if(digitalRead(this->pirPin) == LOW){
digitalWrite(this->ledPin, LOW); //the led visualizes the sensors output pin state
if(this->takeLowTime){
this->lowIn = DateTime.now(); //save the time of the transition from high to LOW
this->takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause, we assume that no more motion is going to happen
if(!(this->lockLow) && DateTime.now() - this->lowIn > pause){
//makes sure this block of code is only executed again after a new motion sequence has been detected
this->lockLow = true;
printEvent(this->sensorID, "Motion ended", DateTime.now() - pause);
delay(50);
}
}
}