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 familiar environment or a youth movement. When you want a consumption from the fridge you can sign in with a badge, the fridge will measure live with a scale how many consumptions are taken out. After you logged out, the amount of consumptions is linked to your account.
You can check on a website what temperature the fridge is at and who signed in last. You can also see how many refreshments are left in the fridge and turn the fridge on and off. It is possible to see how many each person needs to pay to the owner of the Smart fridge.
You can find the code for the project on my repository on Github.
Downloads
Supplies
Main Controller:
- Raspberry Pi 4 model B (2GB or 4GB)
- SD-card (minimal 8GB)
Electronics:
- USB C charger (for Raspberry Pi)
- USB B charger (for Arduino Uno)
- 5V/3.3V module
- Breadboard
- Resistors
- T-Cobbler
- Jumper wires (male-male (40x), female-male(20x))
Sensors and Actuators:
- DS18B20, 1-wire (temperature sensor)
- RFID RC522 Read and Write Module (scanner)
- HX711 AD Module with 4x 50kg load cells (scale)
- Mini Fridge with 5V relay
- Arduino Uno with Level Shifter with 4x7 segment display
- LCD with I²C display
Wooden Case + 3D print + Aluminum plate:
- 2x 400mm x 400mm x 12mm MDF
- 2x 400mm x 100mm x 12mm MDF
- 2x 376mm x 100mm x 12mm MDF
- 200mm x 300mm x 12mm MDF
- Screws and corner profiles
- 3D-print filament
- Aluminum plate
Tools:
- Screwdriver
- Table saw
- Soldering iron with solder
- 3D-printer
Hardware
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, you are working with 220 volts!!!
You also need to solder the 4x7 segments display and the temperature sensor. Make sure you use the level shifter between the Arduino and raspberry pi for serial communication.
The middle wire of my load cells is green, it can happen that they are red too. Keep in mind that the load cells that are crossed need to be wired in pairs, E+ and E-, A+ and A-. The best way to find the middle wire is too measure out the load cells with a multimeter, the two outer wires show 2000 ohms
Look carefully at the resistor values on the scheme when you are wiring.
Setup Raspberry Pi
The Raspberry Pi is our main device who connects everything, backend, frontend, and database. To let the project work you need to follow the next steps.
1. Download the image from OneDrive
You can find the image of the project on my OneDrive.
The image includes:
- Raspberry Pi OS
- Apache webserver
- MariaDB
- Main code for the Smart Fridge
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 Historiek (tracking of the sensors), Persoon (persons), Verbruik (usage of a person) and Frigo (what is in the fridge). You can also find a dump of the database in the repository in the directory Database.
Historiek
The database stores everything that the fridge measures in a table Historiek. He keeps the temperature of the fridge, when somebody comes to scan and if the fridge is turned on or off.
Persoon
Table Persoon stores all the customers of the fridge in his table
Verbruik
Links Persoon with a consumption and how many were taken and when.
Frigo
Stores information of how many consumptions are still in the fridge.
Connect through ssh
You can access the database from your pc with a ssh connection with MySQL Workbench.
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):
helpers
Includes the following classes:
- KlasseLCD_I2C.py, to write easy to my LCD with I²C.
- KlasseHX711.py, to easy get data from my HX711 AD Module with load cells.
- KlasseKNOP.py, to initialize a pull_down_button, you can also put the fridge on and off with a button if you want to.
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
The main document of the backend is the app.py, you need to run this document if you want to get my project running. The backend uses Flask with Socket.io to handle communication with the frontend. This document also reads data from the sensors and write data do the actuators. It provides serial communication with the Arduino who sends numbers to the 4x7 segment display, you can send time from the PI or how many consumptions are taken out. It also provides communication with the RFID Read and Write Module through SPI, you can also send text to the LCD display with I²C. Of course, it also provides a change of weight on the scale of the fridge. The backend works with multiple threads that run from time to time, you can choose by yourself how long the thread has to wait. There is a thread for sending time serial to Arduino with the 4x7 segment display, a thread for reading the RFID Module and a thread for measuring the temperature every minute.
config.py
The 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 QuerySelectors 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, personen.html and data.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 conncection the current temperature and the last person who scanned updates. Also the amount of refreshments and the data updates.
Making Case + Install Hardware Into It, 3D-print and Aluminum Plate
For the case you need the wooden MDF planks. With the wooden planks you make a container of 40 cm by 40 cm of 10 cm high. The top shelf is removable so you can easily work on the electronics.
You need to make gap for the LCD display and 4x7 segment display, the RFID you can just screw on the back of the top shelf, the plank is 12mm thick, so it can go through.
For the scale it is recommended to 3D-print feet's for the load cells which you can find at Thingiverse. You need 4 of them and you can put them on a MDF plate as big as the dimensions of the refrigerator.
You also need to make a hole under the scale so the 4 middle wires of the load cells can go inside the container, you can also use this hole for the temperature sensor.
On the back you can make holes for powering the Raspberry Pi, Arduino Uno, 3.3V/5V Module and fridge. A distribution plug inside the container is recommended.
When everything is inside you can screw everything down, make sure you don't use screw longer than 10mm.
The aluminum plate on the front is sponsored by Impress (Kortrijk).
Enjoy Your Smart Fridge!
I hope the explenation of my project was clear.
If you have any questions, you can email me: michieldeseck@hotmail.com
You can also visit my site of my project: Project One.