Been scratching my head trying to link up a PIR sensor to zoneminder without finding much information or sketches to help me out on my way.
Anyway here is something that works, to anyone stumbles across this post in the future yes it can be done. This works on a $10aud Arduino Leonardo mini compatible
Code: Select all
const int FirePin = A2;
int FIREPINSTATE = 0;
unsigned long MinFireLength = 20000;
unsigned long MaxFireLength = 90000;
unsigned long MiniFireLengthTimer = millis();
unsigned long MaxiFireLengthTimer = millis();
bool FIRESTOP = false;
bool FIREWAIT = false;
const int MotionPin = A0;
int MOTIONPINSTATE = 0;
unsigned long MinMotionLength = 20000;
unsigned long MaxMotionLength = 90000;
unsigned long MiniMotionLengthTimer = millis();
unsigned long MaxiMotionLengthTimer = millis();
bool MOTIONSTOP = false;
bool MOTIONWAIT = false;
void setup() {
Serial.begin(9600);
pinMode(FirePin, INPUT);
pinMode(MotionPin, INPUT);
delay(5000);} //Delay For Compatability
void loop() {
firesense();
motionsense(); }
void firesense() {
FIREPINSTATE = analogRead(FirePin);
unsigned long timeNow = millis();
if (FIREPINSTATE > 1000 && FIREWAIT == false) {
Serial.println("1|on+10|1|fire|fire|jess");
FIRESTOP = true;
FIREWAIT = true;
MaxiFireLengthTimer = timeNow;
MiniFireLengthTimer = timeNow; }
else if (FIREPINSTATE < 999 && FIRESTOP == true && timeNow - MiniFireLengthTimer > MinFireLength) {
Serial.println("1|off+10|1|fire|fire|jess");
FIRESTOP = false;
FIREWAIT = false; }
else if (FIREPINSTATE > 1000 && timeNow - MaxiFireLengthTimer < MaxFireLength) {
MiniFireLengthTimer = timeNow; }
}
void motionsense() {
unsigned long timeNow = millis();
MOTIONPINSTATE = analogRead(MotionPin);
if (MOTIONPINSTATE > 1000 && MOTIONWAIT == false) {
Serial.println("1|on+10|1|Motion|Motion|Peter");
MOTIONSTOP = true;
MOTIONWAIT = true;
MaxiMotionLengthTimer = timeNow;
MiniMotionLengthTimer = timeNow; }
else if (MOTIONPINSTATE < 999 && MOTIONSTOP == true && timeNow - MiniMotionLengthTimer > MinMotionLength) {
Serial.println("1|off+10|1|Motion|Motion|Peter");
MOTIONSTOP = false;
MOTIONWAIT = false; }
else if (MOTIONPINSTATE > 1000 && timeNow - MaxiMotionLengthTimer < MaxMotionLength) {
MiniMotionLengthTimer = timeNow; }