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();
}