Smart Keg System
I built a smart keg system for use in the hospitality industry or for myself at the theater when I help out at the bar. I came up with this idea during my Project One at Howest MCT in Kortrijk, Belgium.
This system measures the tank's volume, temperature, and pressure. The volume is calculated by converting the weight into liters of beer. There is also a cooling system (in this case, a DC motor) connected to a relay that activates when the temperature drops too low.
I thought it was a great idea, so I got right to work.
Note: Some code, file names, table names, etc. may be in Dutch. These terms are explained as they appear.
Supplies
All supplies used for this project are listed in the Bill of Materials.
BOM_SmartKeg.pdf
Everything is also listed below:
- Electronics
- Raspberry Pi 5 with T-cobbler
- HX711 module - weight sensor with load cells
- DS18B20 - Temperature Sensor
- Analog pressure transducer
- MCP3008 - AD Converter
- LCD display
- Optocoupler relay modules
- DC motor
- 3x Neopixel LED rings (5V, 24 bit)
- 5V 5A power supply
- 4x push buttons
- Mini Stainless Steel Beer Keg with Beer Dispenser Set (2L)
Note: I can't get the pressure sensor to fit onto this keg's tap system. You might need to look for a different one.
Downloads
Preparation
Install the Raspberry Pi Imager.
- Hier is de documentatie om een image te installeren op een SD-kaart
If you use this image, follow the steps below, or use a standard image.
Install using this custom image.
Zet de IP-instellingen van je computer op:
- IPv4-address: 192.168.168.169
- IPv4-mask: 255.255.255.0
Connect the Raspberry Pi to your computer using an Ethernet cable and establish an SSH connection using a tool of your choice. (PuTTY, terminal, Remote SSH on VSC)
When you start up for the first time, log in with:
- Username: student
- Password: P@ssw0rd
After logging in, you must first set a new password for the student user:
- Current password: P@ssw0rd
- Enter new password and confirm new password.
- Log in again with the new password
- Use `sudo raspi-config` to configure the system to boot to the desktop automatically and to enable auto-login to the desktop
- REBOOT the Pi. (This may take a few minutes.)
Create a project folder in /home/student if it is not already there.
For this project, you'll need to enable the 1-Wire, I2C, SPI0, and SPI1 interfaces. Run the following command:
Navigate to "Interfacing Options", select "1-Wire", "SPI" or "I2C" (you'll have to do all three anyway), and choose "Yes" to enable them. After making changes, select Finish and reboot your Raspberry Pi for the settings to take effect.
To enable SPI1:
- Open the terminal on your Raspberry Pi (or log in via SSH).
- Edit the configuration file:
- Add the SPI1 overlay. Scroll all the way to the bottom of the file and add the following line:
Note: “1cs” stands for “1 Chip Select.” The MCP3008 is connected to this chip select pin.
- Save the file and exit: In nano, you do this by pressing Ctrl + X, then Y to confirm, and then Enter.
- Restart your Raspberry Pi so that the changes take effect:
UI Design
<<Coming up: screenshots of the user interface>>
Here are some screenshots of my UI. Wanna see the design file: check this Figma link.
I chose a golden yellow color (color of beer) along with the Inter font. All my icons are from the Material Design icons set. You can customize the step-by-step guide for setting up a new barrel at `nieuw_vat.html` with your own photos and instructions based on your custom keg system.
Note: When you start coding, you can customize the website's styling (style.css) as you see fit, but keep in mind that modifying an HTML file may cause the JavaScript to stop working.
Database
Here is an example of my database in MySQL Workbench as an ERD diagram and the tables. I also drew it in Draw.io. Below is an explanation of the database:
tbldevices
This table lists all sensors and actuators, enkel voor de sensoren samen met hun meeteenheid. The history entries will then include information about which device is involved.
tblvaten
This table lists all your kegs, and the most recently created keg is always linked to the most recent historical data.
tblconfig
Here are all your configurations:
- Alarm threshold for when there is too little beer in the keg.
- Alarm threshold for when the temperature is too high.
- Alarm threshold for when the pressure is too low.
- Tare weight of your keg (subtracted from the gross weight on the scale).
tblhistoriek
Ultimately, all historical data ends up here as a value, linked to the keg and the correct device.
Electronic Circuit
Here is the circuit design, available as both a breadboard layout and an electronic schematic.
The LED rings and the relay with DC motor are connected to a separate 5V 5A power supply.
The relay is controlled by a transistor, and the relay controls the motor.
The LED rings are connected in series and use the SPI0 MOSI (GPIO 10).
The LCD display is connected to a PCF8574 (I/O expander for the I2C bus) to save GPIO pins. As a result, they use the I2C protocol.
The load cells are connected to the HX711 module as shown in the diagram: black wires to black and white wires to white, so that the load cells form a loop; the red wires are then connected to the HX711 in a specific order (as shown in the diagram).
Note: If you connect the red wires incorrectly, you may end up measuring completely incorrect values or negative values.
The pressure transducer is connected to the MCP3008 (AD converter). The MCP3008 is connected to the SPI1 bus that we enabled in Step 1.
The DS18B20 (temperature sensor) uses the 1-Wire protocol. It comes with a physical pull-up resistor connected to GPIO 4 (1-Wire).
There are 4 push buttons to shut down the Pi, stop the measurements, tare the weight sensor, and restart the measurements.
Has a protocol not yet been activated? (1-Wire, I2C, SPI0, SPI1): See “Step 1: Preparation”
Enclosure
<<Coming up: photos of the empty case and photos of me making it>>
I built a cabinet to house this project. The barrel will sit on the scale inside the cabinet. The top of the cabinet is a compartment for all the electronics.
I built the cabinet simply out of wood. I cut the wood to size, and after that, it’s easy to drill holes to put cables, buttons, etc., through.
I also 3D-printed 2 things:
- 4x Load cell holders made by yeedoo on makerworld.com
- 3x Holder for 24 x NeoPixel LED Ring on printables.com
I made labels to attach to the buttons and LED rings to clarify what they mean.
Code: Backend
I'll explain all the files from the backend here. These files already work, so they don't need to be modified a lot.
folder: /backend
app.py
This is the main file. This is where everything related to GPIO and hardware, the API, and the WebSocket runs in separate threads.
You will also need to calculate and enter the calibration factor for the HX711 yourself.
Set your calibration_factor to 1.
Place an object with a precisely known weight on the scale and divide the raw measurement displayed by the script by that weight. This calculated value is your final calibration factor.
config_example.py
This file contains the configuration settings for connecting to your database. You must fill out this file YOURSELF and rename it to “config.py”.
/repositories/Database.py
/repositories/DataRepository
These files enable the backend to send queries to the database; SQL statements are passed as parameters to methods in DataRepository.py. These SQL statements are processed in Database.py.
/models/hx711.py
HX711 library from tatobari on GitHub. Using this library, I wrote my own class for the HX711.
/models/models_sens.py
In deze file staan al mijn klasses voor mijn sensoren en actuatoren.
/models/models_api.py
In deze file staan al mijn klasses voor de API.
Code: Frontend
I'll explain all the files from the frontend here. These files already work, so they don't need to be modified a lot.
folder: /front
index.html
This is the homepage.
It shows the live sensor data and updating graphs.
historiek.html
On this page you can look up the sensordata of past kegs.
config.html
Here, you can modify all configurations in the database (tblconfig) or shut down the system.
nieuw_vat.html
Here is a step-by-step guide for creating a new barrel and adding it to the database.
style/style.css
This is the styling. You may make changes here however you like.
Everything has been styled as shown in “Step 2: UI Design”.
script/app.js
1 script to make all pages work with the backend.
images/svg/*
All icons as SVG are in this folder
images/img/*
All other images are in this folder.