Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Build Your Own Automatic Pet Food Dispenser

DZone's Guide to

Build Your Own Automatic Pet Food Dispenser

Want to go away for the holidays (or just a well-earned vacation) but unsure who will feed your pets? Do it yourself with this handy automatic dispenser!

· IoT Zone
Free Resource

Have you given up on having a pet for the fear of not being able to feed it while you're away?

Well, the Ubidots team was inspired by one of our users, or rather, the cat of one of our users, that didn't have anyone to feed her when her owner was away from home.

Cell_Canela

We decided to build an automatic pet food dispenser controlled remotely through Ubidots Cloud. This is an easy project that anyone can get done with some very affordable materials. 

Materials 

  • An automatic food dispenser. You can get it in almost any pet shop.

dispAli

  • A mini CD.

cd

  • A servomotor. We recommend 5-6 volts.

servo

  • Something to help stick the dispenser to a base. In this case, we are using tiny pieces of wood, but you can use anything else.

balso

  • ESP nodeMCU.

Resultado de imagen para NODE MCU

  • Cables.
    arduin_wires

  • Bolts for fixing the servo motor: 
TORNILLO_CABEZA_CRUZ
  • A microUSB cable. A 5-volt supply also works.
Resultado de imagen para microusb cable
  • Super glue.

superpega


Let's Do It

First, we trim down the wood so it can hold the servo motor in the dispenser. 

BalsoSop

After getting the base ready, we will use the bolts to fasten it to the dispenser. Then you can use the super glue to install the servo motor. 

DispFrenteWe recommend using one of the special axes included with the servo:

gogo_servo_7

Now, we tie the CD to the servo motor base. Don't forget to cut off a cd section so the food can come out. Once mechanic stuff is finished, our dispenser should look like this:

mec

Electronic Connections

The connection is pretty simple. First, connect the servomotor's red wire to the NodeMcy 3v3 pin. Then, hook up the black wire to any pin with the name "GND." The last cable, which most of the time is white or yellow, will be connected to the fifth pin (D1). You can see the process in the image below:

nodeMCU.jpg

Program the ESP NodeMCU

Once our connections are finished, we can open the Arduino IDE. We recommend you first to get familiar with the Ubidots MQTT ESP library

/**This code is to control the servo of the 
Pet Automaic Dispenser

 nodeMCU pins:
 3v3  --> Red wire of the servo
 GND --> Black wire of the servo
 5(D1)--> Yellow o white wire of the servo

 Created 28 Octubre 2016
 by María Hernandez

Public code**/
/****************************************
 * Include Libraries
 ****************************************/
#include "UbidotsESPMQTT.h"
#include <Servo.h>
Servo myservo;
/****************************************
 * Define Constants
 ****************************************/
#define TOKEN "..." // Your Ubidots TOKEN
#define WIFINAME "..." //Your SSID
#define WIFIPASS "..." // Your Wifi Pass
#define MQTTCLIENTNAME "..." // Your MQTT Client Name, it must be unique so we recommend to choose a random ASCCI name
int pos = 0;
Ubidots client(TOKEN, MQTTCLIENTNAME);
/****************************************
 * Auxiliary Functions
 ****************************************/
void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i=0;i<length;i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
  if((char)payload[0] == '1')
  {
    if (pos==0)
    {
    for(pos = 0; pos <= 170; pos += 1) //The servo moves from 0 to 170 degrees.
   {            
     myservo.write(pos);
     delay(5);
    } 
     }
     else
     {
       myservo.write(170);
      }
     }
     else if ((char)payload[0] ==  '0')
     {
       if(pos==170)
       {
       for(pos = 170; pos>=0; pos-=1)       
        {                                
          myservo.write(pos);               
          delay(5);                         
         }
        }
       else
      {
        myservo.write(0);
       } 
       }
       else
       {
         myservo.write(170);
       }  
}
/****************************************
 * Main Functions
 ****************************************/
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  client.wifiConnection(WIFINAME, WIFIPASS);
  myservo.attach(5); // D1 pin 
  myservo.write(0);
  client.begin(callback);
  client.ubidotsSubscribe("pet","dispenser"); //Insert the dataSource and Variable's Labels
  }
void loop() {
  // put your main code here, to run repeatedly:
  if(!client.connected()){
      client.reconnect();
      client.ubidotsSubscribe("pet","dispenser"); //Insert the dataSource and Variable's Labels
  }

  client.loop();
  }


Nicely done!

In this blog post, we used ESP libraries in order to make our very useful and affordable project happen.  

Cell_Canela

Ubidots allows you to measure any kind of variables from sensors, such as movement, temperature, and humidity — and store all the historical information in the cloud. You can also trigger automatic alerts via SMS or email and use dashboards to visualize and check your sensors data remotely.

Topics:
arduino ide ,esp nodemcu ,iot ,ubidots cloud

Published at DZone with permission of Juan Jose Bello, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}