Tuesday, January 8, 2019

Automatic Chicken Watering Cup System

Over the past year, my wife and I tried our hand at raising backyard chickens for eggs.  We had a lot of fun, and learned a lot along the way, until our little chicken experiment came to an abrupt end shortly before the new year.  A predator (our research leads us to believe it was a raccoon or weasel) found a way inside the coop one night and killed the entire brood.  Since we don't plan to immediately acquire new chickens, I have decided to shut-down the website I started to chronicle our chicken adventures, and migrate some of the articles to this blog.  Below is such an article.  If you are interested in reading more about our experience raising backyard chickens, let me know in the comments below.  Thanks for reading.

The Watering System


Chickens are ironic creatures.  They require constant access to fresh, clean water, but given the first opportunity they will kick dirt and grass into it, walk in it, and even defecate in it if they happen to be standing in it when the urge strikes.  When we first started raising chickens, we used old pie tins as water dishes. These quickly proved inadequate as the chickens not only filled them with dirt constantly, but also walked in and on them so that they bent the sides down, spilling the water.  In a search for a more elegant solution, I came across Automatic Chicken Watering Cups on Amazon, and decided to give them a try. I’m glad I did, as they turned out to be an excellent way to keep clean water available for our chickens for days at a time.

Before I took the plunge and ordered my Chicken Watering Cups, I scrolled down to the customer reviews to make sure I wasn’t wasting my time and money.  It appeared that most of the negative reviews were from people that used these cups by mounting them directly into a bucket, or drilling the PVC themselves, and the result was a leaky watering system.  Another quick search on Amazon revealed a simple solution: Horizontal PVC T-Fittings with ⅛ inch female threads that were specifically designed to fit items with ⅛” threads like the Chicken Watering Cups.  Coincidentally, Chicken Water Nipples also have ⅛ inch male threads, so if you wanted to give those a try, you could use the same PVC T-Fittings.

Material List:


*Disclaimer: I purchased some of the items above at my local hardware store.  For your convenience I have included Amazon links to all items on the material list in case you would like to purchase everything at once and save a trip to the store. I have placed an asterisk next to the items that I did not purchase off of Amazon to make you aware, since I cannot vouch for their quality.  That being said, Amazon has an excellent return policy if anything you receive is not up to par.

My basic plan was to use a 5-gallon bucket as a reservoir, and to feed the water from the bucket to the watering cups with ½” SCH-40 PVC.  PVC is great for this project because is it durable, sun-proof, easy to work with, rigid enough to not need too much support, and most importantly, very inexpensive.

Below is a sketch of my layout, which also worked as my cut-list.  As I said before, your chicken environment will likely differ from mine, so your specific design and cut-list will also differ.  Just be sure to measure everything precisely. As the old saying goes: measure twice, cut once. If you have any questions about adapting my design to your environment, please ask in the comment section below and I will do my best to answer.


To begin, let’s drill the bucket.  The diameter of the male threaded end of the coupler (8) that goes through the hole in the bucket is slightly larger than 7/8″.  I used a 7/8″ spade bit to drill the bucket, and then widened the hole slightly with a knife, which shaved the soft plastic easily.

If you work with PVC all the time then you probably have a PVC pipe cutter, but if you don’t, there is no need to buy one unless you don’t own pretty much any other type of saw.  I used an upright bandsaw with a miter gauge to cut my PVC, but if you don’t have a bandsaw you can use a hacksaw, miter saw, or any saw that is made for wood or metal because PVC is relatively soft. To eliminate any possible confusion, after I cut each piece I used an ultra fine point Sharpie to write the length on each piece.

Once all the pieces are cut you will need to chamfer the edges by taking a blade and running it across the inside and outside edge of each length of PVC, removing any burrs left from cutting, and leaving a small 45 degree angle around both edges.  When all the pieces are ready it is a good practice to dry assemble the entire project to make sure everything fits as you planned it. Be sure to assemble the T-fittings so that the threaded receptacle will be parallel to the ground, or else your watering cup will end up tilted and the water will spill out.

At this point, while it is still dry assembled,  I like to use a sharpie to draw lines at each junction, originating on the joint, and continuing onto the length of the pipe for about an inch.  This ensures that once you apply the PVC primer and cement, you can align the pieces in the exact same orientation you did when they were dry-assembled.  It is easy to make a mistake while you are assembling the PVC, and once it is fused, there is no way to take it apart again. Be sure to draw the line at least one full inch up the PVC because once you add the primer and cement, the PVC will actually seat further up into the joint than when dry, and you want to make sure you can still see some of the line.

