How can I control a servo with Mysensors? Automatic cat feeder

  • Hey guys. Our cat is our alarm clock and I'm trying to solve that. Every morning she demands to be fed around 6am weekends included. My goal is to fix that problem with an automatic cat feeder.

    I'm trying to figure out a way to control a little microservo that I want to use to trigger a springloaded hinged door. The servo gets power and moves 90 degrees. When this happens the door springs open and the cat can get the food.

    I've written the bit that moves the servo to open and also back to closed position. I need to trigger these actions using MySensors. I'm guessing the best way is to use the relay sketch, but I'm at a loss as to how to modify it. I'm not a programmer so the coding for this sketch is a little foreign to me.

    Can someone explain how the relay sketch can be modified? I would like it to run the 'open door with servo' portion when the relay would be energized, and the 'close door with servo' portion when the relay would be idle.

    Any help is greatly appreciated. In fact, our whole household thanks you for helping us sleep in!!

  • Mod

    It should just be a matter of changing

    digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);

    in the relay sketch to

    if (message.getBool()){
    } else {

    assuming the code you have written are inside the open/close_door_with_servo functions.

  • Admin

    Haha, a youtube clip is mandatory when you finish this project.

  • Hardware Contributor

    This reminds me of my very first arduino project 8 years ago. A vandal(cat)- and smell-proof steel box able to serve 8 individual meals for two cats simultaneously at separate places. I had two cats, one small, sick and in need special food. The other one fat, mean and always stealing the other ones food. She could also break in to everything once she felt the smell of food.

    The cats are not around any more, but the machine is still kept and working I suppose. I should probably MySensorize it...

    Edit, On topic: I've never used servos, so can't help there. Sorry.

  • Contest Winner

    @chuckconnors funny project!

    Arduino has a servo library take a look here

    Your sketch can be the relay sketch like mfalkvidd says (use pin 6 i.s.o. 9 because 9 is used by the radio)

    Servo myservo;  // create servo object to control a servo
    void setup()  {
       myservo.attach(6);  // attaches the servo on pin 6 to the servo object

    And in the message handler

    if (message.getBool()){
        // Open door 90 degrees
    } else {
        // Close door 0 degrees

  • Hardware Contributor

    I saw this on youtube some years ago:
    Its based on rfid cat necklases... nice links in the videos as well.

  • @mfalkvidd thanks for the help. That's definitely what I needed to know!

    I've gotten the 1.0 version working but my range from the gateway is an issue I'm trying to resolve. For now it's basically a spring loaded (rubber band actually) cardboard box but it does work. I'm planning on building a version out of wood once I get some some time.

  • Here's the cardboard prototype proof-of-concept video:

    Youtube video

  • Hardware Contributor

    If you are going to make the solid version that fast - have a sensor to make sure the cat doesnt stand on the lid. I pictured myself a cat going through the room when the lid was opened that fast 😀

    Nice work!

  • Good point. I've got a feeling that the rubber bands won't last. I also had to add a weight to keep the box from tipping over.

    I may just go with something similar to what @sundberg84 posted. This should buy me a few weekends of rest before it starts failing but now I know I can come up with something to solve the problem.

  • Hardware Contributor

    Cats are smart. It will hear when the servo starts miles away and stand right next to the bowl before its open, know exactly what to expect and where to stand (and not). The only chance to scare it or make it fly is the very first time.

  • I'm thinking of building the final device using a spring loaded hinge that is normally used to keep doors closed. I see that some can be adjusted to slow the opening speed. This would be helpful in keeping the box from opening too fast.

    I think a solenoid would be a better fit for this project than the servo but I know nothing about them. The idea would be that the solenoid would hold the lid closed but retract when power is supplied and the pin would allow the box to open using the power of the hinges. Can anyone make a suggestion for a low cost DC server? All the ones I'm seeing have very little movement (1mm - 5mm). I'd think I'd want something closer to 0.5" .

  • Wow, the comments are so old. Hope I didn't bother you guys. Now, I think it would be much better for us to get ourselves an automatic feeder. It would be much more convenient for us to feed our cats this way. Not to mention, you can control the diet and amount of food intake. If your cats have diabetes or similar conditions, getting an automatic feeder will help to improve their health a lot. You check all the important -Removed by moderator- before buying it too. Cheers.

Log in to reply

Suggested Topics

  • 4
  • 1
  • 9
  • 9
  • 933
  • 2