Software apps and online services
Introduction and Motivation
I wanted to monitor activity at the front of my house without the expense of multiple cameras. My project uses a single PTZ IP camera that pans to provide wide area coverage. I have 3 areas that need to be covered, the front yard and the driveway (looking away from the house) and the front door (looking toward the house). I use a PIR sensor and a Sparkfun 8266 board for each zone to detect motion and cause the camera to pan to that zone.
The Cayenne IOT Platform provides the ideal interface to integrate the various functions and to provide dashboard displays in both a web browser and on a mobile app.
Dedicated Camera Display Monitor
I wanted to have a “live” display of the camera image in my living room for continuous monitoring. I used an old 20” Samsung LCD monitor with a Raspberry Pi to implement that. The Pi is running Omxplayer to display a live stream from the camera.
I won a Sparkfun 8266 Thing Dev from the idea phase of this contest. I decided for the purposes of the contest that I would only implement 2 of the 3 zones as proof of concept (I will finish the third zone when I have more time). I will use the 8266 Thing Dev for one zone sensor and I bought an additional 8266 Thing for the second zone sensor.
I am using HC-SR501 modules for PIR detection.
I built a trip wire sensor using a generic 5V 5mW red laser and a generic CDS photocell.
I am using a generic CDS photocell for ambient light detection.
I am using an FDT FD7903 Outdoor HD PTZ IP camera. It has WiFi capability but I am using it with hardwired ethernet for reliability. The network interface to my Pi is also wired. The camera has a built in web server that I can use to pan and record snapshots and video.
I am using the Arduino IDE to program 8266 Thing/Dev boards. It is using the Cayenne MQTTESP8266 library to implement the Cayenne interface.
I am using Cayenne IOT Platform to perform device control/monitoring and inter-device triggering.
Building the Project
Step 1: Setup the PTZ camera.
I needed to find a place to mount the camera that would allow it cover all 3 zones. The camera would need to cover a 270 degree field of view. I had a point at the corner of my garage that I could use, but I needed to build an extension to allow the camera to mount below the gutter downspout.
Step 2: Setup the dedicated display
I used an old Samsung 1280x1024 LCD monitor and a Raspberry Pi 3 to implement the display. Since it was an older monitor I needed to use a VGA to HDMI adapter to connect to the Pi.
I am running a standard Raspbian Jessie OS on the Pi. I needed to add the Omxplayer and Screen software to allow viewing the RTSP stream from the camera.
sudo apt-get install libpcre3-dev libpcrecpp0 libva-dev libva-x11-1 libva1
Download package and unzip:
sudo dpkg -i omxplayer_0.0.1-arm.deb
sudo apt-get install screen
Create shell script to view rtsp stream:
Bash script is named driveway (name of the camera) – see code section
Step 3: Build the PIR Modules
Front Door Module:
I used the ESP8266 Thing for the Front door module. It is similar to the Thing Dev board but it does not have an onboard FTDI interface so I needed to use a 3.3V FTDI Basic board to program it. It does have capability to use and charge a LiPo battery so I may use this board to implement my final configuration. It depends the final average power consumption. Currently I am using generic USB power banks to power the modules.
Laser trip wire sensor:
I mounted the laser in a used ball point pen casing and put that into some PVC sprinkler adapters. I also mounted the CDS photocell into sprinkler adapters to shield it from ambient light. The adapters allowed me to align the laser and photocell. I used an NPN transistor to provide the current drive for the laser. The photocell resistance was between 40-50 ohms under full intensity so I used with a 10 ohm resistor to keep the output voltage within the 1V range of the A/D converter of the ESP8266. See schematic for hookup details.
The sensor has two trim pots for sensitivity and trigger delay. I set them to maximum sensitivity and minimum delay (2-3 seconds). There is also a mode jumper that I set to re-trigger.
I used the ESP8266 Thing Dev for the Driveway module. It does have an onboard FTDI interface so it can be programmed directly via USB.
Ambient light sensor:
I used a CDS photocell mounted on a bottle cap as my ambient light sensor (basically used to determine if it is day or night). I used it in the same configuration as the one in the laser circuit.
This is hooked up identically to the one on the Front door module.
Step 4: Write the ESP8266 Code and upload
I started with the Cayenne ESP8266.ino example program from github: https://github.com/myDevicesIoT/Cayenne-MQTT-ESP8266/blob/master/examples/ESP8266/ESP8266.ino
You need to put in Cayenne device identifiers that you get when you create your device. From the Cayenne dashboard add a new Sparkfun ESP8266 Thing Dev Board and copy the following strings into the code: MQTT Username, MQTT Password and Client ID.
Add the SSID and password of your WiFi network.
Add the device logic and widget code (see the .ino files in the code section).
Step 5: Configure the Cayenne Interface
Next step is to add the widgets to the dashboard and create the triggers. The 2 device dashboards are shown below and also the trigger that is used to pan the camera when motion is detected by the PIR sensor.
Step 6: Test the system
I have not implemented the third zone, but I realized that the decision logic to control the cameras must be more complex. I need to be able to determine what to do if motion is detected in multiple zones simultaneously (need a priority scheme and inter-zone logic). I know that the Cayenne team is working on enhancing the Trigger capability (possibly adding combinatorial logic). I would also like to have the camera send snapshots. I don't know if the camera widget in Cayenne will handle that when it is implemented or if I will need to use the camera webserver to do that.
I have been very happy with the ease of implementation using the Sparkfun ESP8266 hardware. Their tutorials are also great. I am somewhat concerned about how successful I will be in using battery power for these devices. I guess I will know soon.