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

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 RaspberryPi.org.

  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 RaspberryPi.org

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 https://dev.twitter.com/ 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 birdie-tweet.py
  3. Change the permissions of the file
    • chmod 755 birdie-tweet.py
  4. 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!

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.

Comments

author
atanguay (author)2014-09-09

Well, here's my girlfriend's Xmas present just waiting to happen. Awesome

Thanks!

author
Reimey (author)atanguay2014-09-09

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.

author
dmoonen (author)2014-09-07

Can you share the twitter? I can't really find it.

author
Reimey (author)dmoonen2014-09-09

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. https://twitter.com/

author
Reimey (author)dmoonen2014-09-08

Thanks for the kind feedback. The Twitter handle is @MrReimey. https://twitter.com/MrReimey

author
mworrall (author)2014-09-09

I thought it was going to be a bird feeder that twittered to the birds.

author
Reimey (author)mworrall2014-09-09

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. https://twitter.com/

author
parisusa (author)2016-09-04

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!

www.viewbirds.com

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.

author
dmoonen (author)2015-03-31

So how is it? Any new ideas?

author
jack.baldwin.712 (author)2015-03-05

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.

author
wavelet_spaghetti (author)2014-11-19

love this! you should make more of these with HD cameras and place them in trees in nature reserves!

author
Reimey (author)wavelet_spaghetti2014-11-20

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.

author
dmoonen (author)2014-11-04

How is the improved design coming along? Any developments?

author
wisconsinjimmy (author)2014-09-19

Can this be done with an Arduino 2560?

author
dmoonen (author)2014-09-11

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.

author
Reimey (author)dmoonen2014-09-11

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.

author
dmoonen (author)Reimey2014-09-11

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

author
Reimey (author)dmoonen2014-09-11

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?

author
dmoonen (author)Reimey2014-09-15

Hey,

Me again. I was thinking. Couldn't it be possible to change the camera to a gopro? It will take some programming I guess but you will get a very nice wide angle. (with you have to seem a problem with?) Also if you wan't to keep it natural you can just make it a bit bigger.

author
Reimey (author)dmoonen2014-09-15

Hi again,

Yes, I hadn't thought of that. You could definitely use a go-pro camera which would take some fabulous pictures! The only problem is that they cost more than $29 (cost for a raspberry pi camera). I could also make the bird platform smaller to force the birds to have to stand in the viewing area. I was thinking about what you said earlier and found these IR emitter / receiver on SparkFun. https://www.sparkfun.com/products/241 They would work great in establishing an IR beam that, when the birds crossed it, would trigger the presence of a bird on the feeder. I could place them inside of a hollowed out stick so they look natural. What do you think?

author
dmoonen (author)Reimey2014-09-15

Seems nice. but reading through the comments on that page they are a litte bit sensitive to external light. You should be able to fix this by fitting sort of an funnel on the receiver (just drilling it a bit deeper in the wooden stick might do the trick)-. You whould need to be really precise about the placement of the sender then.

About the platform: Make it a bit longer birds will be more in frame) and fit a nice little roof on top so they have to come in from the front.

Keep us up to date!!!

author
dmoonen (author)Reimey2014-09-11

Ha, Well I am not Corey, that is for sure. I live in Belgium. :-D

But it is a great idea, But you will have to experiment with the distance between the two.

author
smoss20 (author)2014-09-09

As a bird lover, this is a great idea. I have a Pi I'm not using so I'll set a reminder for March

author
mworrall (author)2014-09-09

I thought it was going to be a bird feeder that twittered to the birds.

author
jennace (author)2014-09-08

This is so super cool! I can see this becoming a huge Twitter sensation. I wish I had one for myself. Maybe you will share your Twitter handle with me?

author
Reimey (author)jennace2014-09-08

Thank you very much. The twitter handle is @MrReimey. https://twitter.com/MrReimey

author
memjr73 (author)2014-09-07

This one made me chuckle ?

author
dubdubdubstep (author)2014-09-07

At first I thought it was a bird feeder that used Twitter

author
MsSweetSatisfaction (author)2014-09-07

That's a really cool concept! Thanks for sharing!

author

MsSweetSatisfaction, thank you very much for the kind words. We've been having a lot of fun watching our bird feeder's Twitter feed.

About This Instructable

18,711views

112favorites

License:

More by Reimey:Real Pokemon BallsTweeting Bird Feeder
Add instructable to: