IoT Cat Feeder Using Particle Photon Integrated With Alexa, SmartThings, IFTTT, Google Sheets

8,360

128

14

The need for an automatic cat feeder is self explanatory. Cats (our cat's name is Bella) can be obnoxious when hungry and if your cat is like mine will eat the bowl dry every time. I needed a way to dispense a controlled amount of food automatically by 3 methods - 1. Alexa voice command, 2. by a schedule, and 3. by a button in SmartThings. I also wanted a way to track how and when the cat gets fed so we don't feed twice (sometimes when when my wife feeds the cat and then I feed the cat again 15 minutes later).

This project is not overly difficult, I am no developer, nor an engineer, but there was many resources online that helped me. I'm compiling everything I used and all the steps necessary for you to complete this project too. Enjoy, and happy building!

Step 1: Get All Your Needed Materials - Roughly $100

Here's everything I purchased to make this cat feeder. It was about $100 which is a little more than my planned $75 but went for some better quality parts to ensure it will last. Some of materials I already had to make the box like wood glue, hot glue gun, 18ga nailer, sand paper, wood filler, etc. These fall under "tools" in my opinion and are not all necessary. I just go above and beyond sometimes on making things pretty.

If you deviate from these exact products, just make sure your servo has a metal gear and note the number of teeth because your servo arm/horn will need to have the same number of teeth. The servo and arm listed below are 25T, meaning 25 teeth. Also, I used a plastic arm on the first go-around and the teeth stripped within a week of use so don't go the plastic route, get metal.

1. Particle Photon $19.99 http://a.co/flaQM0Z

2. Breadboard and Jumper wires $7.69 http://a.co/iJuFpXp

3. Servo $19.99 https://www.frys.com/product/7027291

4. Metal servo arm/horn $8.98 http://a.co/e9eWOvx

5. Piezo Buzzer $5.05 http://a.co/9iOP2hq

6. Cereal Dispenser $14.95 http://a.co/6c2xpVq

7. Fiber board from hardware store for the box, 2 pieces just in case you mess up $20 https://www.homedepot.com/p/1-2-in-x-2-ft-x-4ft-Me...

8. Rustoleum Hammered Spray Paint $5.97 http://a.co/alqqR8n

8. Misc. items like screws, wood glue, nails, sand paper, wood filler, etc.

Step 2: Set Up Particle Photon

The first step is connecting your Particle Photon to the internet. This is very easy, especially with the guides provided by Particle. Download the Particle app onto your phone, create a particle account, and folllow the guide to getting it connected to your wifi. Watch the Video and follow these instructions!

https://docs.particle.io/guide/getting-started/start/photon/

Step 3: Connect Particle to Servo, Breadboard, and Buzzer

Ok, now we need to wire up the particle to the servo and buzzer using a breadboard. Attach your particle to the breadboard leaving 2 pin holes on each side, it doesn't really matter where the particle is placed outside that. I soldered my wires to the buzzer and then used hot glue to secure it. A simpler method would be to use terminal connectors or butt connectors and crimp them with pliers. Up to you.

Connect the servo wires:

VIN Red servo wire

A5 Yellow servo wire

GND Black servo wire

Connect the buzzer wires (doesn't matter which is which):

D0 Buzzer wire

GND Buzzer wire

Step 4: Flashing Code to the Photon

Now that you have it wired up, lets flash the firmware code to the photon and test that the buzzer plays a melody and the servo turns.

Login to the particle build console using your account https://build.particle.io

Click the code <> button on the left side toolbar. Copy and paste the firmware code provided (cat_feeder.c) into the build console, replace any existing code there by default.

A little explanation on the feed function. Since feeding can be invoked by 3 different methods (button, voice, schedule) we need 3 different commands in order to publish each event so we know how the cat was fed. These commands are "bfeed" when fed by the button, "sfeed" when fed by schedule and "vfeed" when fed by voice command.

Click the Folder looking button to save your code, give it a name of your choosing.

Click the verify button (it looks like a check mark with a circle around it). After a few moments you should see in the bottom status bar:

Compiling code... Code verified. Great work! Ready.

Now, Click the Flash button on the left toolbar (looks like a lightning bolt). After a few moments you should see in the bottom status bar:

Flashing code... Flash successful! Your device is being updated. Ready.

Next, login to the particle console https://console.particle.io/

Click on your Particle Photon. This is a status page for your device, you can see in the Event Logs when actions are taken, such as flashing code or when events are published from invoking the feed commands. To initiate a feed command you will use the Function tile on the right side of this console. Since the function is called "feed" in the code, you should see it and an argument input box.

Type "bfeed" in the argument input box and click Call.

This should play the melody and then turn the servo. If you want, for testing purposes, change the delay time in the code from 330 MS to something longer like 5000 if you want to verify the servo turning. You need to click the Flash button every time you make any changes to the code. You will probably need to adjust the delay later on to get the desired amount of turn (such as feeding a dog, you might want to dispense more food).

Step 5: Make a Box to House Everything

This step consists of your good ol fashion carpentry skills. I purchased 2 -2x4ft fiber boards to make the box because its strong, smooth to the touch, relatively cheap, and easy to cut/work with. You can choose any material. This step is really at your discretion in how it's built because everyone has different needs. I won't have a detailed step by step for making the box but I can share the thought process and methods I used.

There was a number of factors I took into consideration for designing the box. I wanted this thing as compact as possible. I wanted it easily serviceable for cleaning and/or fixing it if it ever malfunctioned. Lastly, I wanted the dispenser tube exposed so I can visibly see when the food is running low. With this in mind I made the box first and then measured the inside dimensions to make a square frame which the the dispenser unit, servo, and board are attached. This way the entire unit can be lifted right out of the box for servicing. See the pictures.

Step 6: SmartThings Device Handlers

This step explains how to implement calling the feed function using SmartThings and Alexa. To do this I had to write 2 groovy device handlers. One of the handlers is for "bfeed" when I press the button in SmartThings and the other handler is for "vfeed" when I ask Alexa to feed Bella by voice command. Another reason to have 2 different handlers is that Alexa only recognizes devices that are switches, not buttons. So I had to trick Alexa into recognizing a switch in order to invoke the function (off and on perform the same action). Ok, let's get started.

Login (or create an account) to the IDE SmartThings portal at http://ide.smartthings.com using either your Samsung Account or SmartThings account.

Confirm your SmartThings hub shows up under "My Locations" and "My Hubs". If it doesn't show, troubleshoot this before continuing.

We will create the Button Handler first.

Click on "My Device Handlers" on the top navigation bar.

Click on blue button "Create New Device Handler"

Select "From Code" tab and paste the code in from the file attached button_handler.groovy. Then Click Create.

Click "Save" and "Publish" --> "For me". You should see a green notification appear that says, "Device type published successfully."

Now, jump over to your phone and open the SmartThings app. You should see the handler appear as a new device. You'll need to configure the handler so it posts to your particle device. Select the newly created device and open the Settings (looks like a gear icon).

Enter Device Name - Name the device whatever you choose, I'm sure your cat is also not named Bella.

Enter Access Token - The access token is going to be found in the Particle Build console https://build.particle.io/ under the Settings (gear icon on bottom left). The Access Token will be a 40 character string.

Enter Device ID - The device ID is found on the Particle Console page as a 24 character string and is also seen in all the particle URL's when you are logged into your account working on your particle device. Device ID seen BOLD in the URL: https://console.particle.io/devices/83900082840c382000132441

Click Save.

Click the Feed button!

By clicking the feed button you should hear the melody and get the servo to turn. You should also be seeing events published in the particle console event log.

Next, we will create the Device Handler for Alexa.

Follow the same procedure as above. Go to the IDE SmartThings portal and Click on "My Device Handlers" on the top navigation bar.
Click on blue button "Create New Device Handler"

Select "From Code" tab and paste the code in from the file attached alexa_handler.groovy. Then Click Create.

Click "Save" and "Publish" --> "For me". You should see a green notification appear that says, "Device type published successfully."

Now, jump back over to your phone and open the SmartThings app. You should see the handler appear as a new device but this time without any button. You'll need to configure the handler with your Access Token and Device ID just like you did previously.

Select the newly created device in SmartThings and open the Settings (looks like a gear icon).

Enter Device Name - Name the device whatever you choose, I called it "Cat Feeder Handler for Alexa" so my wife knows its not the Cat Feeder button.

Enter Access Token and Enter Device ID, then click Save.

Now, open your Alexa App on your phone. If you haven't already done so before, enable the SmartThings Alexa Skill and link your SmartThings account to the Alexa App. Then go to the Smart Home screen and click "Add Device". This can also be done by saying "Alexa, discover devices". A device should show up with a switch icon, it will be named whatever you named the handler in SmartThings. You can change the name of it in the Alexa app if you want but remember that this is a switch type so it will require saying "Alexa, turn on" or "Alexa, turn off". I know this isn't nice to say "Turn on the cat feeder" so an alternative is to create a new routine in the Alexa app and call it with the phrase you want exactly. I made a routine called "Feed Bella" which turns on the cat feeder switch.

By clicking the switch in the Alexa app, you should now be successfully calling the feed function. The Particle Console event log should also post the events indicating so.

Once you have everything named the way you want it go ahead and give it a try!

Step 7: Putting It All Together

The last piece I haven't covered is how to schedule the feeds and record the published events in a Google Sheet. You are probably thinking the Alexa App can be used to make a routine for the schedule but this wouldn't allow us to log schedule vs voice command or button. So instead, there is an IFTTT applet for particle already that we will use.

Let's create the IFTTT applet for scheduling feeds.

Go to https://ifttt.com or download the IFTTT smartphone app and login (create an account if needed)

If you are new to IFTTT its very straight forward. Every applet consists of an IF (a condition or trigger) and a THAT (some action to do).

So once logged in to IFTTT, create a new applet, select IF and search for or select "Date and Time". You configure this to whatever schedule you prefer. Then proceed through the steps and once you get to the THAT you will search for "Particle" and select "Call a Function". Fill out the fields as in the screenshot above, make sure to use "sfeed" as the input as this is the command needed to publish a "Fed by schedule" event. You may need to connect or login to your particle account while setting up this applet. Save the applet and you should be good to go. If you want to test, just change the date and time to near in the future and see if it triggers properly.

Now to create the IFTTT applets for handling the 3 event types.

There are 3 commands we need to account for when the cat feeder runs. These are hard coded in the particle firmware:

Bella fed by schedule
Bella fed by button
Bella fed by voice command

If your pet is not named "Bella" you probably want to change this in the firmware, and re-flash. Change the text in the Particle.publish line of the particle code.

Create a new IFTTT applet. (need to do this 3 times, for each event type)

Starting with the IF, search for Particle and select "New event published". The Event Name will need to be the exact Published Event Name that you have in your firmware. For example "Bella fed by schedule" is the exact event name in the code I provided you. Check out the screenshot as I filled it in for reference. You will need to create 2 more IFTTT to handle the other events too. This applet will create a new sheet in your google drive if it doesn't exist already and log new events to the next empty row.

Share

    Recommendations

    • Big and Small Contest

      Big and Small Contest
    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • PCB Contest

      PCB Contest

    14 Discussions

    0
    None
    AlexTheLion2015

    Question 2 months ago

    Your code killed 3 particles I have tried to get working with the servo. I don't know how your servo survived, but I was running off of a 5.0v 2.5amp samsung fast charger, and the servo which you have up on your parts list. The servo is rated for 6.0-7.2 volts, you can't put anything less than that into the servo or else it will drain the power from the board itself, and cause the board boot memory to corrupt itself. I recommend removing this project, and figuring out a different powersource for the servo. Now I got to buy a JTAG programmer to try and fix the boards that were corrupted thanks to misinformation.

    1 more answer
    0
    None
    ChrisK393AlexTheLion2015

    Reply 2 months ago

    Hi Alex, I'm sorry to hear you've been having trouble. I didn't experience any of the issues you are describing and I'm running the exact code with components without issue (3 months going strong without issue). Maybe your bread board is bad and bridging the +/- connections. I can't think of any other reason the particle would get shorted out. If you figure it let me know, i'm curious.

    0
    None
    AlexTheLion2015

    2 months ago

    Just ordered all my parts for it, once the parts come I'm going to share it! Im planning on making the photon permanent in my design, or at least enclose the breadboard with the photon within an enclosure to prevent dust, and food particles from getting all over the board, as well as a small fan probably. My cat is deaf, so instead of the buzzer, I am thinking 1 bright LED should work for him. Thank you for inspiring me!!! I'll share with you what my design when it is finished.

    0
    None
    jimgust123

    Question 3 months ago

    this has been great fun to build so far

    When I go to verify I get this error for line 72

    cpp:72:18: 'class TimeClass' has no member named 'isDST'

    2 more answers
    0
    None
    ChrisK393jimgust123

    Reply 3 months ago

    Can you share your code? Did you change anything? The isDST() function should return 1 for true or 0 for false depending on whether the DST in in effect. If its in effect you adjust for the correct time, -5 for cdt, otherwise -6 for cst. Are you verifying your code in the particle build console or using cpp in terminal? Try using the particle build console if not already doing so. Hope this helps. - Chris

    0
    None
    ChrisK393jimgust123

    Reply 3 months ago

    can you post your code? did you change anything? The isDST() function should just return true or false. You might have a missing semi column somewhere.

    isDST()

    Since 0.6.0

    Returns true if Daylight Saving Time (DST) is in effect.

    // Print true or false depending on whether the DST in in effect
    Serial.print(Time.isDST());

    Returns: Unsigned 8-bit integer: 0 = false, 1 = true

    0
    None
    NathanKing

    3 months ago on Introduction

    Great job Chris!
    I've been tossing up whether to make one of these for my cat. I bought some cereal feeders and found that it became very hard to turn - due to the biscuits getting caught between the arms and the sides of the container. One of the biggest challenges of automating feeding, is the reliability of the unit. Especially as it's for our loved ones and don't want them to go hungry. Have you experienced any issues with clogging? or perhaps your motor wearing out?

    2 replies
    0
    None
    ChrisK393NathanKing

    Reply 3 months ago

    Nathan, thanks for your support! Two months so far with 2-3 feeds running per day and I haven’t experienced any clogging or issues with the servo. The one I list in the instructions is from frys and it’s actually got a surprising amount of torque. I did strip a plastic servo horn and had to replace with a metal one. It’s been great ever since. Another thought is the cat food we use is relatively small in pieces, check out the YouTube video if you haven’t already. Maybe that’s why no clogging issues.

    0
    None
    NathanKingChrisK393

    Reply 3 months ago

    Thanks for replying.

    Good idea about the metal servo horn. I'll look into getting some someplace.

    Cheers ;)

    0
    None
    AlexTheLion2015

    Question 3 months ago

    Do you know of any way for this to work with google's home automation? I love the idea you have going here, i just need something to feed my cat when he gets angry at me.

    1 more answer
    0
    None
    LinoL9

    3 months ago

    Wow beautiful ! ;)

    0
    None
    Penolopy Bulnick

    3 months ago

    Nice job! Gotta keep those kitties fed :)