To bond the PVC together, first make sure you are in a well ventilated area.  While the primer and cement are both non toxic once cured, they are very toxic if inhaled.  You may also want to put down a drop cloth because the purple primer can stain. Apply two coats of the primer to both the inside of the joint, and the outside of the length of PVC with the provided applicator.  You can be fairly liberal with the primer, just be sure you don’t erase the entire length of line you drew to align the pieces because the primer will instantly erase the sharpie.

Next you will want to apply a liberal coat of the cement to the outside of the length of PVC and a thin coat to the inside of the joint.  To achieve this, I like to dip the applicator into the cement, and wipe off any excess on the rim of the can. First apply the cement to the outside of the length of PVC, then apply to the inside of the joint with what is left on the applicator, without dipping back into the can of cement.

As soon as the cement is applied, push the two pieces together, paying close attention to your sharpie marks to line up the pieces correctly.  While you hold them together for 30 seconds, the cement will actually melt the PVC, fusing the two pieces together. This creates a permanent bond that cannot be unwelded, which is why it is so important to make sure your pieces are lined up the first time.

Once you have repeated the process for the entire length of PVC you will want to let it cure for 24 hours.  At this point the cement and primer is 100% non-toxic, and cannot hurt you or your chickens, although I still like to flush the pipe out with water, just for piece of mind.

The section of PVC that attaches to the bucket does so mechanically by attaching the threaded male and female connectors specified in the drawing at the beginning of this section, but the seal will not be water tight.  Sealing the joint between the PVC and the bucket can be accomplished with a rubber washer or O-ring, but I simply used a silicone caulk to make the seal.

When installing the bucket and PVC in its final location, it will be necessary to raise the bucket up off the ground so that gravity will force the water through the entire length of pipe with enough force that the cups will fill up quickly when the yellow dongle is pushed or pulled.  Six 8”x8”x16” cinder blocks stacked two by two did the trick for me, setting the bottom of the bucket approximately 24” off the ground.

At this point the cap can be put on the other end of the PVC structure, and the cups can be screwed into the T-fittings.  Be sure not to over-tighten the cups on the T-fitting or they will leak. If you have leaks at the junction of the cup and the PVC when you test it out, try loosening the cup one turn to see if it solves the problem.

The part of the PVC with the cups should be fastened securely to some surface, such as the wall of the coop or the run, so that cups will sit about 6 inches off the ground.  The chickens will walk and perch on the PVC, so you want it to hold tight enough not to stress the joints. I found that two-hole conduit straps for ¾” EMT fit the ½” PVC perfectly, and hold it rigidly enough as to not allow it to bend under the weight of the chickens.  Plastic tie wraps (aka cable-ties or zip-ties) work well for additional support, but should not be used as the main supports because the sun will eventually cause them to turn brittle and break.

And that’s about it.  Connect the PVC sticking out of the bucket to the PVC attached to the run with the PVC Union, fill the 5 gallon bucket with water, and open the PVC valve.  You can then test the watering cups by pulling upwards slightly on one of the yellow dongles to see if the cup fills with water. If it does you’re in business.  Fill up all the cups so that the chickens can see the water, and let them at it. If they don’t start drinking out of it right away, try removing any other sources of water to force them to figure out how to use it.

We’ve had great success with the Automatic Chicken Watering Cups.  The smarter chickens in the bunch caught on immediately, and the rest of them figured it out not long after.  The one downfall of this system is that it won’t be able to be used after temperatures drop below freezing, but in this part of Virginia that will mean that it can be used for about 8 months out of the year, which is enough to make it worth it to me.

If you try this solution, let us know how it worked out for you in the comments.  Also, if you run into any problems building it, or getting it to work properly, feel free to leave your questions in the comments and I’ll do my best to help you out.


The Great Chicken Swap



Over the past year, my wife and I tried our hand at raising backyard chickens for eggs.  We had a lot of fun, and learned a lot along the way, until our little chicken experiment came to an abrupt end shortly before the new year.  A predator (our research leads us to believe it was a raccoon or weasel) found a way inside the coop one night and killed the entire brood.  Since we don't plan to immediately acquire new chickens, I have decided to shut-down the website I started to chronicle our chicken adventures, and migrate some of the articles to this blog.  Below is such an article.  If you are interested in reading more about our experience raising backyard chickens, let me know in the comments below.  Thanks for reading.

So It Begins


