Automatic Dog Dispenser

About: student MCT at Howest (Kortrijk Belgium)

With my project I make sure that when you leave your dog alone at home, he / she is never without food.

The automatic feeder will be "hacked" from a cornflakes dispenser. The dispenser is the reservoir for dog food, the wheel at the bottom will be connected to a servo motor that automatically drops food when the crib is nearly empty and when the dog is close enough. At the bottom of the dispenser there will be a PVC tube attached that will drop the dog food nicely into the crib. This project will therefore have 3 sensors, 2 of which are not covered in class and 1 of which is an actuator.

The first sensor is the RFID reader. This sensor checks when the dog comes close to the crib. The RFID will be incorporated in the dog's collar. If this sensor notices that the dog is close enough, it will transmit a signal to the second sensor. The second sensor is the weight sensor (not covered in class) that measures the food in the crib, if this sensor detects that the weight is too low, it will send a signal to the servo motor that will drop the food into the crib (with confirmation of the RFID and the weight sensor). In short, the dog only gets extra food when he / she is close enough to the crib and when the crib is almost empty. Of course there is also a limit set that you can set yourself via the web server; so that the dog does not get too much food per day. The third sensor is a light sensor that illuminates an LED floodlight when it is too dark around the crib. The actuator will therefore be a servo motor connected to the wheel in the dispenser.

This project is meant for dogs, you can also use it for other small pets.

Supplies:

Raspberry Pi 3

Load cell (1KG)

HX711 load cell amplifier

Food bowl

Cereal dispenser

Wood ( + screws and screwdriver)

Light sensor

Led

RFID reader rc522

Jumper wires

16*2 LCD (display)

Servo motor

5V power adapter

Resistor 470 Ohm

PVC tube

Breadbord

Potentiometer

Saw

Sanding paper

Silicon gun

Step 1: Pi Setup

Setup

To get started we’ll first need to set up your Pi.

You’ll need two things:

- Win32 Disk Imager from https://sourceforge.net/projects/win32diskimager/...

- Raspbian OS image from https://www.raspberrypi.org/downloads/raspbian/

Download the ZIP file and extract it to wherever you want.

The installation

1. Select your image via the folder icon

2. Select your SD card via the dropdown

3. Click on write

Now we’ll need to do some extra tinkering with some settings so we’ll be able to access the Pi.

1. Go to the SD card’s boot directory

2. Open the file "cmdline.txt"

3. Add ip=169.254.10.1 At the end of the long line of text separated with a space (on the same line).

4. Save the file.

5. Create a file named ssh with no extension in the same directory

Now you can eject the SD card and put it in your Pi.

Connecting

Now we will need to setup the software.

First plug in a LAN cable, one end in your desktop/laptop and the other in your Pi.

Now boot the Raspberry Pi.

1. Install Putty from https://www.putty.org/

2. Enter 169.254.10.1 in the IP box.

3. Make sure SSH is selected and port 22 is filled in.

4. Click open

5. Fill in the username: pi

6. Fill in the password: raspberry

Raspi-config

Open the Raspi-config utility by using:

sudo raspi-config

Enable the following options in the interfaces category

- 1-Wire

- SPI

Disable the following options in the boot options category

- Splash screen

Lastly set the Desktop/CLI setting in the boot options category to Desktop Autologin.

WiFi

For the dog feeder we need to have a wifi connection so make sure you have your wifi credentials close.

1. Go into root mode

sudo -i

2. Paste this line but make sure that the SSID and Password are both filled in

wpa_passphrase "SSID" "PASSWORD" >> /etc/wpa_supplicant/wpa_supplicant.conf

3. Enter the WPA Client.

Wpa_cli

4. Select the interface

Interface wlan0

5. Reload the config

Reconfigure

Make sure you are connected correctly by typing ip a and seeing if you have an IP on the WLAN0 interfaces.

Packages

Now that we are connected to the internet we'll have to install some packages.

First we'll need to refresh the package lists for the latest one.

sudo apt update

Python

We'll force Raspbian to use Python 3

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

update-alternatives --install /usr/bin/python python /usr/bin/python3 2

MariaDB

Paste the following line to install the database.

sudo apt install mariadb-server

Then we'll need to secure our installation.

mysql_secure_installation

It will ask us for current root password since we don't have one just press enter.

Next it's asking if we want a root password type in y since we want one.

For the next questions just enter Y.

Next we'll be creating a user that we'll be able to use for the mirror.

Enter the mysql shell by doing:

- Elevate ourselves to root

Sudo -i

- Enter the mysql shell

Mysql

- Replace with your own username and the same with

grant all privileges on *.* to ''@'%' identified by '';

- grant all privileges on *.* to ''@'%' identified by '';

Next we’ll be adding our database.

Apache Webserver

To install the Webserver run the line below.

sudo apt install apache2 -y

Python packages

We're going to install these packages

- Flask

- Flask-Cors

- Flask-MySQL

- Flask-SocketIO

- PyMySQL

- Gevent

- Gevent-websocket

- Httplib2

- Python-socketio

- Requests

- Wsaccel

- Ujson

By doing

pip install Flask Flask-Cors Flask-MySQL Flask-SocketIO PyMySQL gevent gevent-websocket httplib2 python-socketio requests wsaccel ujson mfrc522 hx711 Adafruit-CharLCD

