Introduction: Smart Pet Feeder

Do you have a pet?

  • No: adopt one! (and come back to this instructable).
  • Yes: good job!

Wouldn't it be great if you could feed and give water to your loved one without canceling plans in order to get home on time? We say worry no more.

In this project we've made a remote controlled (through web) food and water dispensers.

Through the online dashboard you can view data and control the dispensers:

  • View food and water levels in the tanks.
  • View food and water levels in the bowls.
  • Does the animal eat or drink at this moment?
  • Schedule feedings (device won't dispense food if there's enough food in the bowl).
  • Automatically dispense water when the bowl gets empty.
  • Dispense food/water with a press of a button.
  • Receive push notifications to your phone (by Telegram app).

Who Are We?

Created by Tom Kaufman and Katya Fichman, Computer Science students at IDC Herzliya.

This project was made for an IOT course.

Supplies

Electronics

  • 2 X ESP8266 (Wemos d1 mini).
  • Jumper wires.
  • 2 X Breadboard.
  • 4 X Ultrasonic sensor.
  • 2 X Load cell.
  • 2 X Load cell amplifier (HX711).
  • Servo (180°).
  • Servo (continuous rotation).
  • 2 X 6V power supply.

Parts

Step 1: How Does It Work?

The ESP8266 boards send sensors' readings to Node-RED through Mosquitto (MQTT broker).

Node-RED processes the data, making actions accordingly (also send dispense commands to the ESP8266 boards through Mosquitto) and displaying info on the dashboard.

All the computations are performed in Node-RED so it would be easy to replicate this project and change the processing of the data according to your settings and preferences without getting your hands dirty with coding.

Step 2: Softwares

Arduino IDE

