Tuesday, 15 September 2015

The Possum Feeder

[Warning in advance: This is going to be a very lengthy and technically detailed post with no possum pictures in it.]

Over the past few years, I have pondered the best way to address the problem of feeding possums when there is no one at home. It isn't that the possums are dependent on feeding and are going to die if the food source is cut off, but more that they're part of the family and I want them to feel cared for when there's no one at home.

The Possum Feeder, ready for use

The eventual solution was to build the automatic possum feeder shown here.

The design is conceptually quite simple. The box contains an array of twenty cylindrical chambers, each 90 mm in diameter by 150 mm high and with a door at the bottom. Each door is held closed by a catch and falls open by gravity when the catch is released electrically, thus dropping the contents of the chamber onto the tray underneath.

Each chamber door can be set in software to open at any desired time and date. This means you can drop food multiple times per night and at irregular times during the night.

It may be easier to see how it works by viewing the following video.

This design has the following advantages:
  • All the chambers are completely separate from one another. If the food in one chamber goes off or gets invaded by insects etc., the contamination won't easily spread.
  • If a chamber door jams closed for whatever reason, it won't gum up the whole mechanism; the remaining chambers will still operate normally.
  • The chambers can be filled with anything that will fit in the space. Multiple small items or irregularly sized items will work just as well as a single big item. Each chamber is large enough that you could stack two average-sized apples in it if required.
  • Although the construction can't be totally agricultural, precision work is limited to ensuring that each of the catches opens and closes reliably and the doors swing relatively freely. There are no intricate, complicated mechanisms involved.
  • The chambers are easy to fill; just put food in from the top.
  • The PVC pipes used for the chambers are intended for rain water collection, so are food-safe and easily cleaned. The plastic door at the bottom can also easily be wiped clean.

Each chamber can easily hold an apple or pear...

...or a combination of different foods.

If anyone is interested in building something like this, I've put together some drawings. These don't completely describe the entire device, but they at least give a general idea of how it was built.

The construction process started with fitting the chambers to the base. The chambers were cut from 90 mm storm water pipe and the base from 15 mm exterior-grade plywood (the same stuff used for possum boxes).

The base of the feeder under construction

It turns out that my 90 mm hole saw cuts out a hole that is significantly smaller than 90 mm. I had to sand the edges of the plywood holes and then force the pipes into place. This took some time, but had the advantage that the pipes were held in place very securely without needing any adhesive.

A feeder door with solenoid locking mechanism

Doors for the chambers were made from 6 mm thick acrylic (aka perspex). You'd think that plastic would be cheap, but acrylic in small quantities is surprisingly expensive and it can be difficult to find anything thicker than 1/8" (approx 3 mm). Fortunately, I was able to get some offcuts from Reverse Garbage for a good price.

I used this thickness of acrylic because it was thick enough to hold screws and would allow hinges to be cut out of the plastic itself. Also, the door may potentially be subject to attack by hungry possums, so the stronger the better.

I cut hinges directly out of the plastic with a coping saw. This was a pain to do, but had two advantages. Firstly, it required only two screws and two pins per door. The alternative of using separate hinges would require two hinges and eight screws per door - when multiplied by twenty doors, this would add up to a lot of hardware.

Secondly, the (relatively crude) design of the locking mechanism requires some play in the hinges in order to allow the door to close easily. Cutting out the hinges inherently provides some play due to the kerf width of the saw, so what would otherwise be a disadvantage is actually helpful.

Fitting the locking mechanisms

The locking mechanism consists of a solenoid which acts like a simple bolt. At first sight, using a separate solenoid for each individual door seems to be expensive and excessive, but I was able to get a whole lot of solenoids cheaply on e-bay (less than $4 each, including postage) and any other mechanism I could come up with (e.g. a motor driving cams etc.), required enough precision parts that it would have been overall both more expensive and more difficult to make. Also, the solenoids are completely redundant; if one fails, only that door is affected.

I contrived the rest of the locking mechanism out of pieces of aluminium extrusion. It took quite a bit of planning to make use of the aluminium extrusions I had available, while at the same time minimising the amount of cutting and filing required. Since everything needs to be done twenty times, every saw cut or hole needs to be considered.

One thing I thought of afterwards was that this would be a good application for a 3D printer; you could simply print up the locking mechanisms, and possibly even the entire doors, with very little effort and you wouldn't have to compromise the design to fit the parts available. You might have to fit metal sleeves or pins in some places for strength, but still it would be much easier than all of the cutting and filing and drilling that I had to do.

The magnets for door position sensing

As the feeder was intended to be monitored remotely; it was considered helpful to be able to tell if the doors had opened correctly. This was done by embedding a small magnet in each door and using a reed switch to sense the magnetic field. Both the magnets and reed switches were purchased on eBay for a few cents each.

Reed switches

I learnt a couple of things about reed switches in the process.

Firstly, they are very fragile. Don't even think of bending the leads (or even trying to straighten them when bent) by grabbing the lead and bending. This will break the glass, or - worse - crack it, leading to unreliable operation of the switch. If you want to bend the lead, you need to hold it near to glass end with needle-nose pliers and then bend the free end - and don't even let the tips of the pliers rest against the glass when bending.

