Introduction: SmartFeeder

SmartFeeder is an automatic pet feeder which you control via a website.

This smartdevice just makes your life as a pet owner much easier. You can set a feeding moment (time and weight) on the site. The device makes sure your pet gets the right amount on the exact moment.

The site also shows you the amount of food and water left in the device so you know when to refill it. There also is an option to see all the past feeding moments and the exact amount of food given at that moment.


Microcontrollers and computers:

  • Raspberry Pi(4)
  • 74HC595N (Shiftregister) So LCD use less mins on Pi
  • HX-711 (Load Cell Amplifier) To Read load Cell

Sensors and modules:

  • HC-SR04 (Ultrasonic sensor) To measure water level
  • 2x Infrared Sensor (3pin - digital) To 3 stepmeasure food level
  • 1KG LoadCell To weigh portions


  • 2x SG90 (Micro Servo) 1 to power food dropping mechanism and 1 to power lid on food tray

Optional sensors and modules:

  • LCD screen To display IP adress of Pi (if not static)

Other electronic nessesities:

  • Breadboard
  • Breadboard cables
  • Resistors (1k and 2k)
  • Micro SD card (16 GB) + micro SD to Sd adaptor

Non electronic necessities:

  • Wooden plank(s)12mm thick To make casing and feed section
  • Wooden plank 2mm thick For back and front plate and lid on food bin
  • Screws 3x25mm
  • 2x4M and 2x5M + nutsbolds For Loadcell
  • PVC Tube ø50mm To guide food to food tray
  • PVC 45° Corner ø50mm
  • 2 Bins( safe to use for food) As reservoirs
  • Rubber tube (safe for use for food) To guide water to drink tray
  • Hot glue To secure sensors
  • Silicone To make Water reservoir airtigh


  • Soldering Iron
  • File
  • Sandpaper
  • Small power drill
  • (Small) scale

Step 1: Setting Up the Raspberry Pi

Everything such as: Backend, Frontend, Database will run on the Raspberry Pi. For everything to be able to run we will have to set up some things:

Part 1: Install Raspbian on a Raspberry Pi
Here is a link to a tutorial:

Part 2: Setting up a WiFi
This can be done using:
wpa_passphrase "YourNetwork" "YourSSID" >> /etc/wpa_supplicant/wpa_supplicant.conf
Now you just have to reboot the pi and check with the command "ipconfig" if the WiFi is successfully added.

Part 3: Install the webserver and database
There is still a default password set on the pi, change this with the "passwd" command.

Install the following

Apache, PHP
sudo apt install apache2 -y
sudo apt install php libapache2-mod-php -y

sudo apt install mariadb-server mariadb-client -y
sudo apt install php-mysql -y
sudo systemctl restart apache2.service

sudo apt install phpmyadmin -y

Part 4: Installing the necessary Python libraries
For the backend, we will need some libraries. You install these using following commands:
pip3 install mysql-connector-python
pip3 install flask-socketio
pip3 install flask-cors
pip3 install gevent
pip3 install gevent-websocket

Step 2: Electronic Setup

This is an overview of how the electronics will be put together. The (GPIO) pins may vary with the type op Raspberry Pi you have. Check the if the pins are correct.

Step 3: Database

The database looks like this.

Metingen (measurements):
This table contains the data of the sensors.

Acties (actions):
This table contains the description of the ActionCodes.

Sensoren (Sensors):
This table contains information about the sensors.

This table contains the name, nickname and the password of the feeder. (This table can be used for a login system, which is not implemented at the moment)

Voedermomenten (Feedingmoments):
This table contains the feedingmoments that heve been set through the website.

The database can be found on my Github.
Open the sql in PHPMyAdmin / MySQL Workbench and run it.

Step 4: Loadcell

Make sure your loadcell is mounted like the picture above. It has to be "floating" on bolts. The side with the cable and the M4 thread is the "Base". This has to be mounted to a flat serface.

Every loadcell behaves different. This depends on the voltage, what weight loadcell you have....

So we have to find out what ratio your loadcell has. I made a python file to find out your ratio. This can be found on my Github.

Write down the ratio the script gives you. We will need it later

Step 5: Backend

The backend can be found on my Github.

Place all the files from "Backend" onto the Raspberry Pi.

Explanation of the code:

  1. Initially the IP-adress is displayed on the LCD. After that it checks every 30 seconds if the IP-address has changed. If it did it will display the new address.
  2. There also is another thread running which checks everey 15 seconds if the time on the Raspberry Pi matches with a feedingmoment in the database. To trigger the feeding process.
  3. Another thread reads the data from the reservoirs every 15 minutes and writes them to the database.
  4. There also are a few endpoints being set up with database data for the front and backeend.


Go to and and check if the database data is correct. If not, change them.

Setting it up as a service:

Try to run, once you have confirmed this is working, we can use it as a service.This will automatically start the code in the background when you boot up your pi.

To do this:
copy smartfeerder_service.service to /etc/systemd/system/ctb_service.service
With the sudo cp smartfeeder_service.service /etc/systemd/system/smartfeeder_service.service command
Now enable it using the systemctl enable smartfeeder_service.service command.

More info can be found on

Step 6: Frontend

Copy the frontend files to /var/htmlon the Raspberry Pi. The files can be found on my Github.

This is the website to operate the feeder, it also conains the script to communicate with the backend.

When copying there might occure an error involving rights.

Use sudo chmod 777 /var/www/html/ (Never use this in production environments due to securityrisks)

Step 7: Casing

The structures in the photo's above will function as the "outher shell" of the project. Ahole in the top with a tube will guide the food through the tubes.

Step 8: Feeding Part

Out of the smaller shell the feeding part is made. The top has an extra border and is devided into sections. The biggest part is for the food, the smaller one is for water. The smallest one is a chamber to store the servo that moves the lid over the food tray.

Step 9: Feeding Mechanism

This is the feeding mechanism it's made out of the pvc tube and 45° corner. There hes been made a hole through the tube Inside the tube is a plate which is being rotated 90° to let food through. It is secured at the tube in the big outher shell.

Step 10: Reservoirs

The tubs are used as reservoirs. For a tub te be a food reservoir there has to be a hole the size of the PVC tube. The 2 Infrared sensors are placed in 25% and 75% of the heigt of the bin. For a bin to be a water reservoir there has to be a hole with the rubber tube. One important detail is that the waterreservoir has to be airtight! Also around the Ultrasonic sensor that is placed in the lid.

Step 11: Putting It Together

Put everything together. Place the thin plates (with holes for the watertray and the PVC tube) at the front and a full plate the back of the big outher shell. You can paint it if you like to.