My wife Courtney and I had been talking about raising backyard chickens for a while, so when our friends Jeff and Katie told us they were putting their house on the market, and needed to find a new home for their brood, we knew it was time to take the plunge.  Over the next several weeks we cleared out a space at the top of our yard and began building an environment for the chickens. Having zero experience with chickens, and being unsure exactly what we would need, I only built what I thought would be the bare essentials, a cinder block pad to protect their coop from burrowing predators, a chicken tractor/run to give them some space outside the coop, and a compost bin to dispose of their droppings.  Since Jeff and Katie were going to give us the coop that the chickens were currently living in along with the chickens, we decided we had everything we needed to get started, so we set a date and began to plan for The Great Chicken Swap.

We quickly realized that none of us had any experience with transporting 7 full-grown chickens, and this might be more difficult than it had seemed at first.  After scrapping our first few schemes, Jeff came up with the idea of loading the coop onto a trailer and transporting the chickens inside their own coop. Despite the potential for many things to go wrong with this plan, it was the best idea we had come up with so far, so we decided to give it a go.

The weekend of the move finally arrived, and I was filled with conflicting feelings of excitement about our new found feathered friends, and apprehension about what could go wrong with our somewhat questionable plan to transplant them.  Jeff called me mid-day and said that the chickens were out in the yard, and I could come by to help load the coop on the trailer whenever I was ready. Moving it was easier than we expected. At that point there was nothing to do but wait, and hope that the chickens returned to their relocated coop at sun-down.  Sure enough, like clockwork, as the sun set the hens retired to their perches inside the coop as it sat on the trailer. With a few ratchet straps securing the coop to the trailer, Jeff skillfully navigated the chickens from their house to ours. Surprisingly, the chickens tolerated the whole process very well, and didn’t seem flustered in the least when they arrived in our yard.  To keep their disruption to a minimum, Jeff simply unhitched the trailer, and left it in our yard overnight.

On Sunday morning I woke up with the sun, excited to welcome our flock to their new home.  They seemed equally excited to be let out of their coop, so I set up some temporary fencing to guide them from the coop to the chicken run I had built for them.  With that accomplished, Courtney and I proceeded to unload the coop from the trailer onto the cinder block pad. Once again, everything went much more smoothly than anticipated.  We proceeded to build a tunnel out of stiff fencing material between the coop and the run so the chickens could traverse between the two. Then it was time to make some coffee and take the opportunity to rest and watch the chickens adapt to their new surroundings.  They even had the courtesy to lay five eggs for us that first morning to provide a late, but much appreciated breakfast.

Over the next week we continued to improve their environment by fencing in an area next to the garden with chicken wire so they could have a place to run around and eat grass and bugs during the day when we are home to keep an eye out for predators.  I built a second tunnel between the grassy area and the run to make moving them in and out easy. I also built a watering system for them that I will outline in another post in case anyone would like to build something similar. They have been laying 5 to 6 eggs per day, which is not bad for seven chickens, some of them already three years old.

We have lots of plans for the future.  I would like to expand their environment as time and money permit.  I also have a few more necessities to build, like a dust bath so they will stop making their own in places I would rather them not dig out.  I have also purchased a solar panel and battery so we can bring these chickens into the 21st century with some modern electrical amenities. I plan to use a Raspberry Pi (small single board computer you can read about here) to automate a few things like filling up their water system, dispensing their nonperishable feed, and automatically opening and closing the coop door at dawn and dusk.  And since I will already have power and a computer, no coop would be complete without a live streaming chicken-cam. Eventually I would also like to expand our flock by bringing in a few more birds, but one thing at a time.  For now it’s enough to let the hens get used to their new home, as we get used to life raising backyard chickens.

Sunday, September 30, 2018

Cat Shelves

Here's a quick, easy project for all you feline fanatics out there.  Cats need a place to jump, climb, and scratch, and if you don't give it to them, they will jump, climb, and scratch all over your furniture.  We recently adopted a new kitty, and to welcome her to our home I decided to build a set of "cat shelves" (for lack of a better word), to give her a place to climb around in our living room.


The idea is rather simple, and I didn't think of it on my own.  There are plenty of examples of this sort of thing floating around the internet, I just adapted it to the available space and decor of the room in which I wanted to install it.

I made the shelves out of inexpensive 1"x8" pine boards that you can pick up at any big-box hardware store, or if you're like me, you might even have some lying around in your scrap lumber pile.  I measured the area, put my design down on paper, and cut the boards to the desired lengths.

Next I pulled out a router with a Roman ogee bit to add a little decorative detail to the edges.  I made a couple of passes around the three exposed edges of each board, and then went over the whole board with 220 grit sandpaper to prepare it for painting.

I painted the bottom face as well as the three routed edges, first with primer, then with two coats of flat white interior paint.  Once the paint was dry it was time to install the carpet for the top of the shelves.



I stopped by a local carpet store, told them what I was doing, and asked if they had any remnants they could sell me.  Instead they showed me some scrap they had lying around and told me I could take what I needed from that, so the carpet cost me nothing.

