Skip navigation

Raspberry Pi Projects

2 Posts authored by: Dave Young

wallace and gromit


My dog Penny is one of the best. She has the two critical commands of ‘come’ and ‘stay’ down pat so well that I can go for a run with her off-leash here in Denver.


She’s gentle with our newborn baby, and she doesn’t destroy things. Her only issue is that she goes BONKERS for food. My wife and I have done a great job training it out of her when we’re around so we no longer have to worry about a cheese board sitting on the low coffee table, but I know she gets on the counters any time we are away. Sounds like a job for a machine!

0528151441d.jpgI decided that it might be helpful to have a surrogate to defend the counters when she’s home alone. After the success of the Silent Laser Doorbell, I decided that a Laser Dog Watcher could be similarly effective.  Here are the features:

  • Setup a Laser tripwire using the same mechanical system in the Silent Laser Doorbell<link>
  • On a laser beam break, trigger the digital GPIO of a Raspberry PiRaspberry Pi to play an audio file of me reprimanding her AND taking a photo with the Pi CameraPi Camera. The audio file changes so it’s not always the same.
  • There is a calibration knob to allow for various levels of ambient light.
  • There is an ‘enable’ switch to disable the audio and photo features to allow the user to line up and calibrate for ambient light.
  • If the first audio file doesn’t get her off the counter and reestablish the beam, it plays up to two more audio files before disabling itself. That way it won’t loop over and over in case the system was knocked out of alignment.


Here’s the system in action! I put a bit of food on the counter and left for a while with a video camera setup.


I’ve put a step-by-step tutorial below and attached full documentation to this article for those that would like to build one, but first a few design decisions that had to be made.


Raspberry Pi2 Choice:

I’ve been keen to use my Pi2, and this seemed like a great chance. Although it doesn’t really use the muscle behind the new version I like knowing that expansion of this project would be no problem. Who knows – maybe I’ll do image processing to recognize her and generate a trigger! Here is a spec comparison for the Rev 1 vs. Rev 2 Raspberry Pi:

Pi Pi2_compare_jan30.png



In the Silent Doorbell project, I implemented a clever moving average system to automatically calibrate for ambient light. This was certainly needed in sunny Denver, CO. However the Raspberry Pi doesn’t have any analog inputs that would be required for such an algorithm. Since this design is intended to be used indoors with mostly stable ambient light and the sensor is mostly enclosed, a calibration knob makes on leg of the resistor divider variable and gave plenty of stability (i.e. lights on, lights off, etc…). The way to calibrate is to have the beam broken and make sure the status LED shows that the beam is broken by turning on. Turn on all the lights in the room to be sure it will work in all conditions. Then aim the beam to the sensor and be sure the status LED turns off. Check out the schematic:

<insert schematic image>


Enable Switch:

During laser aiming and calibration, I was annoyed by constantly hearing myself yell at the dog, and poor penny was so worried and confused! It took me about 5 seconds to decide that an enable switch is needed.


Status LED:

When the enable switch turns off audio output, one needs an LED to show that the laser is broken during aiming and calibration! It was a huge help.



Catching animals in the act is hilarious! Also, I want to be sure the system is working properly and count the number of times that it was tripped.


There you have it! If you want to build one for yourself, follow the tutorial below and let us know in the comments how it goes!




1. Download the NOOBS files and follow the tutorial created by Raspberry Pi. It’s a big file so grab a coffee/tea/beer and build the circuit hardware described on the Silent Laser Doorbell page.

2. Plug the Pi into a monitor, keyboard, and mouse and power up the pi

3. Select ‘Raspian’ for your operating system and set your desired language and keyboard. The install takes a while so now’s a great time to re-up your beverage of choice.

4. After the install completes, the Pi restarts itself in the Configuration Tool. Go into ‘Advanced Options > SSH’ to enable SSH. Go into ‘Enable Camers” > ‘Enter’ > ‘Finish’

5. Reboot the system and if you’d like to SSH into the Pi you can remove the monitor, keyboard, and mouse.

6. Update and upgrade the packages. This takes a bit. Probably time for another beverage.

sudo apt-get update

sudo apt-get upgrade

7. Install the RPIO package to allow reading the GPIO lines, Alsa audio drivers, the mpg123 MP3 player, and the PiCamera library

sudo easy_install –U RPIO

sudo apt-get install alsa-utils mpg123

sudo apt-get install python-picamera

8. Reboot the Pi

9. Load the sound drivers and set  the system to use the 3.5mm audio jack output

sudo modprobe snd_bcm2835

sudo amixer cset numid=3 1

10. Create a folder to hold your MP3 files and python script, and another one (in the dogwatcher folder) for the image files

mkdir dogwatcher      #in the pi directory

mkdir photos          #in the dogwatcher directory

