Multi-zone wireless PIR system with SMS notifying

I'm working up a low power, easily (hopefully) implemented intrusion detection system that uses a cheap cell phone for sms notifications. This is for installation in attractive nuisance buildings that don't have power or network connections available.

The Visionic MCR308 handles their proprietary wireless com with sensors (in my case battery powered PIR's) and outputs four separate zone signals as well as a tamper, inactivity, low battery and RF jamming signal. It seems to integrate superbly easily into the Arduino, I've successfully played tests with flashing led's for the different zones.

I am using the Sserial2mobile library successfully to handle sending SMS through a pay as you go sim chip.

However, I'm new to programming, and "processing" sketches in particular and am having trouble getting from the single threaded thought process in most of the examples to one that is more versatile.

Ideally I would like to constantly monitor the input pins for action (they get held high for about two seconds by the Visionic) and store any successive action in an array or something with time differentials so I can characterize the pattern of movement between the zones before I send an SMS with that information.

The simple thing would be just to send an SMS for each trigger, however, the process of handling the SMS takes around a minute depending on how crazy I get with power saving... Does that mean that I can't record other state changes during that time? Am I going to have to get crazy with interrupts or just live with the big pause?

The following code is really just to give an idea of where I'm starting, I can read the inputs, and I can send text messages... this is my blank canvas upon which I've really just started to define my variables.

I'm sure there are good examples of handling multiple digital inputs that all act on a single conditional output, I just can't seem to locate them.

/*
 Example of SSerial2Mobile libary 

Sends a SMS and an email
The SMS phone number and the email address need to be changed to something valid. 

 created 21 June 2008
 by Gustav von Roth 
*/

/*
I modified the end of the MOT-C168i.h file by adding:

//This little tickle command helps get the phone's serial port awake before responding to important commands. It is the same one (+++) used to get a modem's attention normally.
#define PHONE_TICKLE_BEFORE_SENDING_COMMAND "AT+++"

Also added:
        println(PHONE_TICKLE_BEFORE_SENDING_COMMAND);
        delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
at the beginning of the sendTxt, sendEmail, off, on and reset methods in SSerial2Mobile.cpp.
*/

#include <ATT.h>
#include <MOT-C168i.h>
#include <SoftwareSerial.h>
#include <SSerial2Mobile.h>

#define RXpin 0
#define TXpin 1

SSerial2Mobile phone = SSerial2Mobile(RXpin,TXpin);

int ledPin = 13;                // choose the pin for the LED for testing purposes

int zone1 = 2;                  // choose the input pin for zone 1 from Visionic MCR-308
int zone2 = 3;                  // choose the input pin for zone 2 from Visionic MCR-308
int zone3 = 4;                  // choose the input pin for zone 3 from Visionic MCR-308
int zone4 = 5;                  // choose the input pin for zone 4 from Visionic MCR-308
int tamper = 6;                // choose the input pin for Tamper signal from Visionic MCR-308
int inactivity = 7;            // choose the input pin for Inactivity signal from Visionic MCR-308
int loBatt = 8;                // choose the input pin for Low Battery signal from Visionic MCR-308
int jamm = 9;                  // choose the input pin for RF Jamming signal from Visionic MCR-308
int val = 0;                   // variable for reading the pin status


void setup() {
  pinMode(ledPin, OUTPUT);        // declare LED as output
  pinMode(zone1, INPUT);         // declare zone1 as input
  pinMode(zone1, INPUT);
  pinMode(zone2, INPUT);
  pinMode(zone3, INPUT);
  pinMode(zone4, INPUT);
  pinMode(tamper, INPUT);
  pinMode(inactivity, INPUT);
  pinMode(loBatt, INPUT);
  pinMode(jamm, INPUT);
  
}

void loop(){
  val = digitalRead(tamper);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH); // turn LED ON
    delay(500);
    digitalWrite(ledPin, LOW);  // turn LED OFF
    delay(500);
  }

//  phone.sendTxt("+1xxxxxxxxxx","Now with a +++ tickler in code!");
//  delay(30000);
//  phone.on();
  
}

Welp, to carry on the conversation with myself...

As my parallel needs seem to be pretty well met by the fact that the Arduino does not need to monitor the SMS process, I can probably just use millis() to get the phone going while I continue to handle monitoring sensors and then endure a brief pause during the serial processing to send the actual message.

I think that will work pretty well, now I just need to store the sensor triggers, and possibly also time differentials and sequence between them to give me an idea how a perpetrator is moving through the zones.

Getting closer. If this is of any value to anyone, I'll share it here, otherwise I'll stop blabbing.

I think I'm making progress. My current challenge is to try and track the order in which my inputs go high. I'm considering populating an unsized array with the consecutive state changes. Is there a better way? Anybody have any examples of a simple logger?

/*
 Example of SSerial2Mobile libary 

Sends a SMS and an email
The SMS phone number and the email address need to be changed to something valid. 

 created 21 June 2008
 by Gustav von Roth 
*/

