Arduino USB serial

Add any particular hints or tricks you have found to help with your ZoneMinder experience.
Post Reply
ate8888
Posts: 1
Joined: Sat Jun 26, 2021 1:28 pm

Arduino USB serial

Post by ate8888 »

Hi, first time commenter long time user.

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; }
    
alabamatoy
Posts: 349
Joined: Sun Jun 05, 2016 2:53 pm

Re: Arduino USB serial

Post by alabamatoy »

I use a GPIO USB board (numato) to read a PIR motion detection through Guardline Security devices. These are quite reliable, very long life etc and seem to work well over as much as 200 feet. They have models which work up to a mile. I run a simple shell script to detect the PIR shunt (ie read the Numato board), and when detected (the shunt which is normally closed goes to open, ie the value goes from 1 to zero), the script employs cURL and the ZM API to start ZM recording.

It all works pretty well, with one flaw: The Guardline PIR devices shunt is short-lived through the Numato, so sometimes the PIR will detect, open the shunt, and the loop timing of reading the Numato device simply misses it. I cannot come up with a way to constantly monitor the shunt, only check it repeatedly every couple seconds, so sometimes it just misses the detection. I wish there were a way to raise an interrupt or something based on the Numato shunt rather than reading it over and over, I dont know how to do that.

The whole thing is inside the same box running ZM. I have had the whole system running for almost 2 years, and the Guardlines are still on their original batteries!
Post Reply