Step 2: Led and Light Sensor

Hooking up the led

  1. S -> GPIO15 (rxd0)
  2. + -> 5V
  3. G -> Resistor 470 ohm and GND

Hooking up the light sensor

  1. OUT -> GPIO17
  2. VCC -> 3.3V
  3. GND -> GND

Now we can test if our led and light sensor works with this little script

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)

GPIO.setup(15, GPIO.OUT)

GPIO.setup(17, GPIO.IN)

try: while True:

if GPIO.input(17) == 0:

GPIO.output(15, GPIO.HIGH)

if GPIO.input(17) == 1:

GPIO.output(15, GPIO.LOW)

except KeyboardInterrupt: GPIO.cleanup()

Step 3: Servo Motor

Hooking up the servo motor

  1. OUT -> GPIO18
  2. VCC -> 5V
  3. GND -> GND

Now we can test if our led and light sensor works with this little script

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

GPIO.setup(18, GPIO.OUT)

p = GPIO.PWM(18, 50)

p.start(12.5)

try:

while True:

p.ChangeDutyCycle(12.5)

time.sleep(1)

p.ChangeDutyCycle(2.5)

time.sleep(1)

except KeyboardInterrupt:

p.stop()

GPIO.cleanup()

Step 4: RFID Reader RC522

Hooking up the RFID

  1. RST -> GPIO6
  2. MISO -> GPIO9 (MISO)
  3. MOSI -> GPIO10 (MOSI)
  4. SCK -> GPIO11 (SPISCLK)
  5. SDA -> GPIO8 (SPICS0)
  6. 3.3V -> 3.3V
  7. GND -> GND

Now we can test if our RFID reader works with this little script

import RPi.GPIO as GPIO

from mfrc522 import SimpleMFRC522

reader = SimpleMFRC522()

text = input('New data:')

print("Now place your tag to write")

reader.write(text)

print("Written")

Step 5: Load Cell HX711

Hooking up the Load cell to the HX711 driver board

  1. Red -> E+
  2. Black -> E-
  3. Green -> A+
  4. White -> A-

Hooking up the Load cell

  1. DT-> GPIO27
  2. SCK -> GPIO22
  3. RED -> 3.3V
  4. GND -> GND

Now we can test if our load cell works with this little script

import RPi.GPIO as GPIO
import time import sys from klasses.HX711 import HX711

def cleanAndExit(): print( "Cleaning...") GPIO.cleanup() print("Bye!") sys.exit()

hx = HX711 (22, 27)

hx.set_reading_format ("LSB", "MSB")

hx.set_reference_unit (2167)

hx.reset()

hx.tare()

while True:

try:

val = max(0, int(hx.get_weight(5)))

print(val)

hx.power_down()

hx.power_up()

time.sleep(0.5)

except (KeyboardInterrupt, SystemExit): cleanAndExit()

Step 6: LCD (16*2)

Hooking up the LCD

  1. RS -> GPIO21
  2. RW -> GND
  3. E-> GPIO20
  4. D0 -> GPIO16
  5. D1 -> GPIO12
  6. D2 -> GPIO6
  7. D3 ->GPIO24
  8. D4 -> GPIO23
  9. D5 -> GPIO26
  10. D6 -> GPIO19
  11. D7 -> GPIO13
  12. VSS -> GND
  13. VDD -> 5V
  14. A -> 5V
  15. K -> GND
  16. V0 -> middle potentio pin

Now we can test if our LCD screen works with this little script

import Adafruit_CharLCD as LCD
lcd_rs = 21

lcd_en = 20

lcd_d4 = 23

lcd_d5 = 26

lcd_d6 = 19

lcd_d7 = 13

lcd_columns = 16

lcd_rows = 2

lcd = LCD.Adafruit_CharLCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows)

lcd.message('169.254.10.1')

Step 7: Full Circuit

here you can check again if the entire circuit is correct

Step 8: Start of the Case

I used a cornflake dispenser as a reservoir for the dog food

I connected the wheel in the dispenser to my servo motor

Now I can control the wheel with my servo motor and drop food out of the reservoir

At the end of the reservoir there is a PVC tube connected that drops the food nicely into the crib

I use wood as a casing

Step 9: Putting It Together

Step 10: The Website

Now our machine works we need to get the website onto the pi.
Now everything is up and running some few instruction on how the site works.

You can connect you're pi to the wifi by plugging in an hdmi cable and activate this way

The first page is the home page, here you can see:

  • Realtime info about the light
  • Realtime info about the food that is left in the bowl
  • You can drop food
  • Info about the dog

The second page is the edit page, here you can edit:

  • the name of your pet
  • the age of your pet
  • the weigth of your pet
  • the photo of your pet

The third page is the history page, here you can see:

  • when the light did go on
  • when the dog has eaten
  • when the food has dropped

The fourth page is the settings page, here you can edit:

  • when the food needs to drop
  • the amount of food to drop
  • max food/day
  • the light

Share

    Recommendations

    • Games Contest

      Games Contest
    • Sew Tough Challenge

      Sew Tough Challenge
    • DIY Summer Camp Contest

      DIY Summer Camp Contest

    Discussions