Fish feeding as a service

This is my fish, Juicebox.

IMG_20161114_233056.jpg

I try my best to remember to feed him but sometimes it gets a little busy around here. I’d been itching for a new project to end off the new year, so I thought I’d join up what I’ve been working on with IBM Watson and Slack chatbots together with the Particle Photon that I’ve been wanting to breathe some life into since I’ve only ever used it in a very simple temperature project.

This build aimed to feed both my fish and my wife’s fish, Matthew. For the feeder I built a simple mechanism to hold enough food to last each fish at least a month, with feedings every day. The food hoppers are little tea tins that I was glad to upcycle for this purpose. I used some Gorilla glue to fix a tin to a small 5g servo horn, which then attached to the servo. To let the food out of the hopper, a small 2mm hole was drilled into the side.

img_20161210_223437

IMG_20161210_223408.jpg
Food hoppers were old tea tins

To liberate food from the container to feed the fish, the servo has to rotate 180 degrees to turn the hole downwards, then back 180 degrees to secure the food until the next feeding. I wanted this to be something that I could do from almost any service event like a chatbot, or another IoT device, so it made sense to make the feeding action available via a web request. Luckily, Particle makes this easy to do by letting you call functions on the Particle device from the web.

img_20161210_223505
The Particle Photon wired up to control two servos.
IMG_20161210_223356.jpg
The two food hoppers and servos all setup.
img_20161210_230943
The fish feeder setup over the two fish.

I used this code on the Photon to control the servos and to make the function that controls the servos available via a secured web request:

Particle Photon code:

Servo myservo1;  // servo to feed fish #1
Servo myservo2;  // servo to feed fish #2

int pos = 0;  // variable to store the servo position

void setup()
{
  myservo1.attach(D0);
  myservo2.attach(D1);

  // This is how you expose the feedFish function below to the web
  Particle.function("feed", feedFish);
}

// Rotate the servo one way, then back to distribute food
void moveServo(Servo servo)
{
  // Rotate the servo to expose the food hole.
  // This loop moves the servo from 1 degrees
// to 180 degrees in steps of 1 degree
  for(pos = 1; pos < 180; pos += 1)     {                                      servo.write(pos);  // tell servo to go to position in variable 'pos'     delay(5);          // waits 5ms for the servo to finish moving   }   // rotate the servo back to secure the food hole   for(pos = 180; pos>1; pos-=1)
  {
    servo.write(pos);
    delay(5);
  }
}

// This is the function that is made available to the internet
// via a secured call
int feedFish(String command)
{
  moveServo(myservo1);
  delay(1000);  // wait a full second before moving the second servo
  moveServo(myservo2);
  return 1; // particle functions must return 1 when successful
}

IBM Watson has a pretty easy to use NLP service that I’ve been spending a decent amount of time working with. I trained up a “#feed_fish” intent and hooked it up to Slack. You can do this with IBM’s Watson Conversation tutorial here.

IMG_20161210_223531.jpg
Natural language!

I wrote a simple chat bot using Node.js. The incredible folks over at Howdy have done some great work creating the botkit toolkit, which made it super fast to put together a Slack bot that could handle the intents found by Watson in a conversation. You can find the repo for my bot, plus instructions, here.

fish-feeding-bot-diagram
How the parts fit together

How it works: The user can chat with the bot about a few intents that I have trained it to understand. Simple conversational things like “How are you” and “What are you up to?” are understood by the bot, and it will respond in kind with “I’m doing great!” or “Nothing much”. This is possible because every message the user sends to the Slack bot gets sent to the IBM Watson Conversation API, and the bot gets back an intent and the confidence of the intent. Any intents that don’t have a high confidence score send a fallback response to the user, like “Sorry, I didn’t understand what you said.” However, if a user says something which causes a high confidence score for “#feed_fish” then the Slack bot makes a web request to the Particle Photon function that triggers the servo rotations. Utterances like “Hey, the fish look hungry” or “Can you please give the fish some food” work, and as I think of more, I train the both with them.

It works great for the two fish jars we have at home. The only problem is that I STILL have to remember to tell the bot to feed the fish. The bot will have to become smarter I guess. I’ll update this post when I add more features. Any questions? Post them below!

IMG_20161210_231001.jpg
Happy fishes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s