How-to Guide - Using a Cheap wireless Driveway sensor & Raspberry Pi to trigger BI

Rollo

Young grasshopper
Joined
Aug 4, 2014
Messages
45
Reaction score
23
This is how I got a cheap wireless PIR driveway monitor to trigger Blue Iris. I’ve been using BI with a Hikvision DS-2CD2032 but had issues with motion detection not working when my car is parked as it mostly masks the path covered by people coming to the front door. When I made it more sensitive it was then more likely to be triggered by birds etc.

So I decided I wanted to use a PIR sensor as its a very mature & cheap technology, and then use a Raspberry Pi as the brains to trigger Blue Iris. In this project I’ve shamelessly borrowed from lots of other people’s projects/blogs/posts and jammed it all together.

I bought a cheap generic Wireless PIR Driveway monitor - Less than £17 from Amazon and available everywhere with various branding but the same overall design,


SR07737-40.jpg


I stuck the PIR sensor so it just covered the door,


sensor.JPG


When the PIR is triggered it flashes some LEDs and sounds an alarm on the base unit. I chopped the head off one of the LEDs just leaving 2 pins sticking up, then pushed on 2 jumper leads.


leds.JPG


These leads then go to a breadboard with a H11L1 optocoupler which basically uses the voltage from the LEDs being triggered to send a logic signal out to the Raspberry Pi. As its an optocoupler its electrically separated from the Raspberry Pi so I don’t have to worry about zapping the Pi.

The Pi connects to the optocoupler with a 3.3V, ground, and an output which goes into a GPIO pin. Its this pin thats we’re doing all the work with.


breadboard.JPG


Here’s the complete package,


finished.JPG


When nothing is triggered the GPIO pin is reading high, and when its triggered its reading low.

I use a small python program which monitors that pin once per second, and if it detects a 0 then logs the result to the screen, and then uses the curl command to call the http trigger address for the camera in Blue Iris. The program then sleeps for 60 seconds because the LEDs flash 4 times in 5 seconds and I don’t want 4 triggers for every event. The code is nothing special but I’ll copy it below - All seems to be working well so far ! Please note the tab indent formatting got stripped when I pasted in the code so you'd need to re-tab it to work, but it should give an idea of what I did.

#!/usr/bin/env python
import time
import subprocess

import RPi.GPIO as GPIO

def trigger_camera():
subprocess.call(['curl','http://192.168.1.82:81/admin?camera=Drive&trigger'])

def log_results(log_det):
local_time = time.asctime(time.localtime(time.time()))
print(local_time,' ',log_det)

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(4, GPIO.IN)

log_results('Started Monitoring')

try:
while True:
#
# Input is 1 by default and 0 when triggered
#
if GPIO.input(4) == 0:
#
# Log the detection
#
log_results('Detected')
#
# Call curl to trigger Blue Iris
#
trigger_camera()
#
# Sleep for 60 seconds after detection to avoid
# repeat triggers for same event
#
time.sleep(60)
#
# Only check the PIR once per second
#
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,676
Reaction score
14,024
Location
USA
Interesting. You sure make it look easy. However I know almost nothing about electronics hardware at this level. I mean, in your picture of the breadboard, there are two doodads you didn't even mention (resistors of some kind I assume?). So I don't think your guide is quite dummy-proof yet. I don't even know how breadboards work, really.

In the end what amazes me is that nobody has built an all-in-one product for doing this! I'd pay $100 easy for a compact, waterproof, PoE powered PIR sensor that speaks http. Assuming the sensor wasn't blind in most directions like the one in my driveway light. Replacable PIR modules might be a good idea in such a product.
 

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,676
Reaction score
14,024
Location
USA
Also have you tried having it not sleep for 60 seconds after detection? I think Blue Iris might be fine with multiple triggers for each event. The description for the "break time" in BI's motion configuration basically says this. "End trigger unless re-triggered within ___ sec." Hopefully BI is smart enough to not create 4 separate recordings if it receives 4 triggers in 4 seconds!
 

Rollo

Young grasshopper
Joined
Aug 4, 2014
Messages
45
Reaction score
23
Yes you can take out the 60 seconds delay after detection - Blue Iris does only record the one trigger.


The circuit in a bit more detail as I understand it - There are 3 components,


H11L1 optocoupler
270 Ohm resistor
220 Ohm resistor

Theres a rather technical description of the optocoupler here,

http://www.fairchildsemi.com/ds/H1/H11N1M.pdf

My circuit diagram is,

circuit.jpg

Top is the Raspberry Pi side of things with 3 connections,

3.3V which is pin 1 on the Raspberry Pi GPIO
Ground which is pin 6 on the GPIO
GPIO in where I'm using ping 7 on the GPIO

The resistor at the Pi side of things is a fixed value and you shouldn't need to touch it. This resistor effectively connects pin 6 and 4 and doesn't touch pin 5 (the ground).

The bottom is base unit side (or whatever device you want to respond to) with a positive and negative connection which is the 2 sides of the LED where I chopped the head off. The resistor on the bottom is based on that side of things being upto 5v (my base unit is 4.5v and actually gives far less at the LEDs but it works fine). If your device was using a higher voltage then you'd want a bigger resistor.

Theres a good introduction to breadboards and connecting things to the Pi on youtube here,


 
Last edited by a moderator:

bp2008

Staff member
Joined
Mar 10, 2014
Messages
12,676
Reaction score
14,024
Location
USA
Thanks! I've always wanted to learn this stuff but I have so many other things to do...

The most use I get out of a raspberry pi is to feed a pico projector which I use as a projection clock at night.
 

nayr

IPCT Contributor
Joined
Jul 16, 2014
Messages
9,329
Reaction score
5,325
Location
Denver, CO
very nice lil hack; some suggestions tho.. I am familiar with that wireless PIR and I found it mostly junk; it seemed like a blowing blade of grass would set it off and gave me continuous false alarms... Its not looking for mammalian IR signatures; it'll trigger with any IR movement like clouds and headlights.

Newbies here wanting to get into playing with hardware/code should hold off on the RPI and find a nice Arduino w/Ethernet.. there much cheaper, dont need a memory card, dont run a full linux operating system to have to learn.. plus if you look hard enough you can find PoE powered Arduino's.

once you outgrow an arduino there's so much better stuff out there than a RPI; BeagleBones, HummingBoards, etc...

If you want a cool project for your RPI check out OpenSprinkler; I am using the BeagleBone version and its been running great and 100% reliable!
 
Top