Smart Mini Fridge
As a student Multimedia & Communication technology in Howest Kortrijk, I had to make my own IoT project. This is a combination of everything I learned in the modules of the first year. I also added a lot of new things aswell. Because I spend a lot of time behind my computer but I also exercise a lot I thought it would be clever to make a smart minifridge so I could easily access a variation of cold drinks and track my drinking behaviour while I’m busy working in my room.
My project is a Raspberry Pi powered website designed for people who are working a lot in the same room and would like to easily view their drinking behaviour.
What are the features of this website?
- Viewing the amount of consumed drinks in ml (line chart)
- Viewing a subdivision of what kind of drinks you drank that day (pie chart)
- Viewing the current temperature in the fridge
- Viewing what drinks are currently in the fridge
- Viewing whether the fridge is locked or unlocked and being able to change that state.
- Viewing the history of all the recent measurements
Downloads
Supplies
Main computing unit:
- Raspberry Pi
This is the main controller of the system.
Fridge
- Klarnstein Beersafe XL Onyx drankenkoelkast
This is the fridge I used.
Electronics
- Barcode Scanner Module - 1D/2D Codes Reader
Barcode scanner
- DS18B20
Temperature sensor
- Lock-style Solenoid
Lock
- Grove buzzer
Indication when door is open.
- Mini Microschakelaar - SPDT
Check if door is open or closed.
- Raspberry PI T-cobbler
Breakout board for Raspberry Pi.
- RGB LCD 16x2 Display
Display.
- TIP120 Darlington Transistor
Transistor for solenoid.
- Potentiometer
To adjust the LCD contrast.
- 1N4007
Flyback diode.
- 1 kOhm weerstand
Series resistor for the transistor.
- Meanwell 25W - 12V / 2.1A RS2512
Solenoid power supply.
- POWER MODULE FOR BREADBOARDS 3.3V/5V
5V Power supply
- Premium Jumperwires op strip - 40 stuks - M/M - 20cm
M/M jumperwires
- Premium Jumperwires op strip - 40 stuks - M/F - 20cm
M/F jumperwires
Casing
- 2 metal plates
- 10 rivets
- A pack of M3 bolts and nuts
- 1 black pain spray can
- 4 rubber grommets
- double-sided tape
Prototyping
The first thing you have to do is to make the electric schematics. I have made an electric schematic and a breadboard schematic. Make sure to double-check whether everything is correctly wired. You don’t want your Raspberry Pi to explode. You will probably also have to solder a few components to be able to get it on your breadboard.
Preparing the Raspberry Pi
Next up you have to prepare your Raspberry Pi. The Raspberry Pi is a mini computer capable of running its own operating system. The whole project is driven by it. It is responsible for processing all the sensordata and running the webserver and the database.
1. Install custom Raspbian Image
You can download the custom image here.
Once you downloaded the custom image you will have to write it to your Raspberry Pi SD card. Once that's done you just simply plug it into your Raspberry Pi2
2. Connect to the Raspberry Pi
Open your SSH client and connect to 192.168.168.168. User: student with password: W8w00rd.
3. Expand the filesystem
Type 'sudo raspi-config' in the terminal. Go to 'advanced options' and then 'expand filesystem'. We do this so there is enough space on the system to be able to use visual studio code if you need to change some code.
4. Add your wifi network
Type 'wpa_passphrase 'yourssid' 'yourwifipassword' >> /etc/wpa_supplicant/wpa_supplicant.conf' in your terminal to add you wifi network. Then type 'wpa_cli -i wlan0 reconfigure' in your terminal to reload the Raspberry Pi network card. Try typing 'wget www.google.com' in your terminal to see if your wifi works. Otherwise just repeat the steps above.
5. Enable interfaces
Go back to raspi-config and enable 1-wire and serial.
6. Show frontend in Apache
Type in your terminal: 'sudo -i', '`nano /etc/apache2/sites-available/000-default.conf'. Go to the line where you find 'DocumentRoot /home/student/Code/Frontend' and change it to the path of your frontend. When that is done we restart Apache with 'service apache2 restart'. Now we just have to give the right rights to the root folder.
Type 'nano /etc/apache2/apache2.conf' in your terminal and search for the following lines:
Options FollowSymLinks
AllowOverride All
Require all denied
Change this to:
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
Then restart Apache with 'service apache2 restart'
7. Start service on boot
Make a file with the name 'myproject.service'
Add the following code to the file:
[Unit]
Description=Project
After=network.target
[Service]
ExecStart=/usr/bin/python3 -u /home/student//Code/Backend/app.py
WorkingDirectory=/home/student//Code/Backend/app.py
StandardOutput=inherit
StandardError=inherit
Restart=always
User=student
[Install]
WantedBy=multi-user.target
Type 'sudo cp myproject.service /etc/systemd/system/myproject.service'. Then type 'sudo systemctl enable myproject.service' to let it start automatically on boot.
Database
To log and store sensordata I have designed my own database. I first made the EER diagram that you can see here.
1. Devices
This table contains all my sensors and actuators. It describes the devicename and the measuring unit.
2. Actions
This table contains all the possible actions. Every id has a description with the action in it.
3. Products
This table contains all the possible products that can be scanned into the fridge. It described the name, category, barcode and quantity.
4. History
This table contains all the sensor logs. Each log has an id, deviceId, actionId, productId, data, value and a comment with the description.
Backend
If you haven't already, head over to my GitHub and clone/download the repository. Under the folder Backend you will find the full backend for the project. The main application is located under app.py. The files to communicate with the database are under /repositories.
Test the backend!
Make sure the backend doesn't make errors. When app.py runs correctly, stop the application and reboot the Raspberry Pi. Because you already made a service to run on start in step 2, the application will automatically start and if you tested the backend before rebooting, it will all run perfectly.
Frontend
If you downloaded all the folders from my GitHub, the frontend will run perfectly. The frontend already communicates with the backend. If you want to acces the website, type the IP address of the Raspberry Pi in your browser. You can see the IP address on the LCD display.
Note: The website is responsive, so you can use it on desktop aswell as on mobile. Although it works perfectly on mobile, I did originally make it for desktop so it's fair to say that it looks best on desktop.
Case
1. Bend the metal plates in the desired shape
First you will have to bend the plates in the desires shape. I bend it into the shapes you can see in the picture here. This way, I can still easily take off the lid of the case for maintenance.
2. Install the rivets
Then you will need to install the rivets. This way the lid doesn't slide off.
3. Cut the holes out of the metal
Then you will have to cut out some holes in the metal for your LCD, temperature sensor, barcode scanner and wires.
4. Spray paint everything
Then if you want the case to match the fridge better you can spray paint it in the color of the fridge.
5. Use the double-sided tape to install everything
Last, tape everything to the case so you have no loose components. Also, depending on the power supply you have, make sure the power supply is grounded to the case so you don't accidently electrocute yourself.