Secondly, they are sensitive to magnetic field in an axial, but not a radial direction.  That is to say, if you approach the side of the switch with the end of a bar magnet, it won't operate until you're very close; and may not even operate at all. The magnet needs to be parallel to the reed switch to operate reliably. I didn't actually know this until I started building the feeder, and I had to alter the design to embed the reed switch vertically in the floor of the box. This means the switch body was a fair distance from the magnet, however the magnets were very powerful despite their small size, and this arrangement worked reliably.

The controller, before wiring

The brain of the device is an Allen Bradley MicroLogix PLC (Programmable Logic Controller). PLCs are used throughout industry and are specifically designed to make control tasks like this easy to implement. Using a PLC simplifies the design (both in terms of hardware and software) considerably. The down-side is that PLCs are expensive.

Normally for a project like this, it would be logical to use a small microcontroller board like an Arduino, with a suitable relay module. This would be 10 or more times cheaper, which would compensate for the extra design effort required to make it work. However, I already had a spare PLC lying around. It was a very old one I had been give for free and it had a bug in it (literally; an insect had crawled inside and died), but worked once this had been removed.

Also, I've used socketed relays, which, like PLCs, are an industry thing where you pay (relatively heavily) for extra convenience, and again these were used because I already had them on hand.

The feeder, fully wired

All of the electronics were mounted on an aluminium plate facing away from the feeder chambers. In operation it generates a certain amount of heat (total power consumption is 11 W), and it seemed best to keep this away from the food.

By the way, this power consumption is another reason not to use a PLC. It's not that it's a gigantic amount, but it's large enough that you can't run the feeder off batteries, so it remains tethered to a power outlet. If, instead of a PLC, you used a micro-controller board and a moderate amount of care in the design, it should be able to drop the power consumption to considerably less than 1 W, which would allow you to run it off batteries.

The electrical design uses a bit of trickery (a matrix switch as well as a binary decoder) to switch all 20 solenoids using a total of only six relays. I did it this way because the PLC had a limited number of outputs, and I also only had a limited number relays spare and didn't want to buy any more. If I'd had to build everything from scratch, I would have used a 4 x 5 matrix switch consisting of 9 cheap PCB relays.

Once the electronics was installed and tested, the box was painted and a lid and other external hardware added. I put an aluminium strip around the outside of the lid which overlaps the gap beneath and prevents any water from getting inside even if the box is exposed to direct rain.

The feeder, now fully assembled

A piece of Styrofoam fits inside the lid to seal off the tops of the chambers.

In use, the feeder sits on a frame welded out of 1" angle iron. I'm only a beginner when it comes to welding and my welds were a bit unsightly, but at least the frame was more or less square and strong enough for the purpose.

I also mounted a camera underneath to record which possums were visiting. Unfortunately, I had to set the motion detection to a fairly insensitive level in order to prevent too much spurious triggering due to shadows in the daytime, and it turned out it only detected when possums walked directly under the feeder. It wasn't sensitive enough to pick up possums sneaking food off the tray, so I still don't know which possums got what food.

A camera fitted under the box

It's necessary to have some means to set the times at which the doors open. In principle, it would have been possible to do this by use of the PLC programming software, however this would have been very inconvenient and would not have allowed for remote monitoring. I therefore had to write software to communicate with the feeder.

Possum feeder monitoring page

As you can see, the software has the following functions:
  • Can synchronise the internal clock in the PLC. The PLC doesn't have a true Real Time Clock in it and I had to emulate one in software. This meant that it stops whenever the PLC is turned off and therefore needs to be reset to the correct time on restarting the system.
  • Can set a time and date for opening each of the doors.
  • Can manually trigger opening of any door for testing purposes.
  • Indicates the status (open or closed) of each door.
Writing the software (a C program that runs on the Possum TV Server) was an interesting (to me) exercise that involved two particular challenges.

Firstly, it needed to use DF1 protocol over an RS-232 link to talk to the PLC. I'd never programmed a serial protocol in Linux before.

Secondly, it needed to work via a web interface in order to allow it to be used remotely, and that meant implementing some sort of password security system to prevent others from inadvertently (or maliciously) accessing the system and making changes. Also, it had to be set up such that it wasn't possible for a person to determine whether the feeder was in use (and therefore the house unattended), unless they had the password.

The security system I devised uses SSL, but also has an extra layer of security over and above SSL, such that the password is never sent directly over the SSL link, but instead is used (along with a random per-session "salt") to generate an HMAC to validate each message. There are also mechanisms in place to hinder password guessing and defeat timing analysis. This is probably a bit over the top, since a hacker is unlikely to devote this level of attention to taking over control of a possum feeder, but it didn't hurt and was an interesting programming exercise.

Finally, anyone who wants to know more about either this software (e.g. if you got to this page doing a web search on implementing DF1 under Linux or whatever) or the possum feeder itself, please let me know either by email or posting a comment on this blog, because I'm quite willing to share what I know.

1 comment: