Pato Surveillance System

WTF is this !?

Aka PATOSS, is a Raspberry Pi project I started because of a wounded bird I did find on the street. "Pato" is a spanish word which actually means "duck" in english... Since "pájaro", which means "bird" in engish, was too long, I did name it Pato :)

The goal of the project was to be able to monitor via Internet, at least, the following parameters:

  • Video / Picture streaming via Internet in order to check how Pato is doing.
  • Environment temperature.
  • Water level.
  • Possibility to activate a buzzer in case Pato starts to run out of water.
  • Send 1 tweet every hour including water level (OK / NOK), temperature and a current picture taken by the webcam.

In order to accomplish this, I managed to put together the following elements:

  • Raspberry Pi B model 2nd Rev. (512MB RAM).
  • PiFace Digital I/O Expander (element14, £24.20 + VAT + Delivery).
  • HD Webcam C270 from Logitech (bought it 2nd hand via eBay).
  • TP-LINK TL-WN725N Nano Wireless N150 Adapter ( ~8€ w/ shipment).
  • USB Temper Thermometer. (eBay, ~18€ w/ shipment).
  • Liquid level sensor with horizontal float switch (eBay, ~7€ w/ shipment).
  • Red enclosure for RPi + PiFace (element14, £12.47 + VAT + Delivery).
  • Sandisk MicroSD 8GB Class 10 card that was laying around.
  • Non powered USB hub (DealExtreme, ~2€ w/ shipment).


There were two main reasons why I started with this project:

  1. I really want to be sure that Pato is doing fine at any moment, independently if I'm at home or not.
  2. I though it would be a funny way to start playing with digital I/Os on the Raspberry Pi and to manage inputs and outputs with Linux.
  3. Chek how lovely does Pato look with his leg in plaster!

Set-up at software level

I've used Raspbian as OS. To be honest, it is the only one I've been playing with and I do feel confortable "wotking" with it".

The Wireless USB dongle was easily recognized without the need installing any driver, nor enabling any module. I just had to set-up the proper configuretion at network level and my Raspberry Pi was on-line without the need of a network cable :)

Regarding the C270 webcam, pretty much the same. The webcam was properly recognized by Raspbian (started  the Raspberry Pi the the webcam pluged in and checked it with lsusb).

However, I did still needed to find a way to stream video and, if possible, take some pictures at the same time. That's how, surfing on the Internet, I discovered an application named "motion".

Setting up motion

First, we will have to install motion:

sudo apt-get install -y motion

Then, before starting it, we will have to modify three parameters inside /etc/motion/motion.conf and give them the following values.

Daemon = OFF to ON
webcam_localhost = ON to OFF
start_motion_daemon= "no" to “yes”

Once this is done, we can already start motion:

sudo service motion start

And check how our Raspberry Pi streams video :)


Setting up the USB temperature sensor (Temper)

First, we whave to ensure all the necessary dependencies are installed:

	sudo apt-get install -y build-essential libusb-1.0.0 libusb-dev

We get the latest version from the temper binary via git:

	git clone

Compile it!

	cd temper/

And then, just run your new binary :)

	pi@raspberrypi ~/temper $ sudo ./temper
	16-Jul-2013 00:02,26.089081

In case you want to get rid of the date and the time, you can use a script as I do:

TEMP=`sudo /home/pi/temper/temper | awk '{ print $2 }' | cut -d, -f2 | cut -c1-5`
echo "$TEMP'C"

And then, run it:

pi@raspberrypi ~ $ ./

Reading the liquid level sensor

I've connected the liquid level sensor to digital input 0. In order to check if there's water or not, I just have to run the following script. If there's enough water, it will return 1.

import piface.pfio as pfio
print pfio.digital_read(0)

Run it!

pi@raspberrypi ~ $ python

Reading the internal Raspberry Pi temperature sensor

Easy way to read the temperature sensor embedded on the Raspberry Pi.

pi@raspberrypi ~ $ cat
/opt/vc/bin/vcgencmd measure_temp | cut -d= -f2
pi@raspberrypi ~ $ ./

Sending info to Twitter via e-mail

pi@raspberrypi ~ $ sh -x
+ /home/pi/
+ CPUTMP=55.1'C
+ /home/pi/
+ ENVTMP=27.82'C
+ python /home/pi/
+ [ 0 -eq 1 ]
+ [ 0 -eq 0 ]
+ AGUA=Pato needs water
+ SUBJECT=RPi temp: 55.1'C. Room temp: 27.82'C. Pato needs water.
+ echo
+ echo RPi temp: 55.1'C. Room temp: 28.98'C. Pato needs water.
+ mutt -a /tmp/motion/patoss.jpg -s RPi temp: 55.1'C. Room temp: 28.98'C. Pato needs water. --
pi@raspberrypi ~ $

And here you have the posted tweet:

Pato's Tweets timeframe

Every night I move Pato from one room to another which is darker, and I leave him sleeping there until the next morning, that's why PATOSS is only sending tweets from 10 AM GMT+1 until 10 PM GMT+1.

# m h  dom mon dow   command
15 * * * *  /home/pi/

How the "stupid and simple" shell script looks like (updated 26/07/2013)

Note that there are some Spanish words on my scripts.


LIQUID=`python /home/pi/`
TIME=`date +%H`

if [ ${TIME} -lt ${MORNING}  ] || [ ${TIME} -gt ${NIGHT} ]; then
	exit 0

if [ ${LIQUID} -eq 1 ]; then
	AGUA='Water level OK'
elif [ ${LIQUID} -eq 0 ]; then
	#AGUA='Pato needs water'
	AGUA='Liquid sensor not connected'

MESSAGE="RPi temp: ${CPUTMP}. Room temp: ${ENVTMP}. ${AGUA}."

if [ ${TIME} -eq ${MORNING} ]; then
	SUBJECT="Good morning! ${MESSAGE}"
elif [ ${TIME} -eq ${NIGHT} ]; then
	SUBJECT="Good night! ${MESSAGE} "

echo "" | mutt -a /tmp/motion/patoss.jpg -s "`echo ${SUBJECT}`" --

Set-up at hardware level

The Webcam, Wireless dongle and the Thermometer are connected via USB to the Raspberry Pi by using a chinesse and check non-powered USB hub.

On the other hand, the liquid level sensor is connected via the PiFace to the digital input nr. 0 and GND.

From left to right:

  • Liquid level sensor.
  • Webcam.
  • Temperature sensor.
  • USB hub.

Liquid sensor connected to I/O pins 0 and GND

When Pato has enough water, the I/O returns "1", otherwise, it returns "0".

PATOSS's housing

For the electronics housing, I've re-used a paper box I got a while ago when I bought some electornics via Internet. The coolest thing from this box is that there's a magnet in order to keep the box closed :)

Just a pair holes and the box was ready to host the electronics!

In order to keep the webcam attached to the box, I use hook-and-loop fastener.

How does the final set-up look like

On the left side, PATOSS powered via micro USB and transfering data by using a wifi dongle. On the right side, Pato!

TO DO !!!

  • Add a buzzer.
  • Add a backup battery.
  • Mount the liquid level sensor in a way that it's easy to attach and deattach.

Update 26/07/2013

Pato's Twitter account @patossbcn has almost as many followers as my personal account @JorgeRance does... I don't know if I should be happy or sad.

Update 28/07/2013

Pato's Twitter account @patossbcn already has more followers than me... A bird has more followers than me... Pato, we're breaking up, I'm sorry...