Smart-fridge
For Project One, a school project at Howest MCT (Kortrijk, Belgium)
I made a Smart Fridge for refreshments. The Smart Fridge can be used in a youth movement. to make sure the kids cant open the fridge he is locked u can open it with a badge
Supplies
Main Controller:
1) raspberry pi 4 Raspberry pi to control the entire system
2) SD-card (minimal 8GB)
Sensors and Actuators:
1)reed sensor magnetic contact
2)RFID-sensor Rfid-Sensor
3) ds18b20 Temperature Sensor
4) Solenoid 12V door lock| Arduino lock from the fridge
5) SRD-05VDC-SL-C relay 5V relay module WPM406
Electronics:
1) raspberry pi 7" touchscreen display
2) DC-Fan 12 40x40x10 for cooling the case
3) adapter board powering the display
4) raspberry Pi T-cobbler Easy wiring with Raspberry Pi
5) prototyping board 210x150mm cutted to 65x150mm for connecting everything
6) ac dc power converter used to power the fan and the lock
7) solid Wire PVC 0.2mm² Multicolour used to solder
Case and assembly:
13) spacer bolt 12mm 5mm used to higher the prototyping plate
14) cable glad set feedthrough for cables
15) panel feed trough usb-c to power the pi
17) USB Cable USB-C Plug powering the pi
18) Metal Enclosure 250.2x250.2x100.5mm cover
Schematic
Once you have all the parts at your disposal you can start wiring according to the fritzing scheme.
Attention! When you switch the relays, it is best not to plug in the socket,
Setup Raspberry Pi
Download the image
- download this image project 1
The image includes:
- Raspberry Pi OS
- Apache webserver
- MariaDB
2. Write image to SD card
For writing the SD card you can use Win32DiskImager, after that you can put the SD card in your Raspberry Pi and power it on.
3. Connect your PC and Pi through ssh or vnc
Connect your PC and Pi with a network cable, put your PC on a static IP (e.g. 192.168.168.100), the Pi automatically takes IP 192.168.168.168 when he gets no IP from a DHCP server. Use Putty on your PC and connect with your Pi on 192.168.168.168 on port 22 (ssh).
If you like to set up your Pi with a vnc viewer, that is possible too.
4. Login
The login of your Pi is student with password W8w00rd
5. Connect to WIFI
Now log in on your local network. You can do it with vnc (easy) or ssh (hard). With vnc you just go to raspi-config, with ssh you need to put in the following commands:
- sudo -i (password: W8w00rd)
- wpa_passphrase "your_SSID" "your_wifi-password" >> /etc/wpa_supplicant/wpa_supplicant.conf
- wpa_cli -i wlan0 reconfigure
6. Update
If you want, you can update your Raspberry Pi OS with the following commands:
- sudo update
- sudo upgrade
Now wait...
The Apache server is set up and goes directly to the index.html page of the Smart Fridge frontend.
- Also, the MariaDB user is set up on the Pi.
Setup the Database
The main structure of the database are the tables user(here you can find all the users and their id ), frigohistoriek(it keeps all the data from whatever is pulled out in the fridge) drinks(it keeps track of the content of the fridge) Historiek(The database stores everything that the fridge measures)
You need to make a new connection and put in the following details:
- Connection method: Standard (TCP/IP) over SSH
- SSH Hostname: 192.168.168.168 or IP from Pi on your local network
- SSH Username: student
- SSH Password: W8w00rd
- Username database: student
- Password database: W8w00rd (you can save this)
Backend
The backend of my project works with Python. In the repository you can find in the directory Backend the following directories and documents (on the picture you can see al used classes, libraries and more):
repositories
Includes the following documents:
- Database.py, a standard document that processes queries for a database.
- DataRepository.py, a lot of paths that handles the requests from the main file app.py that gives back data from the database or puts data in the database. You also can pass parameters through this document.
app.py
you can find the code in my GitHub repo in the backend map:
config.py
document provides that communication between the backend, frontend and database is possible, check if everything is correct for your personal Pi before running app.py.
service starting automatically
Normally on the image app.py start running automatically. You can configure this by yourself or stop the process.
Configuring mijnproject.service by the following commands:
- sudo cd /etc/systemd/system/
- sudo nano mijnproject.service
- now you see the following document
[Unit]
Description=ProjectOne Project
After=network.target
[Service]
ExecStart=/usr/bin/python3 -u /home/student/Smart-Fridge/Backend/app.py WorkingDirectory=/home/student/Smart-Fridge/Backend
StandardOutput=inherit
StandardError=inherit
Restart=always
User=student
[Install]
WantedBy=multi-user.target
- turning on proces: sudo systemctl start mijnproject.service
- turning off proces: sudo systemctl stop mijnproject.service
- enabling when starting up Pi: sudo systemctl enable mijnproject.service
- disabling when starting up Pi: sudo systemctl disable mijnproject.service
Frontend
The frontend of my project works with HTML, JavaScript, and CSS. In the repository you can find in the directory Frontend the following directories and documents:
script
In this directory can the JavaScript document be found. app.js listens to the request of the user on the site and handle his action by sending it to the backend with socket.io. datahandler.js is used to get data (e. g. for the graphs of the temperature) from the database while using the backend to do that you can get various CRUD destinations from frontend to backend that way. You can link JavaScript with classes in HTML, you can use Query Selectors to trigger the elements in HTML with JavaScript code.
style
This directory includes all the styling of the website from colors to fonts and icons. It also makes the website responsive so u can use it for web and app. There are a lot of classes that links the HTML with CSS. You can try it by navigating on your phone to the IP of your Pi.
index.html, user.html, frigo.html, historiek.html and inhoud.html
This are the main structures of the website; it links the CSS classes and JavaScript classes who also links it to the backend.
On every new connection the current temperature and the last person who scanned updates. Also the amount of refreshments and the data updates.
Casing
for the cover we use the: Metal Enclosure 250.2x250.2x100.5mm cover the square for the screen is 95mm by 38.5mm as well as you can see we need to make some holes for the cables to go trough the holes where mad witth an 12mm drill also make sure to makes some little holes in the back for air flow
Enjoy Your Fridge
and your fresh drinks!