# Mead Maker
### Jacob Mårtensson – jm223fj
## Overview
This is a project which helps to make sure that your brewing experience goes as planned while you cannot attend to it constantly. It uses three different parameters to make sure of this. These being Temperature, moisture in the air and a liquid sensor to make sure that nothing is leaking.
The setup time for this project is roughly an hour.
## Objective
This project was chosen as I am currently brewing mead. I cannot always be home to make sure that everything is going as planned so I wanted to be able to check on it from a distance. The two most important parameters are the temperature and the liquid sensor. If the temperature is too high or too low the yeast may die and if the liquid sensor is reacting there is leakage occurring which could be bad. The moisture in the air can make the flavor less appealing. With the temperature sensor, it can also give data for a longer duration making it easier to conclude if the mead needs to be moved or if it needs immediate attention. This will be a good first experience with IoT as it is a simple device which serves a for me a critical task. It will most likely give me insight on how one start creating a device which is able to relay information through the net.
## Material
In this project, a Pycom LoPy4 was used as it has an extensive amount of connections for digital and analogue inputs while still having several bands of connectivity this combined with being able to use MicroPython which is a language which is easy to program for makes it a suitable device for this smaller project. For this project, several components were used. These were the lopy4 device with an expansion board, a breadboard, several cables and two different sensors. The two sensors were a DHT11 Digital Temperature Humidity Sensor Module for Arduino and Luxorparts Water/Liquid Sensor. The Temperature sensor can sense temperatures between 0-50 C with a +/- 2 accuracy while the water sensor is a simple sensor which uses an analogue signal to determine how much liquid is present on the sensor. To extend the Liquid sensor from the BreadBoard female to male cables were used.
 *Figure 1. DHT11*
 *Figure 2. Luxorparts Water/Liquid Sensor*
