Smart Pet Feeder
The Smart Pet Feeder is a schoolproject.
Parts
All parts, pricing and places to buy are in my BOM (Bill Of Materials) which can be found in the attachement.
Requirements:
1 x Raspberry Pi 4 model B
1 x RGB Ledstrip (WS2801)
1 x LDR
1 x HC-SR501 PIR
1 x 28BYJ-48 Stepper Motor with ULN2003 Stepper Motor Driver Board
1 x Load Cell 1KG
1 x 1602 LCD Display
1 x HX711
1 x Breadboard
1 x Breadboard Power Supply
1x Potentiometer
1 x 10uF Capacitor
1 x T-Cobbler Plus Module
Electronics
Schematics made with Fritzing: http://fritzing.org/
Setup Raspberry Pi
1) Download the required software and files:
Win32 Disk Imager
Raspberry Pi OS
PuTTY
2) Configure the SD card
Insert SD card (minimum 8GB) with SD card reader in the PC and open Win32 Disk Imager.
Select the Raspberry Pi OS image and choose your SD card as your device and click read.
Once it's finished, go to the SD directory and you should see a file called 'cmdline.txt'. Open the file with notepad or notepad++ and add the line 'ip=169.254.10.1' (without quotes) at the end and save the file. Add a file called ssh (without extension). Once done you can put the SD card in de Raspberry Pi.
3) Configure the Raspberry Pi
3.1) Connecting to the Raspberry Pi
Open PuTTY and insert 169.254.10.1 as Hostname and Port 22. Once you click open you will get a screen. Now you will get asked to insert the username and password. (User: pi Password: raspberry).
3.2) Adding WIFI connection
First you need to become root by typing
sudo -i
After that type
wpa_passphrase "ssid" "password" >> /etc/wpa_supplicant/wpa_supplicant.conf
(Replace ssid and password with your own network name and password).
After that type
wpa_cli -i wlan0
Enter ' wget www.google.com ' to test your connection.
3.3) Updating the Raspberry Pi
After you have successfully connected your Pi to the internet you cna now update it by inserting these 2 commands. ' sudo apt-get update ' and ' sudo apt-get upgrade '.
3.4) Installing Packages
MariaDB Database: apt install mariadb-server mariadb-client -y
Apache2 Webserver: sudo apt install apache2
Python: sudo apt-get install python3
Python Packages: pip3 install flask-cors
pip3 install flask-socketio
pip3 install mysql-connector-python
pip3 install gevent
pip3 install gevent-websocket
3.5) Making a MariaDB User
Enter the following commands to get access on the MariaDB-server:
mysql -u root -p<br>grant all on *.* to '[your username]'@'localhost' identified by '[your password]'; <br>grant grant option on *.* to '[your username]'@'localhost'; <br>flush privileges<br>exit
4) Reboot The Raspberry Pi
sudo reboot
Configuring MySQLWorkbench
We need to connect MySQL with the Raspberry Pi's Database. Open MySQLWorkbench on your PC and add a new connection.
You change the following:
Connection Method: Standard TCP/IP over SSH.
SSH Hostname: [Raspberry Pi's IP address]
SSH Username: [Raspberry Pi's login]
SSH Password: [Raspberry Pi's login password]
MySQL Hostname: 127.0.0.1
MySQL Server Port: 3306
Username: [same as SSH Username]
Password: [same as SSH Password]
Configuring Visual Studio Code
Open Visual Studio Code and install the extension Remote-SSH. Press F1 and enter ssh. Choose for the option Remote-SSH: Add New SSH Host and enter the following:
ssh yourusername@IPofRasberryPi
A new window will open and ask for your password. Enter your Rasberry Pi's Password. Make the folders shown in the image. Now you can find the code of the project here. You can put the folder inside your RPI directory.
Show Frontend in Apache
Connect to your Raspberry Pi and enter the following:
sudo nano /etc/apache2/sites-available/000-default.conf
Now scroll down until you see DocumentRoot /var/www/html and change it to yourfolder/Code/Frontend.
Save the file and restart Apache by entering this command:
service apache2 restart
enter the following: sudo nano /etc/apache2/apache2.conf and scroll down until you see
< Directory />\ Options FollowSymLinks\ AllowOverride All\ Require all denied\ < /Directory >
and change it to
< Directory />\ Options Indexes FollowSymLinks Includes ExecCGI\ AllowOverride All\ Require all granted\ < / Directory>\
Save the file and restart Apache.
Building the Case
For my case I used an old shelft and used the top and bottom of the sleft for my top and bottom for the case.
1) I made a wooden box with only the front being open.
2) On the top left I made 2 little holes for the LDR so that it can sit on top of the case.
3) I made a cylinder for my motor. I made 3 holes. 2 holes to screw the motor on the cylinder and 1 hole for the motor to stick out on the inside.
4) I made 2 circulat shades and paste them together and put it on the motor.
5) I put all the electronics in the case.
6) For the front of the case I made a circulat hole for the cylinder. I cut a square shape on the left for the PIR sensor and a rectangular shape for the LCD display.
7) On the front bottom right and on the back bottom left I made a hole for the cables that need to stick out. (Power Supplies in the back and the RGB strip + Load Cell in the front).
8) In front of the case I put the Load cell between 2 wooden planks. The bottom is screwed with the 2 left screw holes and the top plank with the right screw holes. At the end I put the bowl top of the wooden plank.
Auto Start When Plugged in
To automatically run the code when plugged in you need to make a new file and put these line in it and edit the necessary.
[Unit]
Description=Smart Pet Feeder After=network.target [Service] ExecStart=/usr/bin/python3 -u /yourfolder/Backend/app.py WorkingDirectory=/yourfolder/Backend
StandardOutput=inherit StandardError=inherit Restart=always User=yourusername [Install]
After that save the file and insert the following command to copy it to /etc/systemd/system:
sudo cp smartpetfeeder.service /etc/systemd/system/smartpetfeeder.service