Tweeting Bird Feeder





Introduction: 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

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

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
  • 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

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

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.

  1. 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.
  2. Attach the platform to the front of the birdhouse.
  3. 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.
  4. 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.
  5. 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.
  6. 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

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

  1. Attach the red wire to +5V (pin 2)
  2. Attach the black wire to Ground (pin 6)
  3. 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

  1. 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.
  2. Write the image to the SD card, insert the SD card in the Raspberry Pi and boot it up.
  3. 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
  4. 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
  5. 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

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

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

Step 8: Create a Twitter Account for Your Bird Feeder

  1. Create a new account on Twitter for your bird feeder.
  2. After creating the new account navigate to and sign in
  3. From the pull down in the top right corner, select My Applications
  4. Then click Create New App button
  5. Fill in all of the required fields.
  6. Give your new application Read & Write access level permissions
  7. Check the box to Allow this application to be used to Sign in to Twitter
  8. 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

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

  1. Create a new directory for our Python program
    • mkdir /home/pi/tweeting_birdfeeder
    • cd /home/pi/tweeting_birdfeeder/
  2. Create a new file for the Python program
    • nano
  3. Change the permissions of the file
    • chmod 755
  4. Get from or copy the contents of the program into

#!/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.setup(04, GPIO.IN)

# GPIO4 is pin 7

# Twitter Token

APP_KEY = ''




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


# 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)):


# 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)


print("Unexpected error:")

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




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!

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.

Microcontroller Contest

Runner Up in the
Microcontroller Contest



    • Creative Misuse Contest

      Creative Misuse Contest
    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest

    32 Discussions

    atanguay, thanks for leaving this comment. Please let me know if you run into any challenges or if any of the instructions aren't clear.


    Thanks for the kind feedback. The Twitter handle is @MrReimey.



    Question 5 weeks ago

    Hello, say if a raspberry pi version 2 camera has an ir sensor built in then will we I need to purchase the IR sensor?

    what if the pi camera has motion detection built in?

    Here is a huge list of cities that have live web cams / photos of nesting birds including Eagles, Hawks etc. there is one in my city! Look for yours! Enjoy!

    The sites listed below feature live streaming bird cams, updated videos, and/or updated photographs of nesting wild birds. You can follow the efforts of the parents and the progress of the young birds by periodically visiting these nest cam sites.

    Great project, really cool, I haven't looked at the motion sensor for the pi at all, but I'd imagine you could tweek it to not trigger when the person comes out the door.

    wavelet_spaghetti, that is a great idea. I have been dreaming about making one specific to birds of prey so I can capture close up photos of hawks and eagles.

    How is the improved design coming along? Any developments?

    I've been following your twitter and You should fix the fact that empty pictures are posted. I don't know what the exact problem is but it is a bit weird. Just some hints.

    3 replies

    Hi dmoonen. Thanks for following my Twitter feed. Yes, that is the biggest problem that I am working on right now. I'll share with you what I've seen in hopes you have some great ideas that can help me fix it. One problem I've seen is that raspistill program that I'm using to take the picture takes on average 1500 milliseconds to snap a picture after you call the program. For many birds this is too long--they won't loiter long enough and fly off after grabbing the first seed they see. The second problem I've observed is that I'm using an IR sensor to detect the proximity of a bird. IR is sensitive to sunlight as well as abrupt temperature swings (I think). At first I thought the sensor was bad so I swapped it out with another IR sensor and that didn't fix it. I even swapped it out with a pressure pad that detected the weight from a bird but that gave me mixed results. I realized the best way is to remove the sensor all together and continuously record video, just like a DVR. Then when I detect a bird in the frame of the video, I can capture that frame as an image and post it to Twitter. I've written the software that does this using OpenCV. This software has the added benefit of being able to identify the type of bird based on its colors. When I tried to install OpenCV on my Raspberry Pi, I quickly realized OpenCV doesn't support non-USB based cameras (such as the Raspberry Pi camera). Right now, I'm working on writing drivers for the Raspberry Pi camera so that Open CV will recognize it. Unfortunately this is taking me a while since writing the driver in C is more complicated, but I am making progress. I am very excited to get this completed, so I can post another instructable and start to identify the birds that are in the image.

    This is very fascinating. I already thought the sunlight was the problem.
    From the top of my head I would do this.
    Why not use a IR sender and a receiver. (You can shield this ones of from indirect IR light) If the beam is disrupted the program makes a picture. Something like some shops use to ring a bell when you walk in.

    But your software solution is really cool and inventive. Well done!!!

    That is a great suggestion. I was speaking with an Engineer at work and he actually told me the same thing. Are you Corey? I would do this if I could figure out how to do it and make it still look like a natural bird feeder. Maybe I can embed the IR sensor and receiver in wood with holes drilled through so they can communicate? What do you think?