Friday, August 7, 2015

Fault tolerant vacation automatic pet feeder

Finally, I made it. I went on vacation for a full week and my bunny survived. Though I have a pan and tilt cam watching if anything went wrong.

Those on the market are too expensive. And even if I get one I don't trust them. First, they have a single motor. Auger / screw types can jam. If the motor fails, all meals will fail.

I actually built a multiple meal automatic feeder for my dog. It was complete with a hacked digital timer, and low level logic chips like NAND gates. I did that because I always have about a week to design and build it. And it have to work. The problem is, the motors are too expensive, or I couldn't reliably mount them to "open doors". So I only tested it for a weekend or two before he rested in peace.

At the time I hardly know what is a servo. And after I came across it, I just didn't have time to learn the hardware and software of a controller to drive them. And how much 7 servos cost? I used the cheapest motors and they work fine. The problem is that it's hard to glue some latches to the bare motor axle without gears.

This time around it's different. Tiny servos like sg90 cost next to nothing. Arduino kits are cheap and you can do a lot of other things with it. You order it from Amazon and they came quick enough before I setoff for vacation. I hope it's plug-and-play as they claimed. But I saved some money by ordering from other sources. So it's not plug-and-play but I figured it out how to program it.

I'm sort of a hardware and software professional so the rest is easy. The software is supposed to be simple, just wake up everyday at the same time and turn on different motors. That's why I actually built one with discrete logic that could be more reliable, and worked first time. But I don't trust a cheap controller working outdoors. One power outage or interruption the controller can be trapped into non-operational states.

I was prepared to write and test complicated software so if power is stopped for an hour, the operation behaves as if time has been lost for an hour or two, not whole days and not skipping meals.

After more thinking than coding, I realized it's best to drive the Arduino with a digital or mechanical timer. When the Arduino has stable power, it only need to use one location to remember which motor to turn on. The software is real simple. I was preparing to work overnight to make something work reliably. With this simplicity, I just needed trivial modifications to the sample code. There's only a few "critical" lines so I can tested them thoroughly in no time and went to sleep before leaving early the next morning. So to fail the timer has to fail and the board hardware has to fail. They seldom do.

My designs has been for the servos to open something like a trap door under food, and so all the food fall down to a tray. And I have no time to make the custom containers.

What I did was building a see-saw with fat lolipop sticks, with a cup of food on one end and a servo arm on the other end. When the servo turns the cup will drop. Everything is made of fat lolipop sticks that you can find in craft shops, and school glue. They are a surprisingly fast and secure combinations. To guard against earthquick, bigger animals and an angry bunny shaking the pet house, there are little slip guards also made of strips from wooden sticks and the cups are stabilized by cup cake paper liners. The craft isn't too bad but I have to build ad-hoc guards and defences to defend against bigger wild animals and the weather.

Wooden sticks was a surprisingly good choice because you can stack them up with glue to your desired height, or stick them to square dowels, also from craft stores and also hardware stores.

All the wires from the servo, 21 of them, are not soldered, but using the wires from the kit that plug directly into the Arduino board, and also use the tiny development board for the 5V and GND distribution. It doesn't matter if the wires fail to contact. Only one servo will be affected by one circuit failure.

And to ensure a good drop, the first thing was to custom built a big tray and inclined walls for the pet house. I had sewing threads glued to the cups and sticks to ensure they fall as expected but not into the tray to confuse the bunny.

The see-saw isn't the best design but I picked it because I had no time for other things. A long see-saw can balance out a heavy cup if the servo is weak.

As seen in the picture, one of the cup didn't drop. But there's only treats in the cups. There are plenty of other pellet food and hay that the bunny doesn't eat that much unless he has to. The problem was that the little vertical slip guard wasn't vertical enough. So the see-saw stick was trapped. This was a known problem in one or two of the unique handmade mechanisms. I forced the little glued sticks sections apart until it was smoother for the see-saw stick to drop. But one of them revert to the bad position eventually.

I almost built a automatic flush toilet too using the Arduino with servos. But it's too risky first time so the flush was driven by the lawn sprinkler controller for now.