I cut the pieces I needed with a razor blade, and trimmed them up with scissors.  I used Liquid Nails to adhere the carpet to the pine board, which I may have done differently if I had it to do over again.  The Liquid Nails bonds excellently, but it has a seven day cure time, and stinks of solvent the whole time it is curing, so it delayed me bringing these into the house for longer than I had planned.

As for how to mount the cat shelves on the wall, I left the decision up to my wife.  She picked these decorative brackets from Amazon, and I think they compliment the room excellently.  It's important to take one's time and use a level to make sure the shelves are mounted in a visually appealing fashion.


In addition to the shelves, I also added a "climbing wall" to the area.  I had a couple of 2'x'2 carpet tiles lying around that I cut into sections and mounted to the wall by using drywall screws through the carpet and into studs behind the drywall.  The cat can then climb up the carpet on the wall to reach one of the platforms.  This provides her exercise, as well as gives her a chance to scratch something other than the furniture.


I hope you've enjoyed this short but entertaining project.  Hopefully it will inspire some of you to build your own cat-play-area.  If you have any questions about adapting this design to your own space, please let me know in the comments below.  Thanks for reading.

Friday, September 7, 2018

Using the Raspberry Pi to Pen Test Wireless Networks or The Coconut-Pi

Inspired by Hak5's wireless pen testing device named the Pineapple, I decided to pair a Raspberry Pi with a USB WiFi Adapter to create a small, portable device for monitoring wireless traffic, analyzing  wireless access points, or penetrating wireless networks.  Because the Pineapple was my inspiration, and I used a Pi as the basis, I've decided to whimsically call this device the Coconut-Pi.  Because of the potential for one to use this device for evil, I will place the standard disclaimer here:  I am not advocating the use of this device for anything illegal.  Do not attempt to gain access to any network that you have not been given permission to access.  Do not use this device to spoof any network with the intention of tricking people into logging onto your device.  Despite the fact that I find these disclaimers pointless and ineffective, seriously, prison does not seem like a good place to end up, so please use the following information responsibly.

The idea is fairly basic.  It uses a Raspberry Pi  connected to a USB WiFi Adapter capable of being put into monitor mode.  The Pi 3B comes with on-board WiFi, but the chip on the Pi does not support monitor mode, so the adapter is required.  Specifically, I used an Alfa AWUS036NHA long range USB Wifi Adapter, which utilizes an Atheros AR9271 chipset.  There are probably better WiFi adapters I could have used, but I purchased this adapter years ago, specifically because it could be put into monitor mode, and the driver came preinstalled on Kali Linux.  Conveniently enough, the driver is also included with Raspbian Lite, which is the OS I will be using.  If we want to make this rig portable, we can't forget the 5V rechargeable Li-ion battery as well.

One could ask the question, if this is supposed to be a pen testing rig, why would you use Raspbian Lite instead of Kali Linux, since Kali has also been ported to work on the Raspberry Pi?  The answer is simply, in my opinion, Kali does not run well on the Pi.  It's been a year or two since I tried it, so I can't remember exactly where it fell short, and there may have been improvements since then, but I prefer to stick to using Raspbian on the Pi whenever practical.  We will mainly be using Aircrack-ng and TCPDump, both of which are in the Raspbian repositories, and since both Kali and Raspbian are Debian-based, anything else that I end up needing down the road can also be installed on Raspbian.

When I first conceived of this project, my intention was to use a Raspberry Pi Zero.  I planned to use the Pi's UART to console into the Pi from a laptop, and then use a male micro USB OTG to female USB-A adapter to connect the WiFi adapter to the Pi.  This would have worked well, and I still may build that in the future, but since the Pi uses 3.3V TTL for serial communication on it's UART, I would need either a TTL to RS-232 converter (max232) or TTL to USB converter, and I didn't have either lying around in my shop.  I did order a couple 3.3V TTL to USB converters, but even with Prime 2-day shipping, I didn't have the patience to wait on it to arrive, so I redesigned the project using a Pi model 3B.  With the Pi 3B I can use the Ethernet port and a cross-over Ethernet cable to connect my laptop to the Pi, so no level shifter is required, and the Wifi adapter can plug directly into one of the 3B's female USB-A ports.  Bottom line, I ended up using a more expensive Pi, but saved some money on adapters, so based on cost there is little difference between the designs.

Setting up the Raspberry Pi


There really isn't too much set-up to this project.  I installed Raspbian Lite on an SD card, stuck it in the Pi, and did the basic Pi set-up (changed password, expanded the file system, enabled SSH, changed locale, timezone, and keyboard configuration, etc.).  If you need any instruction on doing basic set-up for the Pi, see my first Raspberry Pi post here.  The Pi will need an internet connection to do installation from the repository, and I'll be using the Ethernet port to connect to my laptop, so I set the Pi's built-in wifi to connect to my home network.  Another way to do this would be to change the settings on the laptop to allow the Pi to share the laptop's internet connections, but I chose not to do that.  As I mentioned before, to connect the laptop to the Pi I used a cross-over Ethernet cable, which simply swaps pins 1&2 with 3&6.  These days, thanks to auto-MDIX, you can use any old Ethernet cable and get away with it, but I'm stuck in the past, so I made a short cross-over cable for this project.

At this point, you will either need to assign static IP addresses in the same subnet on both your laptop and your Pi, or simply allow them to assign themselves their own link-local addresses via DHCP.

If the Ethernet ports on both your Pi and your laptop are set to DHCP, when you connect them directly they will soon realize that there is no DHCP server to give them an address.  Once they become aware of this, they will assign themselves IP addresses from the link-local address space of 169.254.0.0/16.  You will then need to find the Pi's self-assigned address by using the command: ifconfig.

If you choose to use static IP addresses, be sure to choose an obscure subnet such as: 172.30.253.0/30 to avoid conflicting with any wifi network you might be auditing.  Using this example, the /30 subnet (or 255.255.255.252) only has two assignable IP addresses, so we'll call the Pi ".2" and the laptop ".1".

To change the IP address on the Pi, find your Ethernet interface name with ifconfig, and edit /etc/dhcpcd.conf to add the following lines:

interface enx...  # replace enx... with your interface name
static ip_address=172.30.253.2/30


To change the IP on my laptop running Kali Linux I went to Settings>Network>Wired>Add Profile... and created a new profile with the following settings:

Address: 172.30.253.1
Netmask: 255.255.255.252
Leave Gateway and DNS blank

To change the IP on my laptop running Windows 10 go to Control Panel>Network and Internet>Network Connections>Ethernet>Properties>IPv4 Properties and set the following:

IP Address: 172.30.253.1
Subnet mask: 255.255.255.252
Leave everything else blank

Up until this point we have needed a monitor and keyboard to do the initial configuration on the Pi, but now that we can remotely access the Pi using our laptop, we can do everything else via SSH. (Actually it is possible to do all the prior steps headlessly as well, but that is slightly more complicated, and a subject for another post.)

If you're using Linux you can SSH into the Pi using:

ssh -l pi 172.30.253.2
(obviously if you used a different IP address then use that instead)

And in Windows I like to use Putty for SSH.  Since I will be using this connection again in the future I made sure to save the Session for future use.

So now we're logged onto the Pi, and the Pi has internet access via its wifi, so let's install aircrack-ng and tcpdump:

sudo apt-get update
sudo apt-get install aircrack-ng tcpdump -y

And that's it.  The Pi is ready for its initial mission.  Plug in the Wifi adapter, watch the lights flash, and run ifconfig to verify the Pi recognizes it.  I'm sure that I will install additional functionality in the future, and scripts will be written to simplify tasks, but for now, we should be good.  To test to make sure everything is working run:

sudo airmon-ng

note the Interface name of your Wifi adapter

sudo airmon-ng check
sudo airmon-ng check kill
sudo airmon-ng start wlx...  # replace wlx... with your interface name noted above

