Using cheap PIR for motion detection

Add any particular hints or tricks you have found to help with your ZoneMinder experience.
Post Reply
chippy99
Posts: 66
Joined: Wed Aug 30, 2006 5:38 pm
Location: Barnet, Herts. UK

Using cheap PIR for motion detection

Post by chippy99 »

I bought a cheap IR day/night camera but it had terrible interference at night so I was getting false alarms all the time. I looked at using an X10 PIR for doing motion detection but it seemed a bit expensive and complicated so I decided to try using an ordinary burglar alarm PIR connected to the parallel port on my server. It works very well with CPU useage much reduced and better still did not cost me a penny because I already had the parts laying around.
You need to connect the relay connections of the PIR to a data pin and an input pin on the parallel port (I used pins 9 and 10), of course you also need to provide power to the PIR (usually 12v). Be careful when doing this because a short could fry either your parallel port or your motherboard, might be an idea to test it with an old pc or use a PCI parallel port card if you are not too sure what you are doing. You then need to check that opt_triggers is enabled in options->system. I then wrote this crude program in python to send a message to zmtrigger to start and stop the alarm events.

Code: Select all

#! /usr/bin/env python

import sys
from socket import *
import parallel
import time

PORT = 6802
HOST = 'localhost'
MONITOR_ID = "6"

def raise_alarm():
        s = socket(AF_INET, SOCK_STREAM)
        s.connect((HOST, PORT))
        s.send(MONITOR_ID + "|on|255|entrance|frontdoor");
        s.close()
        #print "alarm raised"

def clear_alarm():
        s = socket(AF_INET, SOCK_STREAM)
        s.connect((HOST, PORT))
        s.send(MONITOR_ID + "|off|255|entrance|frontdoor");
        s.close()
        #print "alarm cleared"

p = parallel.Parallel()

p.setData(0)
#print p.getInAcknowledge()
alarm_raised = 0
while (1):
        while (p.getInAcknowledge() == True):
                if (alarm_raised == 0):
                        raise_alarm()
                        alarm_raised = 1
                time.sleep(5)
        if (alarm_raised == 1):
                clear_alarm()
                alarm_raised = 0

        time.sleep(0.5)
Change monitor_id to suit your setup, to get your monitor_id execute the following sql statement "select * from Monitors;". You can change the sleep values according to your requirements
You will probably have to install pyparallel and then do rmmod lp and modprobe ppdev to get this program to work.
Set the monitor to nodect in zm and then run this program in the background.
Like I said earlier you can fry your parallel port or motherboard if you make a mistake so although I have had no problems with this you do it at your own risk.
MoOz
Posts: 31
Joined: Tue Jan 17, 2017 9:49 pm

Re: Using cheap PIR for motion detection

Post by MoOz »

That's a great ideal
what would you have to change in the software
so you can control the output port
to follow the alarm from zoneminder
Moz
SlowScan
Posts: 25
Joined: Tue Feb 28, 2017 11:47 pm

Re: Using cheap PIR for motion detection

Post by SlowScan »

The OP posted six years ago. Just wondered if you noticed that?
MoOz
Posts: 31
Joined: Tue Jan 17, 2017 9:49 pm

Re: Using cheap PIR for motion detection

Post by MoOz »

yes i did
Post Reply