11. Transfer your MP3’s to your Raspberry Pi into your ‘dogwatcher’ folder. There are many ways to do this. My two favorite methods are (1) login to your Pi with an SFTP (SSH File Transfer Protocol) client like FileZilla and copy them to the desired directory or (2) Use a thumb drive to transfer the files. My files are ‘hey.mp3’ ‘uhoh.mp3’ and ‘baddog.mp3’

12. Test to be sure that you can play the file desired to your 3.5mm audio jack by running the following command in your folder:

mpg123 hey.mp3

13. Install the Rpi.GPIO module on the Pi

sudo apt-get install python-dev python-rpi.gpio

14. Upload the python script to the dogwatcher folder. Feel free to use mine; attached here as ‘’

15. Build the laser detection hardware and enable switch circuit described in the schematic

16. Turn on the Pi, navigate to the dogwatcher folder, and run the python script.

cd dogwatcher

sudo python

17. Calibrate the sensor, then enable the switch to make sure everything runs as planned. You can pull photos off in the same way you added the MP3’s, but I’m a big fan of doing it over SSH FTP with Filezilla.

18. Setup the Pi to activate the system on boot using your favorite method (instructable listed below for the method I used, or you can use the included ‘’ file of mine attached here).

19. Test it! It should run on bootup.


Attached Design Files: Python script that runs the system

Laser Dog Watcher.sch: EAGLE schematic benefiting from the Raspberry Pi 2 EAGLE library

Laser Dog Watcher Schematic.pdf: PDF of the schematic

hey.mp3: One of the audio files that I used (in case you need a known-good audio file to test your system)


Helpful Links:

to start a python script at boot:

0429151712a.jpgA couple years ago, I showed how to setup an ownCloud server on a Raspberry Pi.  The system worked, but there were some performance hiccups. Most importantly was the ability for the system to handle large files and for the Pi v1 to take on the task in a speedy manner. I found myself using Microsoft’s OneDrive more often, electing to use their more proven platform for anything that didn’t require tight privacy controls and a firm handle on my data’s location. Still, it was a small, secure, and low-power cloud storage solution.


With the latest release of the Raspberry Pi 2Raspberry Pi 2, I thought this was a perfect time to update both my hardware and software in hopes of seeing performance improvements. The result gave ownCloud a whole new lease on life, at least in my lab. Check out my video showing the system and its performance:



I can’t be sure if it is the upgraded hardware, the updated linux OS and packages, changing to an nginx server, or the latest version of ownCloud, but the system worked much better. I had the server up and running within a few hours, and the web and desktop clients singing minutes after that. But the Pi2’s vastly improved specs have to be part of it:

Pi Pi2_compare_jan30.png

Although things are greatly improved, it still can’t beat the usability of OneDrive. I tried creating issues for the system by uploading a 1GB file from ‘Computer A’ over a browser, uploading music files from ‘Computer B’ via the client, and quickly browsing the files from ‘Computer C’ over a browser. It worked for a while, but it had difficulty on the 1GB file upload and caused a sync error to flag on the client. Thankfully after a few minutes the system figured itself out and updated everything as one would hope. Stability and storage integrity is the ultimate goal so this is yet another example of trading patience/minor hassles for privacy.

broken hard drive.jpg


I looked at some customizations like overclocking, but decided against it on account of stability trumping speed when it comes to data storage. Waiting a few seconds or even a minute for a webpage to load or a file to sync is annoying; having the system go down when a critical file is needed is simply unacceptable.


The ease of use, extremely low cost, and improved performance makes for a viable system when trying to control data and its privacy. With the new world of cloud-based systems everywhere it’s easy to forget that data is a tangible asset and must be considered as such!


While there are a few tutorials out there relating to Pi ownCloud servers, I couldn’t find one that was used with the Pi2 and OwnCloud v8 and solved all of my size limitation issues, so here are the steps that I followed to get the system installed and running.



1. Follow Rpi’s getting started guide to install Raspian

2. Expand filesystem, set international options, Setup hostname and GPU memory split to 16, and enable ssh in the advanced options.

3. Update and upgrade the packages

4. Add users to the www-data group.

sudo usermod -a -G www-data www-data

5. Install nginx , OpenSSL, php5, etc… packages

sudo apt-get install nginx openssl ssl-cert php5-cli php5-sqlite php5-gd php5-common php5-cgi sqlite3 php-pear php-apc curl libapr1 libtool curl libcurl4-openssl-dev php-xml-parser php5 php5-dev php5-gd php5-fpm memcached php5-memcache varnish

6. Create the SSL certificate based on your location, organization, and email by running:

sudo openssl req $@ -new -x509 -days 730 -nodes -out /etc/nginx/cert.pem -keyout /etc/nginx/cert.key

7. Modify the privileges to the two cert files:

sudo chmod 600 /etc/nginx/cert.pem
sudo chmod 600 /etc/nginx/cert.key

8. Access the web server configuration file by running the command

sudo nano /etc/nginx/sites-available/default

