# IoT device measuring beer left in a keg *Made by* Albin Lidbäck, AL225SW 2021-07-29 ## Introduction In this tutorial you will follow the steps of making a IoT device that measures the level of beer left in a keg and the temperature of the fridge it's stored in. The data from the device is uploaded to Ubidots to make it able to monotor from anywhere. Possible improvments and difrent solutions is presented at the end. The estimated time reqierd for following this tutorial is 2-6 hours. Depending on how familiar you are working whit python and electronics. ## Objective The purpose of this project is to be able to monitor the amount of beer that is left in my keg. Sins I brew my own beer and the fermenting process takes a cople of weeks it's nice to know when to start the next batch. The device measures the wight of the keg and converts the wight to an approximation of how many litres that's left. As a bonus the temperature of the fridge is measured aswell to make sure the beer is nice and cold:wink: Hopefully this project will show me how easy it's to build your own IoT devices for everyday purposes. And build a solid ground to make more interesting projects from. ## Material | Name | **Store** | **Price** | |:----------------------------- |:--------------------------------------------------------------------------------------------- | ----------------:| | LoPy4 and Expansion Board 3.0 | [Pycom](https://pycom.io/product/lopy4/) | ~580 kr | | Battery | [Electrokit](https://www.electrokit.com/produkt/batteri-lipo-3-7v-4400mah/) | 249 kr | | HX711 amplifier | [Electrokit](https://www.electrokit.com/produkt/hx711-lastcellsforstarkare-monterad-pa-kort/) | 36 kr | | Weight cell | [Electrokit](https://www.electrokit.com/produkt/lastcell-50kg/) | 99 kr | | DHT11 | [Electrokit](https://www.electrokit.com/produkt/digital-temperatur-och-fuktsensor-dht11/) | 36 kr | | Breadboard, wires and resistors | | ~50 kr | | | | **Total 1050 kr** | ![](https://i.imgur.com/YWwqIAf.jpg) ### LoPy4, Expansion board and battery The **LoPy4** and **Expansion Board 3.0** is a MicroPython controlled development board. It uses the ESP32 chip in order to work and is compatible with multiple network protocols, Bluetooth, WiFi, LoRa and Sigfox. The **battery** is used to make the LoPy remote and abel to operate without a voltage source. ### HX711 amplifier and weight cell The **HX711** chip is used to convert and amplifier the data from the **weight cell** to a digital output. This makes it easier to use sins you don't have to voltage masuers whit the LoPy board. ### DHT11 The **DHT11** is a simple termometer and humidity sensor. It's mounted at board to make it digital which makes it easyer to read and store the data. This sensor is not necessarily neaded for the project. It just serves as a fun feather. ### Breadboard, wires and resistors The **Breadboard, wires and resistors** are pretty self explanatory. The breadboard and wires are used to wire up the different sensors and devices to their specifications. The resistors are used as a Wheatstone bridge together with the weight cell to make the **HX711** work. ## Computer setup In this project I’m using [Visual Studio](https://code.visualstudio.com/) whit the [Pymakr](https://marketplace.visualstudio.com/items?itemName=pycom.Pymakr) plugin installed (the plugin is needed to do the communication whit the LoPy). The communication is don using USB witch runs really smooth and I have not run into some issues either with the IDE or plugin. Just make sure to instal Node.js on your computer if you are using windows. [Hear](https://docs.pycom.io/gettingstarted/software/vscode/) is a full guid on how to set up the IDE. When you get a new Pycom device it's recommended that you update the firmware bout on the LoPy4 and Expansion Board. Pycom (witch makes the boards) have a good tutorial on how to do this: - [Updating the device firmware](https://docs.pycom.io/updatefirmware/device/) - [Updating the expansion boards firmware](https://docs.pycom.io/gettingstarted/software/drivers/) It is not necessary to update the expansion boards firmware. I didn’t do it in it turned out great. But if you bump into some issues it might be good to have in the back of yore head that updating might solve the problem. Updating the LoPy was really easy it's just to follow the guid and you’re good to go. ## Putting everything together Al the components are hooked up ass seen in the diagram below. Sins I only use one wight cell I have built a whetstone bridge whit two resistors. Be careful when hoking them up sins they easily can be weird wrong. ![](https://i.imgur.com/RsAvhca.jpg) ## Platform I use Ubidots which takes cear of all the transitions. It's easy to use and free. A bonus is that you can use their example code to include in you’re projects. That makes it not needed to send data to Pybytes or any other service. You can instantly publish to Ubidots. ## The code [The code I wrote for this project is available at GitHub.](https://github.com/AlbinLidback/Beer_Left) The code is structure as seen below. You will not find the credentials file in the GitHub repository sins they contain passwords and other credentials. ``` Beer_Left ┣ lib ┃ ┣ dht.py ┃ ┣ hx711.py ┃ ┗ urequests.py ┣ boot.py ┣ credentials.py ┗ main.py ``` ### Libraries - [dht.py](https://github.com/JurassicPork/DHT_PyCom) - [hx711.py](https://github.com/robert-hh/hx711) ## Transmitting the data / connectivity To view the data I use Ubidots. It's simple to use and provides a library for sending data to their cloud service. The data is sent in intervals of approximately 30 minutes. Sins my fridge is in the apartment I use WiFi to connect to Ubidots MQTT server. Therefore I don't have to worry about getting a subscription to LoRa or Sigfox. ## Presenting the data I use Ubidots to display the data. It has worked realy nice. And a bonus is that it's free. The data is displayed as in the picture below. ![](https://i.imgur.com/92dInyk.jpg) I have let the amount of beer left take up much space and placed a time diagram over the consumption. As a bonus the temperature and humidity can be viewed as well. The data is updated and saved every 30 minutes whit the transmit from the LoPy. ## Finalizing the design The result is this box below. Unfortunately is my keg at my parents getting refeild. But when it's back it will be placed on top of the weight cell. You can see the LoPy and wiring and al that other stuff in the box. ![](https://i.imgur.com/lQvrb4b.jpg) The data is logged at Ubidots where I have made this page on witch al info can be viewed. ![](https://i.imgur.com/92dInyk.jpg) A lot of improvements can be made although. Example could it be nice to have a display at the fridge showing the amount of beer left. An alarm if the temperature is getting high. But over al am I happy whit the project. I have learned that it is easy to make these small things home witout bying something from the shelf.