Introduction: Automatic Dog Feeder
First Prize in the
Internet of Things Contest 2017
The problem every pet owner has had at least once, did i feed my pet yet. I wanted a way to solve this this problem, that's why I build this automatic dog feeder. This will make sure you never forget to feed your pet, while at the same time training your dog.
By using this machine you can feed your dog via website, either manualy or at specified times. But the dog can also earn food by dropping a ball into a tube.
On the wesbite you can see how much your dog has eaten today and the days before or how much food is left in the reservoir. You can also set a maximum portionsize, so you're dog doesn't get overfed, and set specified times when you're dog should get food.
This way you can train your dog and make sure you never forget to feed him again.
Step 1: The Materials
- raspberry pi 3 model B
- nema 17 stepper motor
- A4988 stepper driver board
- A9060 light sensor
- laser transmittor (3V)
- 1Kg load cell
- 5Kg load cell
- 2 HX711 load cell amplifier
- mcp 3008 analog to digital converter
- female-female connectors
- male-male connectors
- 8Gb SD-card
- socket box for 2 sockets
- 12 Volt 2A adapter
- z-axis 8 to 5 mm
- 1,20 m- 60 cm, 2mm MDF wood plate
- cereal dispenser
- 7,5 or 9 cm diameter PVC tube (depending on the size of the ball you will use)
- 90° curve
- 17 cm straight
- 10 to 7 cm diamter narrowing piece
- sanding paper
- silicon gun
- second glue
The total cost of all the items when you buy them new is around €200. You can off cource lower this price by recycling some of the items. More info in the BOM
Step 2: Pi (basic Setup)
First we need to setup the pi, write jessie using win32diskimager on the SD-Card. You need to add an empty file without extension called ssh into the boot folder. To get an static ip you need to add ip=169.254.10.1 to "cmd.txt" file, it shoud now look like the image above.
Now you can insert the SD-Card into the pi and connect to it using putty. The login to the pi is pi, password is raspberry.
First do an sudo apt-get update, sudo apt-get upgrade, sudo apt get dist-upgrade, to get the pi up to date.
Step 3: Pi (mysql)
You need to install mysql to store data, you do this by using the following commands:
- sudo apt-get install mysql-server
- sudo apt-get install mysql-client.
During the installation you'll need to set your root mysql user password.
Now that mysql is installed,you can enter by using, mysql -uroot -p and entering the password you set earlier.
- create a database named smartpet
- create the tables using the queries in create tables.txt file
- then insert the data by importing all the other dump files to your database
- you now need to create 2 users like shown in the picture above, but :
- you need to change finly by website and feedingscript
- for both users the password is abc123
- change the grant privileges on *.* to smartpet.* , for both users
Now that our sql works we can move on to the build.
Step 4: Scales
First we need to make 2 scale's to weigh how much food is in the bowl and in the reservoir.
If you want to make it easier to connect you're load cell to the pi you can solder some female wire's onto the load cell wire's.
- measure the base of your bowl an your cereal-dispenser, in my case the bases were 2 times a 20 by 20 cm square
- use these measurements to make two identical planks for each scale
- now measure the dril holes to attach the load cell, when mesuring the holes make sure the center of the loadcell is in the center of the plank
- mill out the hole so the bolds dont are even with the plank and don't stick out
- put the bolts through the holes and place a nut on it. After this you place the loading cell on top of the bolds and screw them into the load cell
- Screw in the bold until there's about 1cm space between the base plate and the load cel. After this tighten the nut onto the base.
- now do the same (3-6) for the top plate
- when you're ready make sure the scale's are level by tightening or loosing up the nuts
Step 5: Calibrating the Scales
Now that we have the scales we have to calibrate them. Using this link, calbrating code, you can find the code to calibrate them.
You will have to download the following files: HX711.py and scale_1kg/5kg.
Now hook up de load cells to the HX711 driver boards like this:
- Red -> E+
- Black -> E-
- Green -> A+
- White -> A-
then connect to other end of the board to the pi:
- VCC -> 5v
- GND -> GND
- SCLK -> GPIO 21 (1Kg) / GPIO 24 (5Kg)
- DLT -> GPIO 20 (1Kg) / GPIO 23 (5 Kg)
First we have to alter to code a bit
- comment out the line: hx.set_reference_unit(2167)
- change the line max(0, int(hx.get_weight(5))) to hx.get_weight(5)
Now you can run the code. You need to place on it that is about half the weight of the load cell's limit.
Take an average of 10 values, then devide this value by the weight you placed on the scale, this can be positive or negative. For the 5 Kg scale the value needs to be positive, you can get this by switching the green and white wires on the driver board. Write these values down beacause we need them later.
Now that we have the value we can uncomment set reference and insert the value we got earlier, you can also change back the get.weight to what it was before.
Now test it out by placing different weight's on the scale, keep in in mind this won't be extremely accurate but for me the result value fluctuated around 3 grams from the real weight.
Step 6: Stepper Motor
Now we can test out the steppermotor.
Hooking up the a4988 stepper driver with the nema 17 motor:
- 5V -> VDD
- GND -> GND
- 2B -> blue wire stepper
- 2A -> red wire stepper
- 1A -> green wire stepper
- 1B -> black wire stepper
- Step -> GPIO 26
- Dir -> GPIO 19
- Reset -> Sleep
To turn the motor off when it isn't turning i added a transistor between the 12v power supply
- 12V + -> collecter
- vmot -> collector ( before the collecter a 1k resistor)
- base -> GPIO 13 with 1K transistor
- emitor -> GND mot, 12V GND
To try the motor add to a4998 the folowing code:
mot = a4988()
Now the motor will turn in an infinte loop. If the motor makes werid sounds while turing or it isn't runing at all you'll have to alter the potentio meter on top of the driver board (the small screw). Keep turning the screw slowly until the motor turns smoothly without (almost) any sound.
If the motor is turning to the left you'll have to change: GPIO.output(self.dir,GPIO.HIGH) --> GPIO.output(self.dir,GPIO.LOW)
When you're done testing make sure to remove the while loop from the code.
Step 7: Dispenser (base)
We also need a way to store and dispense the food:
- start by getting the iron rod, this rod is used to propel the screw in the cereal dispenser. We will have to sand down one side because the dispenser screw has a flat side.
- to make the dispensing easier I also clipped the wings of of the screw. Just clip it down so it doesn't touch the sides of cereal dispenser
- drill a hole in the back of the cereal dispenser. The center of the hole should be on the height where the stick passes through the dispenser itself. You'll also have to drill 4 holes to mount the steppermotor onto.
- cut a part away drom the dispenser holder.you'll need to cut from the right side where the holder supports the reservoir like in the image above, i will explain the reason in the next step.
- now you put the z-axis onto the steppermotor but don't insert the steel rod yet.
- at last you can mount the stepper motor onto the back of the holder
Step 8: Dispensor (reservoir)
The base is ready so we can work on the reservoir.
Building the reservoir i noticed the stepper motor isn't very strong, that's why we need to do a few modifications:
- clip the wings from the dispensor screw so that there's about 1-2 mm of space between the side of te dispenser.
- you need to cut about half of the reservoir's base, like the image above, this is to ensure the food wont get stuck and will just fall out when the motor turns.
- you need to make a small plate that fits into the dispenser, like the image above, if you it place in the reservoir it should be angling at 45°. This will limit how many food fall onto the screw so the motor will have enough power.
- Before glueing the plate into the resevoir using silcone, you just need to lay ithe plate in the in the reservoir en test it out, because the size of hole in the plate will depend on the size of the food.
Step 9: Casing: Cutting Matrials
Now that we have everything ready we can start cutting the wood we need for the casing Keep in mind the size of the base plate and height will vary from the type and size of the cereal dispenser you have.
- base plate of 60/22 cm (the width is the size of your scales +2 cm)
- 15/22 cm plate (again 22 may vary)
- 25,5/35 cm
- 35/5 cm
- 22,5/9,5 cm
- 22/25,5 cm
- 25,5/11 cm
- 25,5/39 cm
- 2 other shape like the images above
Step 10: Putting It Together
We now have all the parts and can start putting it together.
- place the 15/22 cm plate, 22,5 cm from the start of the base plate, on top of the base plate
- drill a small hole in it where you can fit the load sensor cables thru
- place the 1 kg scale in front of the recently placed plate, there should about 0.5 cm place between the scale and the base plate all around. The scale can't touch the side beacuse it would influence the measuring of the weight.
- screw the base of the scale onto the base plate
- to raise the 5 kg scale i placed 2 old woodslates on top of eachother so they would raise the scale about 6cm
- place the 5kg scale, 0,5 cm from the plate deviding the 2 scales, on top of the woodslates and screw the scale to the slates, like the first scale there should be 0,5 cm of place all around.
- now take the cereal dispenser and screw it on top of the 5kg scale.
- screw the side plate to the right side
- now screw the 25,5/11 cm plate in front of the base plate, before the 1 kg scale
- screw the 25,5/35 cm plate ate the back
- screw the 9/35 cm plate to the back plate and in front of the base plate
- place the 9,5/22,5 cm plate in front of the base plate next to the previous plate (22,5 down)
- and finaly screw the last side plate to the side
- now you will have to make door the fill the hole at the left slide. the way you hold the door closed it up to you.
Before we place the top, we will have to make a hole where the reservoir can fit thru, make to hole so the reservoir doesn't touch the side. Then you can screw the roof on it.
Step 11: Ball Detector
Because i wanted a way my dog could earn food i made a tube where he has drop in a ball. When he drops it in he gets a smal reward. To do this i used a laser and a light sensor to detect if a ball has been dropped.
- take a the straight pvc tube and drill 2 holes facing eachother the size of the laser and the lightsensor, make sure the laser is shining straight on the sensor
- you can then glue them in
How to connect them:
- red wire -> 3.3v
- blue/black -> gnd
For the lightsensor i used an MCP 3008 to read the data:
- 9 -> GND
- 10 -> CE0
- 11 -> MOSI
- 12 -> MISO
- 13 -> SCLK
- 14 -> GND
- 15 -> 3.3V
- 16 -> 3.3V
- connect 1 feet of the light sensor to pin 1 and also connect a 220 resistor to pin one
- resistor -> 3.3 V
- sensor -> GND
To test out the laser add this code to MCP.py:
print(m.data) (this should print a value, depending on the laser, under a 100.)
Again remove this code after your done.
Implement the tube in the casing:
- drill a hole to the right hand side, the size of the 90° turn.
- now check where the tube will go to thru the top of the casing an drill a hole so the tube narrower can fit in.
- if you see the ball gets stuck in the 90° turn, you'll have to file out the turn until it doesn't get stuck
- now connect the turn, the straight piece and the narrowing and silicone them to the side and the top of the casing.
Step 12: The Slide
To get the food into the bowl, we need to make a slide.
- get 2 2,5/15 cm woodslates and screw them at an angle to the side of machine
- make a plate, like the first image, this will fit around dispenser without touching it, the length of this plate depends on the size of your food bowl
- on this plate make a narrowing so the foods slides to the center.
- now make 2 holes in the plate. it should be at the place where the plate exits the machine.
- the size of de mdf plate is: 22/18 cm, we need this plate to hide the machine
- cut in this plate a small hole where the food can exit the machine
- just slide in the plate and screw it tide to the earlier placed slates
Now that everything is ready you just need to make a hole at the for an ethernet cable and the power cord at the back. Then you can place all the electronics inside off it. If you want you can solder it onto a PCB but you can just leave it on a bradboard if you want.
Step 13: Activating Everything
Now our machine works we need to get the website onto the pi.
int the untitled1 file you need to alter the reference units to the values you got earlier for youre scales:
- hx --> use the 1Kg reference unit
- hx_res --> use the 5Kg reference unit
To make these files boot up use this instructable
You'll only have to make a few adjustments:
- instead of pyhton you need to type pyhton3
- after the line pyhton 3 .... youshould place & to make it run in the background
The files you need to activate using python3 are:
- untitled1.py (i know weird name, but beause flask won't let me change it so this the name)
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
Step 14: Instructions
We now have everything ready.
Before putting food in the reservoir, place a bowl where the food will exit the machine ( on the 1Kg scale). If you don't do it, food wil ldrop out and can end between the side of the scale.
Don't move the machine when there is still food in the reservoir, this will mess up how much food will drop out or can even block the motor. If the motor gets stuck, just use a stick to get out the food that is laying on the blades or turn the motor manualy using your hands.
Step 15: Website Instructions
The first page is the home page here you can see:
- how much food the dog has eaten today
- how much food is left in the reservoir
- by using the manual feed you can give you're dog some extra food, this portion isn't subtracted from the maximum daily portionsize. This is used for exapmle when you went on along walk with you're dog so he has to eat a bit more.
On the second page is the hsitory page
- you can see the history of how much you're dog has eaten by hovering over the graph
- in the bar on top you can change the date
the third page is the timer page
- here you can set the times when you're dog should get food
- how much he gets per time depends on the maximum portion and how many times a day he should get food
the last page is the settings page
- here you can set some info about you're dog like, his name, weight, ...
- if you enter his weight the page will recommend the daily portionsize for you're dog. This is only based on the weight not on race,age, and so on.
- you'll have to set the maximum portionsize for you're dog, if you change it the new limit will activate add 00:00 AM the following day
- you can also see how much food he can eat today
Everythime food has been given, doesn't matter how, it will take about 10-20 seconds for the page to update/load because it needs to calculate the weights. It also isn't possible to give an other portion at this time.
- if you're using wifi it could take about 2 minutes for the pi to boot up and start the website, this is much faster by using ethernet
- also by using wifi after a certain amount of time the website is unreacheble beacuse the wifi shuts down, but you're dog will be able to get food at the times you selected or by using his ball. To fix this unplug and replug the feeder and the website should reboot
- if you're on the timer page when the dog is getting food at a certain time but he can't because the max portion limit is reached the website could crash
If you can fix any of these problems please let me know.
From now on you can keep track on how much you're dog can eat and you're live will be much easier.
We have a be nice policy.
Please be positive and constructive.