The Easy Cat Set
Hello!
I was given a school assignment a few months ago. For that task, I had to come up with a project. I didn't find a good project right away, but all of a sudden when I was sitting at my computer in the evening our cat came in and my mom likes when the cat is inside at night, so she asked me if I wanted to closed the door for our cat. I was lazy to do that so at that point came the idea of making an automatic cat flap. But that was just a small project so I wanted to add something like a food and water bowl. So the easy cat set came. for this big project you need a lot of motivation and patience and all that was not a problem with me. I knew that I was going to be happy the moment the project was going to be finished. That's where I got all my motivation from.
If you have followed all the steps you will have a working feeding and drinking bowl of which the weight and temperature is tracked and also an automatic cat flap that you can control remotely by bluetooth.
Supplies
Microcontrollers
- Raspberry pi 4
- ESP32
Sensors
- DS18B20 Temperature Sensor
The DS18B20 is a 1-wire temperature sensor from Maxim Integrated. The sensor can measure a temperatures in a range of -55°C to 125°C, with an accuracy of +/- 0.5°C.
- Motion Sensor
The motion sensor is a passive infrared sensor and are used to detect motion within approximately 7 meters distance. It also has an adjustable delay (from approximately 0.3 seconds to 5 minutes) and an adjustable sensitivity.
- Weight sensor
A load cell is a force transducer. It converts a force such as tension, compression, pressure, or torque into an electrical signal that can be measured and standardized. As the force applied to the load cell increases, the electrical signal changes proportionally.
Modules
- HX711
The hx711 module amplifies the signal so that the variations of the load cell can be digitally processed.
I searched for a long time how this worked so I will explain it to you so that no time is lost. First you download the library from the hx711.
Then open the example.py folder and put 'hx.set_reference_unit(92)' in comments. Then you need to calibrate the weight sensor with the Rapsberry Pi, this is very important. For this you need a weight whose weight is known (550g). As follows place the weight on the sensor and run the code example.py. Then a number (-987258) appears, this can be positive or negative. Finally, calculate the reference value by dividing the given number by the weight (-987258 / 550 = -1.795).
Actuators
- Micro Servomotor
The servomotor uses a plastic gear drive and is light and compact. It can be used for various applications and DIY products, such as toy cars, boats, windmills etc.
- Peristaltic pump 12-24V
I used this pump to get water from the container in the drinking bowl. This is a 24V version but there are lower version too.
- LCD Display
A liquid-crystal display (LCD) is a flat-panel display or other electronically modulated optical device that uses the light-modulating properties of liquid crystals combined with polarizers. Liquid crystals do not emit light directly, instead using a backlight or reflector to produce images in color or monochrome. I use the display to show the ip address
Connect All Electronics
Above you can see my fritzing circuits how I have connected my electronics. There are two types of circuits, one on a breadboard and one schematic. As I mentioned earlier I am using a Raspberry Pi with two weight sensors attached, a temperature sensor, an LCD, a peristaltic pump for the water and a servo motor for the food.
The pump that I use needs 24 volts while all the other electronics run on 3.3v-5v therefore I use a transistor for the pump.
Below you will find the two circuits in a PDF, this way you can have a better look at them.
Downloads
The Database
All data from the sensors is stored in this database.
My database contains 5 tables:
Cat flap option
This table contains the 3 options you can choose from: open, closed and indoor only.
Cat flap
This contains the cat flap options, date and time. The cat flap option table is a foreign key of the cat flap table. The date and time show when the cat passed by the cat flap.
Trough type
This contains the two types of troughs and these are the feed trough and drinking trough.
Trough
This contains a foreign key the trough type. Then we have data of sensors, the weight and temperature. The temperature will only be visible at the drinking trough. It also contains the date and time so you can see when the food or drink is at a certain amount.
Weight of troughs
This contains the two weights of the drinker and feeder themselves so they are subtracted from the gross weight. You can also omit this table by programming a calibration system.
The dump of my database can be found in my GitHub repository under Code>Database-export
The Backend
in the backend we have 4 important files:
config.py
This file takes care of the configuration to connect to the Database.
helpers
In the helpers folder there are 3 Python files. These codes are classes that are used for sensors and actuators. So the lcd file takes care of displaying a message, the temperature file takes care of retrieving the temperature and the hx711 file takes care of measuring the weight.
repositories
The repositories folder contains 2 Python files:
- The Database.py file is a helper that allows you to retrieve data from the database.
- The DataRepository.py contains SQL queries that can be used in the app.py file to create, read, update or delete data.
app.py
This file is the most important because it takes care of the whole operation of the project. It makes sure the servomotor is working, the temperature is retrieved and the weight is measured. It also uses routes to retrieve the stored data from the database and all the socketio.on's.
Esp32
This is the ino file for the esp32, it works with arduino.
The backend can be found in my repository under Code > Backend.
The Frontend
We are almost at the end. Now we have the fontend, I used AdobeXD to create my design how I would like my web server to look. The theme is the color blue but a nice to have was that there was a choice of what background could be chosen and so also the theme color changed. My design what that page would look like is also on top here.
The frontend contains 2 HTML files, the overview page and the weight page. It also contains a CSS file (screen.css), you can use this if you like my design. It also has 2 Javascript files under the folder scripts. The scripts work together with the backend to display data from the Database or backend.
My frontend can be found in the GitHub repository under Code > Frontend.
The Casing
My casing consists of 2 parts. The cat flap and the feeding/drinking bowl.
Cat flap
The cat flap was the easiest part because there really isn't much more to do to it, being an existing cat flap. At the bottom the mini servomotor was placed so the options could change, but because the dial had to be high enough, I had to cut out a piece at the top. Then I inserted the servo motor properly and glued it with tec 7 so it is secure. Next to the servo motor is the ESP32, it just lays there. Finally, the motion sensor is at the very top of the cat flap. At the top I only made a hole so that the ball of the sensor can pass through. For the final touch I attached the cat flap to a shelf so it could be presented nicely.
feeding/drinking trough
Now comes the biggest part of the enclosure. For my enclosure, I took plastic sheets. Why? It's not heavy, easier to work with than wood and I happened to have it lying around.
First I started with the base. So I measured everything and then cut it out. The sides are using plastic scraps of which I made an L-shape and screwed them on. Then I started with the feeder. The container is made from a 5l water bottle, this bottle is on a made tray containing the servo motor. I pushed the servo motor into a hole that I cut out of a plastic sheet.
The water container is also made of a 5l bottle and is standing on the surface. The water container comes with a water dipstick so you know from the outside how much water is still in it. I made a hole in the cap of the bottle with a tube through it and glued it tight. So the dipstick starts at the bottom. The tube then comes out on the right side and is fixed at the top. The two containers are bolted to the wall at the back. And both have a pvc tube in front to carry the feed/water in the containers.
Above the containers is a shelf with the water pump bolted to it. This is the main place of all the electronics, but not for long. I had once tested the weight sensors that are from below, but they didn't work so well anymore because the distance was too great from the wiring. I solved this by adding a substrate and making that the main location. After that problem was solved I put the weight sensors together the example is at the top between the pictures. I then added those two sensors to the housing along with all the electronics. Finally there was one small problem and that was that there were 3 cables, one coming out the left side, one coming out the right side and one coming out the back. This of course is inconvenient so my solution was to put a socket outlet in the housing with all the plugs in so there is only one cable left to run. The final touch is to cover it with sticky foil with cat paws on it.
Good luck and enjoy!