In this task, we will set up a bird feeder with a motion sensor. Whenever a bird flies into feed on the grains out of the feeder, the motion sensor is triggered to send a message to the Raspberry Pi. A camera module or a USB camera is connected to the Raspberry Pi, which captures some beautiful moments in our backyard.
Srihari Yamanoor (one of the authors of this book) has an extensive backyard where this bird feeder has been installed. Check out this book's website to find out whether we have captured any beautiful moments thus far!
In order to build this interactive pet feeder, we need the following items:
python-twisted
server launched on Raspberry Pi:if (client.connect(server, 8000)) { Serial.println("Motion Detected"); client.println("Motion Detected"); client.println(); //Lets wait for the client to read and //echo the message //Note: A second's delay is a bit excessive delay(1000); client.stop(); Serial.println("Client Disconnected"); } else { Serial.println("connection failed"); }
python-twis
ted
server, we need the picamera
module (https://pypi.python.org/pypi/picamera). It can be installed as follows:sudo apt-get install python-picamera
python-twisted
example, simpleserv.py
, to import the picamera
and datetime
modules (to name the pictures captured by the camera using a timestamp).Motion Detected
, we will take a picture and name the file using a timestamp. DataReceived
, let's capture an image:with picamera.PiCamera() as camera: camera.start_preview() time.sleep(2) camera.capture('img{timestamp:%Y-%m-%d-%H-%M}.jpg')
Check out this book's website to look at the Raspberry Pi and Spark Sensor setup that is used to take pictures. This is really helpful to learn more about the birds in your neighborhood.
3.143.9.223