9. Replace everything in the file with the following, replacing my Pi’s IP ( with your own (I only put my Pi’s local IP here for security – you may have a global IP to allow you to access it anywhere on the 'net).

upstream php-handler {


#server unix:/var/run/php5-fpm.sock;



server {

listen 80;


return 301 https://$server_name$request_uri;  # enforce https



server {

listen 443 ssl;



ssl_certificate /etc/nginx/cert.pem;

ssl_certificate_key /etc/nginx/cert.key;


# Path to the root of your installation

root /var/www/owncloud;


client_max_body_size 2000M; # set max upload size

fastcgi_buffers 64 4K;


rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;

rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;

rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;


index index.php;

error_page 403 /core/templates/403.php;

error_page 404 /core/templates/404.php;


location = /robots.txt {

allow all;

log_not_found off;

access_log off;



location ~ ^/(?:\.htaccess|data|config|db_structure\.xml|README) {

deny all;



location / {

                # The following 2 rules are only needed with webfinger

                rewrite ^/.well-known/host-meta /public.php?service=host-meta last;

                rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;


                rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;

                rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;


                rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;


                try_files $uri $uri/ index.php;



location ~ \.php(?:$|/) {

                fastcgi_split_path_info ^(.+\.php)(/.+)$;

                include fastcgi_params;

                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

                fastcgi_param PATH_INFO $fastcgi_path_info;

                fastcgi_param HTTPS on;

                fastcgi_pass php-handler;



# Optional: set long EXPIRES header on static assets

location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {

                expires 30d;

                # Optional: Don't log access to assets

                access_log off;




10. Edit php.ini file to allow 2GB file sizes by running the following and changing a couple parameters:

sudo nano /etc/php5/fpm/php.ini

search for upload_max_filesize and set it to 2000M

search for post_max_size and set it to 2000M

11. Configure PHP settings by running the following two commands and making the described changes in each file:

sudo nano /etc/php5/fpm/pool.d/www.conf

Then Change:

listen = /var/run/php5-fpm.sock
to :
listen =

sudo nano /etc/dphys-swapfile

Then Change:

to :

12. Restart the Pi

13. Install owncloud by running the following commands and verify the files are in the right place:

sudo mkdir -p /var/www/owncloud

sudo wget

sudo tar xvf owncloud-8.0.2.tar.bz2

sudo mv owncloud/ /var/www/

sudo chown -R www-data:www-data /var/www

rm -rf owncloud owncloud-8.0.2.tar.bz2

14. Plug in the external hard drive (mine was formatted with NTFS).

15. Install the package to work with NTFS if your drive is setup as NTFS

sudo apt-get install ntfs-3g

16. Make a directory for mounting the drive

sudo mkdir /media/owncloud

17. Mount the drive (command below for NTFS drive)

sudo mount -t ntfs-3g -o uid=1000,gid=1000,umask=007 /dev/sda1 /media/owncloud

18. Find the UUID by running the following command. UUIS is the blue text associated with the sda1 drive that will look something like 4264E66D64E66361

ls -l /dev/disk/by-uuid/

19. Backup and then open fstab by running:

sudo cp /etc/fstab /etc/fstab.backup
sudo nano /etc/fstab

20. Edit fstab by adding the following at the bottom while replacing my UUID 4264E66D64E66361 with the one you found on your setup in step 18:

UUID=4264E66D64E66361 /media/owncloud ntfs-3g uid=1000,gid=1000,umask=007 0 0

21. Reboot the Pi and check that your drive has been automatically mounted.

22. Set permissions for the www-data group:

sudo usermod -a -G pi www-data

23. Navigate to cd /var/www/owncloud

24. Edit the .htaccess file to set the max file size:

sudo nano .htaccess

Then set the following values to 2000M:

Php_value upload_max_filesize

Php_value post_max_size

Php_value memory_limit

25. Edit the .user.ini file and change the following fields to 2000M:

sudo nano .user.ini

Then set the following values to 2000M:




26. Reboot the Pi.

27. Visit the location of your Pi’s IP (mine was with a browser to access your ownCloud Server and create an admin account! Note that without cURL installed, there may be an error for files over 4GB. But since this setup limits the files to 2GB, that’s no big deal.

28. Install ownCloud's free client/app on any of your machines, or elect you just use the browser interface.

29. Implement your favorite method of allowing access to your Pi2 from the internet. These steps vary from network to network and modem to modem, but here are a few resources that may help:

NOTE: A comment from Nick Vee below that may be helpful to some users:

it was not pointing to the USB drive. The data was going on the sd card. There are a few steps missing to make sure the USB drive is being used. Make sure in /var/owncloud/config/config.php that the data directory is pointing to your USB mount point for your external disk. There is supposed to be a dialog for this in the admin setup, but I never saw it.  Also the data directory on your USB must be owned by www-data (the web server user) so you have to set that permission with a chown command. There are examples of this in "how to move your data directory" in the owncloud forums.

Of course being an analog electronics guy, I am no linux wiz. I was able to put together this tutorial which is a variation of the following resources published by the real pros:

Filter Blog

By date: By tag: