Page 1 of 1

Using cheap PIR for motion detection

Posted: Tue Jul 12, 2011 11:35 am
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.

Re: Using cheap PIR for motion detection

Posted: Sat May 20, 2017 2:33 am
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

Re: Using cheap PIR for motion detection

Posted: Sat May 20, 2017 12:18 pm
by SlowScan
The OP posted six years ago. Just wondered if you noticed that?

Re: Using cheap PIR for motion detection

Posted: Sun May 21, 2017 8:57 pm
by MoOz
yes i did