Download and install (link: https://www.arduino.cc/en/Main/Software).

Mosquitto

Download and install (link: https://mosquitto.org/download/).

Node.js

Download and install (link: https://nodejs.org/en/download/).

Node-RED

Follow the instructions: https://nodered.org/docs/getting-started/local

ngrok

Download: https://ngrok.com/download

Telegram

Install the app on your smartphone.


Step 3: Circuit Layout

* Both devices have identical circuits

Water Dispenser

  • Ultrasonic sensor (for the water tank)
    • GND - G
    • VCC - 5V
    • ECHO - D5
    • TRIGGER - D0
  • Ultrasonic sensor (for the pet's distance from the bowl)
    • GND - G
    • VCC - 5V
    • ECHO - D6
    • TRIGGER - D7
  • Load cell
    • GREEN - A+ (HX711)
    • WHITE - A- (HX711)
    • BLACK - E- (HX711)
    • RED - E+ (HX711)
  • HX711 (load cell amplifier)
    • GND - G
    • VCC - 5V
    • DT - D4
    • SCK - D3
  • Servo (180°)
    • GND - G
    • VCC - 5V

Food Dispenser

  • Ultrasonic sensor (for the food tank)
    • GND - G
    • VCC - 5V
    • ECHO - D5
    • TRIGGER - D0
  • Ultrasonic sensor (for the pet's distance from the bowl)
    • GND - G
    • VCC - 5V
    • ECHO - D6
    • TRIGGER - D7
  • Load cell
    • GREEN - A+ (HX711)
    • WHITE - A- (HX711)
    • BLACK - E- (HX711)
    • RED - E+ (HX711)
  • HX711 (load cell amplifier)
    • GND - G
    • VCC - 5V
    • DT - D4
    • SCK - D3
  • Servo (continuous rotation)
    • GND - G
    • VCC - 5V
    • CONTROL - D8

Step 4: Craft

Water dispenser

  1. Glue the servo to the top of the bottom part of the dispenser (as shown in the photo).
  2. Drill a small hole in the water dispenser's knob.
  3. Connect the servo head to the knob with a wire (make sure that the servo head is at position 0 and make sure that the wire is tight).
  4. Glue one ultrasonic sensor to the inner side of the tank, near its top (sensor facing down).
  5. Glue one ultrasonic sensor below the water knob toward the outside (make sure it's high enough so that the water bowl will not effect its readings).

Food dispenser

  1. Screw the servo to its holder (3D printed part).
  2. Glue the funnel (3D printed part) to the tank holder (3D printed part).
  3. Connect the tank holder to the dispenser's stand (3D printed part) and put the tank in place.
  4. Insert the spinning part (3D printed) to its place and through the spinning rubber part of the dispenser.
  5. Screw the servo holder part to the dispenser's stand.
  6. Glue one ultrasonic sensor to the inner side of the tank's lid (sensor facing down).
  7. Glue one ultrasonic sensor to the side of the tank's holder facing towards the place where your pet will eat.

Load Cells

  • Glue each load cell to the 3D printed base and plate (load cell's arrow facing down).

Step 5: Mosquitto

Open Mosquitto (windows users: go to Mosquitto folder, open cmd and enter: "mosquitto -v").

* To get the internal IP address of the computer, run cmd and enter "ipconfig".

Step 6: Arduino IDE

Open the Arduino IDE and follow the "Install ESP8266 Add-on in Arduino IDE" part of this guide: https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/.

Go to Tools->Board and choose "LOLIN(WEMOS) D1 R2 & mini".

Go to Sketch->Include Library->Add .ZIP Library... and add the 3 libraries in the "Libraries.rar" file.

Open "HX711Calibration" sketch, upload it to both ESP8266's, run it and follow the instructions (in the beginning of the code and in the serial monitor) to calibrate the load cells (make sure that the baud rate of the serial monitor is set to 115200 baud).

* Write down the calibration factor and the zero offset (for later use).

Open "FoodDispenser" and "WaterDispenser" sketches through the IDE and change the following variables with your settings (in file "Settings.h"):

  • WIFI_SSID
  • WIFI_PASSWORD
  • MQTT_SERVER
  • LOAD_CELL_CALIBRATION_FACTOR
  • LOAD_CELL_ZERO_OFFSET

* In MQTT_SERVER enter the internal IP address from the "Mosquitto" step.

Upload the sketches to your two ESP8266 (one code to each board).

* Notice that we've used the "AsyncMqttClient" library and not the more common "pubsubclient" library since the esp8266 crashes when combined with the "HX711" library.

* If you choose to make changes to the code, make sure not to use the "delay" and "yield" functions inside callback functions as it will cause crashes.

Step 7: Ngrok

Unzip the downloaded file (from the link in the "Softwares" step).

Open "ngrok.exe" and run the command "ngrok http 1880".

* You can select the region closest to you (au, eu, ap, us, jp, in, sa). The default is us.

For instance running the command: "ngrok http --region=eu 1880" (set the region to Europe).

Now you'll see your web address for external use (we'll refer to this address as YOUR_NGROK_ADDRESS).

Step 8: Node-RED

Open Node-RED (windows users: open cmd and enter "node-red") and go to http://localhost:1880 (if it doesn't work, search for the address in the cmd window where it's written "Server now running at").

Open the menu (at the top right corner) and press "Manage palette".

Go to "Install" tab, search and install these modules:

  • node-red-contrib-persist.
  • node-red-contrib-cron-plus.
  • node-red-contrib-ui-led.
  • node-red-dashboard.
  • node-red-contrib-telegrambot.

Go the menu->Import and upload the flow file (extract the attached RAR file and upload the json file).

See the attached images for explanations about the flow.

You'll need to modify these nodes with your settings:

  • Update the "Telegram sender" node's profile with your bot's username and token (use this guide: https://www.iotwithus.com/send-messages-using-tel... ).
  • In the bottom of the flow change the payloads of "Ngrok Address" and "Telegram Chat Id" nodes (get your chat id by using the Telegram guide in the link above).
  • In the bottom part of the flow there are settings nodes - modify them according to your needs:
    • Activate pet is eating/drinking alerts.
    • Define what is the distance for activating eating/drinking alert.
    • Define bowls and tanks data processing.
    • Modify dispenses times (for how long does the dispenses occur - auto mode and button press).
    • Define food bowl's overflow threshold percentage (abort automatic food dispense if there's enough food in the bowl).

Deploy the flow (at the top right).

* Only at the first deploy, you will see a warning in the debug window about missing 'persistance.json' file. Don't worry about it since at the moment you'll set feeding times or change the auto water switch, it'll initialize this file and you'll no longer have this warning.

You can view your dashboard on http://NODE-RED_PC'S_INTERNAL_IP_ADDRESS:1880/ui (if you're connected to the same LAN as the server) or YOUR_NGROK_ADDRESS/ui (from everywhere).

Step 9: Wrap Up

We hope this tutorial was informative and easy to read, understand and implement.

Feel free to ask us anything.