A brief overview of a bird feeder that triggers a camera

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!

Prepare for lift off

In order to build this interactive pet feeder, we need the following items:

Engage thrusters

  1. The first step involved in programming Spark Core is to detect the motion sensor events and publish those results to Raspberry Pi.
  2. The sensor needs to be connected to SparkCore mounted on the breadboard as shown in the following figure:
    Engage thrusters

    A motion sensor connected to Spark Core

  3. We will modify the example from Adafruit that prints the motion sensor events (https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/using-a-pir).
  4. Whenever a motion event is detected, we need to send an alert to the 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");
    }
  5. In order to take pictures of the bird feeder when there is an incoming motion detection event, the camera has to be interfaced to the Raspberry Pi as demonstrated in the video provided by the Raspberry Pi Foundation (https://www.youtube.com/watch?v=GImeVqHQzsE).
  6. In order to trigger a camera to take a snapshot using the python-twisted server, we need the picamera module (https://pypi.python.org/pypi/picamera). It can be installed as follows:
    sudo apt-get install python-picamera
    
  7. Let's modify the python-twisted example, simpleserv.py, to import the picamera and datetime modules (to name the pictures captured by the camera using a timestamp).
  8. If the incoming message is Motion Detected, we will take a picture and name the file using a timestamp.
  9. In the callback method, 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')
    Engage thrusters

    A bird trigger

Objective complete – mini debriefing

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.

Alternatives and project ideas to consider

  1. In this project, we discussed the examples using the Spark Core and the Arduino Ethernet board. Another example to consider is the EPS8266 module, which is available at http://www.banggood.com/buy/Esp8266.html, and costs about 3 USD. Refer to this book's website for setting up the ESP8266 module to emulate these examples.
  2. In Project 4, Christmas Light Sequencer, we used a Power Switch Tail and a relay board example to control decorative appliances. Similarly, we can use them to control automatic pet feeders to dispense treats.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.9.223