/*
I modified the end of the MOT-C168i.h file by adding:

//This little tickle command helps get the phone's serial port awake before responding to important commands. It is the same one (+++) used to get a modem's attention normally.
#define PHONE_TICKLE_BEFORE_SENDING_COMMAND "AT+++"

Also added:
        println(PHONE_TICKLE_BEFORE_SENDING_COMMAND);
        delay(PHONE_DELAY_AFTER_SENDING_COMMAND_VALUE);
at the beginning of the sendTxt, sendEmail, off, on and reset methods in SSerial2Mobile.cpp.
*/

#include <ATT.h>
#include <MOT-C168i.h>
#include <SoftwareSerial.h>
#include <SSerial2Mobile.h>


#define RXpin 0
#define TXpin 1

SSerial2Mobile phone = SSerial2Mobile(RXpin,TXpin);

int ledPin = 13;                // choose the pin for the LED for testing purposes

int zone1 = 2;                  // choose the input pin for zone 1 from Visionic MCR-308
int zone2 = 3;                  // choose the input pin for zone 2 from Visionic MCR-308
int zone3 = 4;                  // choose the input pin for zone 3 from Visionic MCR-308
int zone4 = 5;                  // choose the input pin for zone 4 from Visionic MCR-308
int tamper = 6;                // choose the input pin for Tamper signal from Visionic MCR-308
int inactivity = 7;            // choose the input pin for Inactivity signal from Visionic MCR-308
int loBatt = 8;                // choose the input pin for Low Battery signal from Visionic MCR-308
int jamm = 9;                  // choose the input pin for RF Jamming signal from Visionic MCR-308
int val = 0;                   // variable for reading the pin status

int zn1 = 0;                  // Define holding variables for sensors
int old_zn1 = 0;              // Define holding variables to detect state change
int zn2 = 0;
int old_zn2 = 0;
int zn3 = 0;
int old_zn3 = 0;
int zn4 = 0;
int old_zn4 = 0;
int tmpr = 0;
int old_tmpr = 0;
int inac = 0;
int old_inac = 0;
int batt = 0;
int old_batt = 0;
int jam = 0;
int old_jam = 0;

int phoneState = 0;                  // variable to hold the state of the phone, 
                                     // 0 = off, 1 = ready, 2 = sending

unsigned long trigger_time = 0;      // variable to hold the time that the alarm is triggered
unsigned long trigger_delay = 60000;  // variable that holds the delay time for the trigger, one minute.
unsigned long now = 1;               // variable to hold millis() for clock rollover detection
unsigned long old_now = 0;           // variable to hold the old time for comparison to current time
unsigned long last_send = 0;


void setup() {
  pinMode(ledPin, OUTPUT);        // declare LED as output
  pinMode(zone1, INPUT);         // declare zone1 as input
  pinMode(zone2, INPUT);
  pinMode(zone3, INPUT);
  pinMode(zone4, INPUT);
  pinMode(tamper, INPUT);
  pinMode(inactivity, INPUT);
  pinMode(loBatt, INPUT);
  pinMode(jamm, INPUT);
  Serial.begin(4800);       // debug -- use the serial port
}

void loop(){
  
  now = millis();
  
  if (old_now > now) {  // when the old time is bigger than the current time, the clock has rolled over
    old_now = now;      // because we've already compared, we need to make now the old_now for the next loop
    trigger_time = now; // because we rolled over, update the trigger_time so our comparison doesn't get lost in time ;)
    delay(10);
  } else {
    old_now = now;      // because we've already compared, we need to make now the old_now for the next loop
    delay(10);
  }
 
  if ((phoneState == 0) && (trigger_delay < now) && ((now - trigger_time) > trigger_delay)) { //check to make sure we don't cause a negative number before determining that we've passed the delay time
    phoneState = 1;    //Ready for action
    delay(10);
  }
  
  if (phoneState == 1) {
    phone.sendTxt("+1xxxxxxxxxx","Now with a +++ tickler in code!");
    delay(10);
    last_send = now;
    delay(10);
    phoneState = 2;     //Phone is sending.
    //add code here to reset the various alarm stacks
  }
  
  if ((phoneState == 2) && ((now - last_send) > trigger_delay)) {
    phone.off();       // Turn off the phone
    delay(10);
    phoneState = 0;    //Reset the state to off when a message has completed sending.
    delay(10);
  }
  
  val = digitalRead(tamper);        // read input value
  if (val == HIGH) {                // check if the input is HIGH
    digitalWrite(ledPin, LOW);      // turn LED OFF
  } else {
    Serial.println("Knock!");       // debug -- send the string "Knock!" back to the computer, followed by newline for testing purposes
    delay(100);                     // short delay to avoid overloading the serial port

  }

  
}

Did you manage to complete this project?? I'm a keen hobbyist and think this would be an interesting project to work on. Any chance you could post your finished code/hardware configuration etc?