Tweeting Bird Feeder
Tweeting Bird Feeder

This Summer my 5 year old son and I wanted to work on a project that would be fun, educational, and related to nature. While enjoying a beautiful Colorado summer evening on Grandpa and Grandma's deck watching all of the hummingbirds fight over 6 spots on their hummingbird feeder, it came to us. Let's build a bird feeder that takes close up pictures of the birds and posts them to Twitter! We had our work cut out for us. We reviewed what others have created on instructables and found this post Image Capturing Bird Feeder. Since we already had a Raspberry Pi and a Pi Camera we decided to take our own spin on this great idea.

This Instructable will help you build your very own tweeting bird feeder so you too can enjoy the photos from the local birds in your neck of the woods. To clear up the ambiguity, this bird feeder does not twitter /?twit?r/ (verb) - give a call consisting of repeated light tremulous sounds. This bird feeder takes pictures of visiting birds while they are eating and posts these pictures and a bird-related caption to the social media website Twitter.

Step 1: Choose a Bird House Design

Tweeting Bird Feeder

There are many Instructables for building a bird house. Browse through the birdhouse Instructables and find one that you really like. When searching for the perfect one, keep in mind these guidelines:

  • Even though we are making a tweeting bird feeder, we need a bird house to protect the Raspberry Pi and Pi Camera from the outside elements.
  • Choose one that allows you to make a large "window" viewing area; otherwise your photos from inside the birdhouse won't be able to capture the entire bird at your feeder.
  • Choose one that you can modify to build a large platform (at least 6" x 4") to hold the bird food.
  • Choose one that allows you to have a roof over the food since the food won't be inside the covered area where the Raspberry Pi is. Birds don't really like wet or spoiled seeds.

    Step 2: Gather Materials

    Tweeting Bird Feeder

    Assemble all of your materials.

  • Assemble all of the materials for the birdhouse you selected, following their instructions.
  • Raspberry Pi Model B
  • Raspberry Pi Camera
  • 4 GB (or higher) SD card
  • IR proximity sensor (I used this one http://www.adafruit.com/product/164)
  • Raspberry Pi Power cord
  • Raspberry Pi Case (any case that provides a space to run the Pi Camera ribbon cable and 3 wires from the Pi board to the IR proximity sensor)
  • Miniature WiFi USB module (I used this one http://www.adafruit.com/products/814)

    Step 3: Assemble the Bird House

    Follow the instructions on the birdhouse you selected to assemble the birdhouse.

    Step 4: Customize the Birdhouse for the Raspberry Pi

    Tweeting Bird Feeder

    Now it is time to customize the bird house. We will do this by adding a tray to hold the bird seed, creating a large window so the IR proximity sensor can detect birds and the camera can capture full-length photos, making a roof or shelter to cover the bird seed, and also protect the Raspberry Pi from the elements, and making a platform to for the Raspberry Pi.

  • Cut a 6" wide by 4" deep by 0.5" high piece of wood for the platform. The bird seed will be placed on this platform, so you will need one large enough to fit a pile of seeds and also provide room for birds to stand to eat.
  • Attach the platform to the front of the birdhouse.
  • Create a viewing window on the front of the birdhouse directly centered in front of the platform. The viewing window should start 1/4" above the platform and be 5" tall by 5" wide.
  • Create a roof or shelter that extends over the platform. Attach the roof or shelter to your birdhouse so that it covers the entire platform holding the seeds.
  • Cut a piece of wood 2" by 4" by 5". This will provide a raised platform for the Raspberry Pi and IR proximity sensor. Attach the Raspberry Pi platform inside the birdhouse centered with the viewing window, about 1"-2" from the front of the window.
  • I also placed a piece of glass over the viewing area to protect the Raspberry Pi from water and animals that want to get inside the bird feeder. Just remember to place the IR distance sensor on the outside of the glass since the IR will not go through glass.

    Step 5: Attach the IR Proximity Sensor

    Tweeting Bird Feeder
    Tweeting Bird Feeder
    Tweeting Bird Feeder

    In this step we will attach the Sharp IR proximity sensor. The sensor comes with three wires: red, black, and white.

  • Attach the red wire to +5V (pin 2)
  • Attach the black wire to Ground (pin 6)
  • Attach the white wire to GPIO 4 (pin 7)

    Raspberry Pi Version 2 Pinout Photo by PinballSP

    Step 6: Install Raspberry PI OS and Required Software

    There are a lot of tutorials for setting up a Raspberry Pi on RaspberryPi.org.

  • From the Downloads page download Raspbian. You can select your favorite flavor of Linux. I've also built a tweeting bird feeder on Arch Linux.
  • Write the image to the SD card, insert the SD card in the Raspberry Pi and boot it up.
  • Log in as pi user and run the following commands
  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install python-setuptools
  • sudo easy_install pip
  • sudo pip install twython
  • sudo apt-get install python-dev
  • sudo apt-get install python-rpi.gpio
  • Make sure you have the correct version of Python installed. I used Python 2.7.8. Run this command to see what version you have installed.
  • python2 --version
  • Configure your Raspberry Pi to join your WiFi network. Make sure it automatically joins the wireless network at start-up.

    Step 7: Install the Raspberry Pi Camera

    Tweeting Bird Feeder
  • Power down your Raspberry Pi and unplug the power cable.
  • Connect the ribbon cable of the camera module to the CSI port, which is right behind the Ethernet port
  • Plug in the power cable and log in after your Raspberry Pi boots up
  • Open the raspi-config tool from the Terminal
  • sudo raspi-config
  • Select Enable camera and hit Enter
  • Select Finish and reboot the Raspberry Pi when it prompts.


    You can watch a helpful video illustrating how to install the camera on RaspberryPi.org

    Step 8: Create a Twitter Account for your Bird Feeder

  • Create a new account on Twitter for your bird feeder.
  • After creating the new account navigate to https://dev.twitter.com/ and sign in
  • From the pull down in the top right corner, select My Applications
  • Then click Create New App button
  • Fill in all of the required fields.
  • Give your new application Read & Write access level permissions
  • Check the box to Allow this application to be used to Sign in to Twitter
  • Make a note of your API Key, API Secret, Access Token, and Access Token Secret. You will need to enter in these values into the Python program.

    Step 9: Write the Tweeting Bird Feeder Program

    Tweeting Bird Feeder

    In this step you will be writing the Python program that is the magic behind the tweeting bird feeder.

  • Create a new directory for our Python program
  • mkdir /home/pi/tweeting_birdfeeder
  • cd /home/pi/tweeting_birdfeeder/
  • Create a new file for the Python program
  • nano birdie-tweet.py
  • Change the permissions of the file
  • chmod 755 birdie-tweet.py
  • Get birdie-tweet.py from https://github.com/reimey/tweeting-bird-feeder or copy the contents of the program into birdie-tweet.py

    #!/usr/bin/env python

    #######################################################################

    # # Birdie Tweet

    # Takes a picture of a bird when it is at the bird feeder and tweets it to Twitter.

    #

    # This program requires python2 and twython

    # # Author: Mark Reimer

    # Date: August 3, 2014

    #######################################################################

    from twython import Twython

    from subprocess import call

    import time

    import random

    import RPi.GPIO as GPIO

    # Initialize GPIO

    GPIO.setmode(GPIO.BCM)

    GPIO.setup(04, GPIO.IN)

    # GPIO4 is pin 7

    # Twitter Token

    APP_KEY = ''

    APP_SECRET = ''

    ACCESS_TOKEN = ''

    ACCESS_TOKEN_SECRET = ''

    # How much time in seconds to sleep before looking for another bird

    SLEEP_DURATION = 30

    # Twitter messages to use when tweeting

    messages = []

    messages.append("The early bird gets the fresh seeds. #birds #birdwatching")

    messages.append("This bird just took a selfie. #birds #birdwatching")

    messages.append("Thanks for visiting the tweeting bird feeder. #birds #birdwatching")

    messages.append("Another happy bird served. #bird #birds #birdwatching")

    messages.append("Who ruffled her feathers? #bird #birds #birdwatching")

    messages.append("Show me your birdie. #birds #birdwatching #bird")

    messages.append("A #bird on the feeder is worth two tweets. #bird #birds #birdwatching")

    messages.append("Free as a bird. #birdwatching #birds #bird")

    messages.append("Intelligence without ambition is a bird without wings. -Salvador Dali #birdwatching")

    messages.append("A bird sitting on a tree is never afraid of the branch breaking, because her trust is not on the branch but on its own wings. -unknown")

    messages.append("I think we consider too much the good luck of the early bird and not enough the bad luck of the early worm. -FDR #birdwatching")

    messages.append("Hold fast to dreams, for if dreams die, life is a broken-winged bird that cannot fly. -Langston Hughes #birds #birdwatching")

    messages.append("Faith is the bird that feels the light when the dawn is still dark. -Rabindranath Tagore #birdwatching #birds")

    messages.append("A fish may love a bird, but where would they live? -Drew Barrymore #birds #birdwatching")

    messages.append("If you cannot catch a bird of paradise, better take a wet hen. -Nikita Khrushchev #bird #birdwatching")

    messages.append("Some newspaper articles are fit only to line the bottom of bird cages. #birdwatching #birds #bird")

    messages.append("Some birds aren't meant to be caged. Their feathers are just too bright. -Stephen King #birdwatching #birds")

    messages.append("You're so vain, you probably think this selfie is about you. #birdwatching #birds")

    messages.append("In order to see birds it is necessary to become a part of the silence. -Robert Lynd #birdwatching #birds")

    messages.append("He imagines a necessary joy in things that must fly to eat. -Wendell Berry #birds #birdwatching #bird")

    # wait for proximity sensor

    while True:

    if (GPIO.input(04)):

    try:

    # Take a picture. I mounted the camera upside down with the ribbon cable going up. So I use the option to vertically flip the image.

    call("/opt/vc/bin/raspistill -e jpg --vflip -w 320 -h 320 -q 100 -o /tmp/snapshot.jpg", shell=True)

    # Sign in to Twitter twitter = Twython(APP_KEY, APP_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

    # Post a status update with a picture

    photo = open('/tmp/snapshot.jpg', 'rb')

    r = random.randint(0, len(messages)-1)

    message = messages[r]

    twitter.update_status_with_media(status=message, media=photo)

    except:

    print("Unexpected error:")

    # Sleep so that multiple pictures aren't taken of the same bird

    time.sleep(SLEEP_DURATION)

    else:

    time.sleep(0.25)

    5. Save the file and exit nano

    6. If you copy and paste the source code above, remember to go back and update the tabs or spacing since Python is strict about spacing.

    Step 10: Sit Back and Enjoy the Show!

    Tweeting Bird Feeder

    It sometimes takes a little while for birds to discover and start using a new bird feeder. Just be patient. They will come.

    The other day I caught this hungry squirrel on camera eating some bird seeds.

  •  
     

    Tag cloud

    make build easy simple arduino making homemade solar laser printed portable cheap mini building custom cardboard wooden create super lego turn paracord chocolate your paper light intel