If you are using a new version of Raspbian (Stretch or later) which uses predictable network interface names, after the command above you will receive a message that the name is too long, and it will be renamed using the old style, which in this case is wlan1 (or more specifically wlan1mon now that it's been put in monitor mode.) Quick note, I put the three commands above followed by another airmon-ng into a bash script so I can now put the adapter into monitor mode with one command.

So now that we've got a WiFi interface in monitor mode, what can we do with it?  First let's see what Wifi networks are in range with:

sudo airodump wlan1mon

This gives all sorts of useful information, such as channel, encryption, and BSSID, which can be used for a number of different useful tasks such as capturing encrypted handshakes or monitoring traffic  on a specific network.  Speaking of monitoring traffic, now that we're in monitor mode, we can also use tcpdump to literally pull wireless packets out of the air like so:

sudo tcpdump -i wlan1mon

This information can be fed back to the laptop, or to a desktop, to be analyzed by Wireshark or any script you can dream up.  Any unencrypted traffic will be easy to decipher.

So that is as far as I'm going to take this post.  I may make another post on using this device in more detail in the future, but for now there is plenty of information out there on using aircrack-ng and tcpdump.  Since we have two WiFi interfaces on this device, one could even do a man-in-the-middle set-up if one was so inclined, but I would like to stress once again that I strongly advise against using this device for any illegal activity.

What do I plan on using this device for?  It's intended purpose is wireless network auditing.  I plan to write a python script that analyzes the data from the output of airodump-ng.  For example, if the Coconut-Pi detected two networks of sufficient strength operating on the same wireless channel it could note that on an audit so that it could be adjusted.  I'll also admit that sometimes when you are sitting in a hotel room it can be entertaining to watch the wireless traffic just to see what people send through the air unencrypted.  It will make you value a home VPN server even more.

One last thing I'd like to mention is that if one were to use this device to capture a wpa2 handshake with the intention of trying to crack it, whatever you do don't use the Raspberry Pi for hashing.  I imagine you might be able to do it faster with pen and paper.  I joke, but seriously, use a different machine for hashing, unless you are cracking something for future generations to see long after you're deceased.

Wednesday, August 22, 2018

Voyeur Bluebird House with a Raspberry Pi

     Previous readers of my blog may remember my initial foray into filming birds using the Raspberry Pi.  That first experience was inspired by coincidence, as a family of wrens made their nest on the windowsill of my basement workshop, and proceeded to raise five young babies.  I built a small wooden enclosure to house a Pi, motion detector, and camera, and set it on the windowsill adjacent to the nest.  Each time the mother flew in to feed the babies, or the babies started to move outside the nest, the camera would turn on, and continue to film until movement had ceased.  I enjoyed the process of filming these birds so much, that I decided to try to recreate the project.  This time, however, I doubted I could rely on fate to deliver another family of birds to my windowsill.

     I decided the best way to ensure birds would nest in a place suitable for filming would be to build a birdhouse, and install a camera inside.  I decided on Bluebirds as the species of bird I wanted to film, and a quick Google search told me the dimensions of the birdhouse and opening I would need to attract that specific variety of bird.

     If you are not interested in how this project was done, and would just like to see a video of the chickadee that originally settled in the birdhouse, as well as the final video of the baby bluebirds, just scroll down to the section entitled "Filming the Birds", and watch the two YouTube videos.  I would hate to see people get bored by the technical specifics of the project and stop reading before they get to the videos of the birds.  If you are interested in how I built this project, or would like to build one yourself, please continue reading.

Building the Birdhouse


     I chose cedar as the species of wood to build the birdhouse due to its resistance to insects and rot.  I purchased cedar that was rough-sawn on one side to give the birds a surface that they could easily sink their claws into.  I also chose not to build a perch outside the entrance hole.  Instead, I flipped a piece of the cedar so that the rough-sawn surface was facing outward, allowing the bluebirds to grip the surface with their claws, but making it less suitable for predators, or other species of bird that would likely kill the bluebirds and steal their house, such as sparrows.  Also, since I was concerned about potential heat generated inside the birdhouse by the Raspberry Pi, I decided to add a small sheltered area to the back of the birdhouse that could protect the Pi from the elements, but also keep me from having to place it inside the actual birdhouse.  Since there are literally thousands of birdhouse plans available on the internet, and anyone emulating this project will need to pick a species native to their geographical location, I won't go into great detail on the construction of the birdhouse here.  If anyone has questions on the specifics of how the birdhouse was built, please feel free to ask in the comments at the end of this post.


      One thing to keep in mind as you are assembling your birdhouse is that you don't want to make the top of the birdhouse airtight.  Instead, make sure to leave some air-gaps, and even drill a few holes in the side near the top as well as in the bottom to allow cool air to flow in through the bottom of the birdhouse and hot air to escape out the top so it doesn't get too hot in your birdhouse during the summer months.  Also, keeping in mind the way my first project filming birds ended (see the end of this post), I made sure to do everything in my power to protect the birdhouse from predators.  I covered the mounting post with PVC pipe to make it more difficult to climb, and I added a squirrel baffle between the PVC and the birdhouse to keep anything that was able to climb the PVC from reaching the house (this is not the exact baffle I purchased, but it is similar.)  If a squirrel or other large rodent was able to reach the birdhouse, the double wall around the opening would make it more difficult for anything to widen the opening by clawing at it.

Installing the Hardware


     With the birdhouse constructed, it was time to figure out how to film the birds.  Since it was going to be dark inside the birdhouse, I decided to use a infrared night vision camera.  I also needed to find one with an adjustable focus, since the birds would be very close to the camera.  Here is the link to the particular camera I purchased for this project.  In addition, I was going to need an infrared motion detector that could be powered by 5V DC, but would be capable of sending a 3.3V signal to the Raspberry Pi, which I found here.  Finally I decided to add an LM75A Temperature Sensor inside the birdhouse so I could ensure that all the electronics did not cause the temperature inside to get too hot.

     With hardware in hand, I needed to find a way to mount the camera, motion detector, infrared LED, and temperature sensor inside the birdhouse.  For the camera and infrared LED, I settled on using a small piece of clear acrylic that I cut and drilled to fit.  I then epoxied some 12 awg insulated solid copper wire to the bottom of the acrylic so that I could mount the wire to the back of the birdhouse, and then bend it to point the camera in the exact direction I needed it to point.  Once the acrylic was in place and focused towards the center of the birdhouse, I wedged the motion detector between the acrylic and the side of the birdhouse.  A couple of drops from the hot glue gun made sure everything stayed in place.  I allowed the temperature sensor to hang slightly below the rest of the electronics to allow it to measure the temperature closer to where the birds would be nesting.



     The Raspberry Pi model I chose for this project was the Raspberry Pi Zero W, because of it's much lower price point, and it's smaller size.  I purchased it in a kit that came with a plastic case, so that I could mount the case inside the enclosure on the back of the birdhouse, and easily remove the Pi from the case for maintenance.  I then ran the camera ribbon cable from the Pi on the back of the birdhouse to the camera inside the birdhouse.  A few more wires to get power and signal to the motion detector, power and signal to the temperature sensor, plus power wires for the infrared LED, and the Pi was ready to go.  Feel free to use any of the GPIO pins on the Pi you would like to use, just be sure that the pins referenced in the Python script match the pins used on the Pi.



     I used a 16GB USB flash drive as a hard-drive to store the video files.  Other options would have been to use the SD card that held the operating system, but that would have limited space, and could shorten the life of the SD card.  Alternatively I could have just automatically sent the video files to my file server, but that would involve another point of failure, so even if the Pi was up and running, if something knocked the server offline or the power flickered and the server powered down, then any files being sent from the Pi would be lost.  The flash drive seemed to be the simplest solution, and as long as I transferred the video files remotely and wiped the USB drive at some point before I collected 16GB of video, I should be OK.

     One last detail, in order to be able to plug in the power supply for the Raspberry Pi without having to worry about the length of the power cord, I mounted a 120V AC outlet inside an outdoor enclosure on the back of the birdhouse.  I then attached a piece of outdoor-rated flexible power cable with a three pronged plug to the outlet.  I could now power the outlet using this power cable, and just plug the Raspberry Pi power supply into the outlet on the birdhouse directly below it.

Writing the Software


     With the hardware complete, all I had to do was to write the software, which is pretty much the exact same Python script I used in my last post where I filmed the birds in the windowsill with an added bit of code for the temperature sensor.  Regardless, in case you would like to copy the script for use in your own project, I will post it below.  Don't forget to add a line to /etc/rc.local to tell the Pi to run the script on boot.  Here it is:

 #!/usr/bin/env python  
   
 import RPi.GPIO as GPIO  
 import picamera  
 import time  
 import smbus # lets us access the i2c bus  
   
 MOTION_PIN = 4  
 BUS_NUM = 1 # 1 is the I2C bus (board pins 3 and 5)  
 TEMP_SENSOR1 = 0x48  
 EMAIL_THRESHOLD = 98  
 GMAIL_USER = 'email1@gmail.com' # email account used to send email  
 GMAIL_PASS = 'emailpass' # password for email account used to send email  
 SENT_FROM = GMAIL_USER  
 SEND_TO = 'email2@gmail.com, email3@gmail.com' # email recipient for alerts  
   
   
 def take_video(channel):  
      print 'motion detected' # for troubleshooting only  
      timestamp = time.strftime("%m-%d-%y-%H-%M-%S")  
      #camera.annotate_background = picamera.Color('black')  
      #camera.annotate_text = timestamp  
      camera.start_recording('bvid%s.h264' % timestamp)  
      print 'recording started'  
      camera.wait_recording(10)  
      while GPIO.input(MOTION_PIN):  
           camera.wait_recording(5)  
      camera.stop_recording()  
      print 'recording stoped'  
   
 def WRITE_TO_FILE(temp):  
     print 'writing to file' # for troubleshooting only  
     timestamp = time.strftime("%y-%m-%d %H:%M:%S")  
   
     f=open('/mnt/usb/temperature.txt', 'a') # this opens a file for writing.  
                          # the 'a' means append, which will   
                          # add anything written to the end  
                          # of the file.  
   
           # The line below writes to the file we are appending  
     f.write('%s %d \n' % (timestamp, temp))  
     f.close() # This closes the file we just appended.  
   
   
 def CtoF( Ctemp ): # this function converts the Celcius temperature passed  
                       # to the funtion to Fahrenheit and returns it.  
     return((Ctemp*9.0/5.0)+32)  
   
             
 def GET_TEMPS( sensor_add ):  
   print 'getting temp'  
   Ctemp1 = bus.read_byte(sensor_add)  
   Ftemp1 = CtoF(Ctemp1)  
   return Ftemp1  
        
        
 def SEND_EMAIL ( temperature ): # This function sends an email  
   
     timestamp = time.strftime("%m-%d-%y %H:%M:%S")  
     subject = 'Birdhouse Temperature Too High' % (location) + timestamp  
     body = 'The temperature in the birdhouse is %d degrees.' % (temperature)  
   
     msg = MIMEText(body)  
     msg['From'] = SENT_FROM  
     msg['To'] = SEND_TO  
     msg['Subject'] = subject  
   
     try:  
       server = smtplib.SMTP_SSL('smtp.gmail.com', 465)  
       server.ehlo()  
       server.login(GMAIL_USER, GMAIL_PASS)  
        server.sendmail(SENT_FROM, SEND_TO, msg.as_string())  
        server.close()  
        print 'email sent' # for troubleshooting only  
     except:  
       print 'email atempted and failed' # for troubleshooting only  
             
 # Begining of Program  
   
   
 bus = smbus.SMBus(BUS_NUM) # sets the variable bus to refer to I2C bus 1  
   
 camera = picamera.PiCamera()  
 camera.led = False  
   
 GPIO.setmode(GPIO.BCM)  
 GPIO.setup(MOTION_PIN, GPIO.IN)  
   
 GPIO.add_event_detect(MOTION_PIN, GPIO.RISING, callback=take_video, bouncetime=1000)  
   
 while True:  
      Ftemp_1 = GET_TEMPS ( TEMP_SENSOR1 )  
      if Ftemp_1 > EMAIL_THRESHOLD:  
           SEND_EMAIL (Ftemp_1)  
      WRITE_TO_FILE(Ftemp_1)  
      time.sleep(300)  
             

Filming the Birds


     So that's the how-to, and now onto the fun part: filming the birds.  I set the birdhouse up outside my house in August of 2017 and plugged it into one of our outdoor outlets.  Honestly, after a few months I had forgotten all about it.  One day in late spring of 2018, my wife Courtney saw a bird fly out of the birdhouse and asked me to check the camera.  Much to my surprise, the Raspberry Pi was still up and running from 8 or 9 months prior, and had captured plenty of video.  All that time outside in the winter weather hadn't cause any issues with the Pi at all (that's some well made hardware!).  Upon examination of the video, it appeared we had a chickadee moving into our bluebird house.  Well, I'm not one to discriminate, I was just happy to have a bird enjoying the birdhouse, and I was even happier that the video recorder was working.


     We continued to check the camera from time to time, watching the chickadee as it gathered it's nest building materials and meticulously arranged them just so.  Then one day, all of a sudden, there was a bluebird in the birdhouse.  I reviewed the videos, and narrowed it down to the change, but there was no "event".  One video showed the chickadee working on it's nest, and the next video showed a bluebird checking out his new pad.  If there was an altercation it must have happened outside the birdhouse.  Alternatively the bluebird may have just moved in, and when the chickadee returned to find a bigger bird in his house, he just decided to move on.  Regardless, I was now filming bluebirds, which was my original intention.

     Fast-forward about a month, and the blue bird had completely revamped the nest, and laid some eggs.  I was very excited to see them hatch.  Unfortunately, I underestimated how often I would need to clean off the USB flash drive that was holding the video once the bird had laid eggs.  When the birds were building the nests, they would make an appearance here and there, and then go back out to forage for food, and find more nesting materials, which only created a limited number of videos.  Once the eggs were laid, the bluebird spent most of her time sitting on the eggs inside the birdhouse, and consequently the flash drive filled up with video in just a few days.  Once it was full, it stopped saving the recordings, so unfortunately I missed the moment of hatching while we were out of town for a weekend.  Once I returned home and realized what had happened I quickly downloaded the existing video and erased the drive, so I was at least able to film the majority of the young birds' infancy.

      Below is a montage of the baby bluebirds I put together .  The total span of the videos is only a couple weeks, so you can see that they grew quickly.  I lost my infrared LED a few days after the babies hatched, so the lighting is a little off in the second half of the video, but of course I couldn't get into the birdhouse to change the LED until after the birds had vacated the nest.  It still turned out great in my opinion.  My wife Courtney thinks these little guys are cute, but personally I think they're ugly little spuds before their feathers fully grow in.