| Name | Price | Store | Bundle |
| --------------------- | -------- | --------------- | ------ |
| LoPy4 | 995,00:- | Electrokit | Yes |
| Expansion board | 995,00:- | Electrokit | Yes |
| BreadBoard | 995,00:- | Electrokit | Yes |
| Cables | 995,00:- | Electrokit | Yes |
| DHT11 | 99,90:- | Kjell & Company | No |
| Water Sensor | 49,90:- | Kjell & Company | No |
| Cables female to male | 74,90:- | Kjell & Company | No |
## Computer setup
The chosen IDE for this project was ATOM with the plugin Pymakr Atom Package. To be able to use the Pycom properly some setup is required. The first step should be to update the expansion board to the Lop4. I did this on a Linux device as it is far easier in my opinion. If you are using a Windows machine you can follow these instructions ( https://docs.pycom.io/pytrackpysense/installation/firmware/). For Linux, you need to do three things. First, check which version of the board you have and download the correct version. Second install DFU – Util Tools. This can be done by writing “`$ sudo apt-get install dfu-util`” in the terminal. This can vary depending on what kind of installer you have on Linux. The third step is opening the folder which you saved the latest firmware and running this command in the terminal “`$ dfu-util -D file_version.dfu`”. There `file_version.dfu` is the file you downloaded.
Create an account on Pybytes and create a new project with the network configuration of WiFi. Connect it to your WiFi then asked so. After this press the “ADD VIA USB” button on the Project menu and select the LOPY4. Select Wifi again and choose a fitting name. After this, you should get a Long string called “Activate your device with Firmware updater”. Save this string as it will be used in the firmware updater.
To update a device Firmware I a windows system, but alternative installations steps can be found at (https://docs.pycom.io/gettingstarted/installation/firmwaretool/). Start with downloading the firmware upgrade program and installing it. Make sure that your device is not connected to the computer and make sure that it is connected to the expansion board. Reconnect the expansion board to the computer, run the program and make sure that no IDE is running. In the program select the port which the Pybyte is connected to, show advance setting, the type should be pybytes and Force update Pybytes registration. The press continues and then prompted paste in the string into the box. When the advance settings come up to make sure that the device type is a LoPy 4, the correct version of Pybytes is being installed and that the box for “Erase during update” is selected. After this, you should be able to see on the Pybytes website if you manage to install it.
In Atom after installing the Pymaker plugin you can then create a project folder. This project folder can then be uploaded to the connected device. To use it a main.py file is required and potentially a lib folder for any nonstandard libraries. To be able to upload anything to the device it needs to be connected through a USB cable. You can check if it is connected by pressing the “Get device info” button in the plugin.
## Putting everything together

*Figure 3. Pycom With expansion board from [Pycom.io](https://docs.pycom.io/gettingstarted/connection/lopy4/). Breadbord from [TinkerCad](https://www.tinkercad.com).*
This is a simple Digram describing how it is setup. The Red wires indicate power, the black wires are ground and the yellow are data. If the names of the pin slots don't match exactly others can be used. It is important for the water sensor that it is given a slot which supports analogue inputs.
## Platform
The platform chosen for this project was Pycoms own platform called Pybytes. It is a cloud-based platform which is free to use and covers most of the needs for this project. It is easy to manage and get a good overview of the device is connected and can easily implement other features with the help of its online editor. It is also easy to add new devices if so is required. This combined with a built-in and easy to use dashboard made it a good option of the platform. There are options to add different signals for the dashboard so if it was chosen this could be added to several of the same devices if you were brewing many things at the same time. It has some limitations though as it still is early in development. Features such as more advanced Notifications are not yet implemented and the online editor Pymaker online is not always working as it is intended.
## Code
```python=
############################## Libary and Import
import time
from dht import DHT
from machine import Pin
import machine
import pycom
############################## Setup
th = DHT(Pin('P23', mode=Pin.OPEN_DRAIN), 0) ### Create the connection between the pins and the DHT11 sensor
time.sleep(2)
print('Starting')
adc = machine.ADC() # create an ADC object
apin = adc.channel(pin='P13') # create an analog pin on P13. This is needed for the water sensor
############################## Main Loop
while True:
result = th.read()
while not result.is_valid(): #See if the data from the sensor is valid. Otherwise wait and try again later
time.sleep(.5)
result = th.read()
if apin() > 0: # We only need to know if it is wet. If it is send a 1 otherwise send 0
val = 1
else:
val = 0
print('Temp:', result.temperature) # Print out the values in terminal
print('RH:', result.humidity)
print('Wet:',val)
pybytes.send_signal(0,val) # Send the signal with the values to the Pybytes platform
pybytes.send_signal(1,result.temperature)
pybytes.send_signal(2,result.humidity)
time.sleep(120) # Wait for 2 mins before running the loop once again
```
The only libary I used was the DHT libary which can be found at the link: https://github.com/iot-lnu/applied-iot-20/blob/master/sensor-examples/DHT11-22/lib/dht.py
## Transmitting the data/connectivity
The data is sent over WiFi from the Pycom device to the Pybytes platform. This connection is created during the setup device and each time the device is started it will connect to the WiFi. WiFi was chosen as it will only be used in my home their connection won’t be an issue and an outlet is closed by making it easy to feed the Pycom with energy from the USB port. The settings which the device checks on can be found in a JSON file called pybytes_config.json. Pybytes uses by default the MQTT transport protocol which is the one I picked. The data is sent once every two minutes. This time was chosen as the difference in room temperature takes a while to increase and decrease. The liquid sensor will also check every two minutes as if there is a leakage it should only be a small leakage. If not the leakage was most likely too big to do anything to fix.
## Presenting the data
The data is represented by using several bar graphs to indicate the change in temperature through Pymaker. Only the last 200 instances are shown which makes it will go through all the data in 400 min or 6 hours and 40 minutes. These slices were chosen as anything bigger than that made it hard to see sudden changes. The data is saved each time a signal is received. How the data is stored is not well defined on the Pybytes platform. *Figure 4. Data representation of Wetness, Temperature and Humidity.*
## Finalizing the design
I think the project wen well overall, but if I could change something about, I would have changed away from the platform Pybytes. It is simple to get going and display the data, but you can barely customize anything which makes it not ideal. It can send some notification through an app if something is happening, but only certain things such it are running out of battery and similar. So that would be the first thing I would change. This would also help if I would like to try another transport protocol. Though functionalities such as measuring temperature and liquid I am pleased with. If I would have a 3D printer, I would make a case for it and secure the cables ever so slightly. I don’t think the choice of working WiFI was bad overall as it will only be used inside my house.
 *Figure 5. End result*