owned this note
owned this note
Published
Linked with GitHub
# Applied IoT Sangria pump
**By**: Elin Andersson Lundell
**Username**: ea225jp
## Project Description
This project aims to create a device that can be used during a “sittning” (a dinner often hosted by a university chapter). During this dinner, sangria needs to be dispensed to the five tables with thirsty, and above the age of 18, students. This device aims to dispense sangria with the help of a collision sensor, track how much sangria has been dispensed, and notify when the sangria needs to be refilled.
The time needed for this project is estimated to be around 25 hours, given that you have the same code resources that I had. The most time-consuming part of this project is connecting the hardware and configuring ADAFruit to showcase the correct data.
## Objective
I chose this project because I have been given the responsibility of fixing a sangria pump for one of my chapter's dinners. This is a yearly tradition and in the past, the pump has been made from very simple materials. My ambition was, however, to make an actual pump and not just a tube in a tank. The device will also allow us to keep track of how much alcohol has been consumed by the students, which can be good when determining if they should have any more.
By doing this project, you will learn how to use the Raspberry Pi Pico W to control devices with larger voltages by using a relay. This is something that can be useful in the future as it is somewhat restricting to only handle low voltage devices. After this project, you can, for example, create your own automatic fanning system for the hot summer days.
## Materials
The materials used for this project are:
- **Raspberry Pi Pico W**: The given microcontroller for this course. This will be used to control the device with code that we have written on the computer and uploaded to it. It has multiple pins which can, for example, be used for input or output. It also has an RP2040 microcontroller chip and can be connected using a USB to micro-USB cable. More specifications can be found here: [Raspberry Pi Pico Documentation](https://raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html)
- **Water pump**: I used a DC 12V pump that I found in my garage with a flow rate of 0.3 liters per second. See the picture for the exact product.
- **Collision detector IR**: Uses IR-LED and an IR-receiver to detect if an area is in the dark or in the light. It also has two dials that allow the sensitivity and detected distance to be adjusted.
- **Power supply for the water pump**: This was made by cutting up a random charger and exposing its positive and negative wires.
- **Power supply for the Raspberry Pi Pico W**: This was a micro-USB charger.
- **Relay 5v DC**: A relay that will control the pump’s power supply. This will act as a “switch” that allows the pump to turn on or off depending on the signals from the microcontroller.
- **Cables, male to male**
- **Cables, male to female**
- **Tank with known capacity**
- **Electric tape**: Used to secure the connections between the pump and the pump’s power supply.
- **Painters tape**
- **Plastic bags**
- **Jug**
- **Hose**
## Material Cost
This table shows how much each component costs. Keep in mind that I found materials in my house so the price is only an estimate. Additionally, not all materials are listed here, such as tape, as it often can be found at home. As for the pump, I used it because I had it at home and I recommend you to find one that is cheaper than the one listed here. This can be found on Amazon.
| Name | Cost (SEK) | Link |
|------------------------|------------|----------------------------------------------------------------------------------------|
| Raspberry Pi Pico W | 89 | [Electrokit](https://www.electrokit.com/raspberry-pi-pico-w) |
| Water pump | 400 | [IMNASA](https://www.imnasa.com/en/bilge-pumps/in-line-pump-280gph-12v-44250853) |
| Collision detector IR | 39 | [Electrokit](https://www.electrokit.com/kollisionssensor-ir) |
| Relay 5V | 99.90 | [Kjell & Company](https://www.kjell.com/se/produkter/el-verktyg/elektronik/utvecklingskit/arduino/moduler/luxorparts-relamodul-for-arduino-1x-p87032) |
| Breadboard | 69 | [Electrokit](https://www.electrokit.com/kopplingsdack-840-anslutningar) |
| Hose | 39 | |
| **Total** | **736** | |
## Computer Setup
I chose Visual Studio Code, commonly shortened to VS Code, as my IDE. To install it, please go to this link and follow the instructions for your system: [VS Code Installation](https://code.visualstudio.com/docs)
I used the PyMkr extension to flash (upload) the code to the microcontroller. To install it, navigate to the extensions panel in VS Code and search and install PyMkr. To flash the code, follow the following tutorial: [PyMkr Tutorial](https://hackmd.io/@lnu-iot/rkFw7gao_)
I followed this tutorial to set up the IDE. Do the same and follow the instructions for your operating system: [IDE Setup Tutorial](https://hackmd.io/@lnu-iot/rkiTJj8O9)
## Assembling / Putting It Together
To assemble the pump system, look at the picture below.

A thing that is important to note is that the negative wire from the pump is connected to the Normally Open terminal while the negative wire from the power supply is connected to the Common Terminal. To better understand how relays work, I recommend this video: [Relay Tutorial](https://www.youtube.com/watch?v=mj2kMD0LCR4)
This was, by far, the most irritating part of this project as the first relay module I bought was faulty. This led to me wasting several hours just trying to get the relay to switch. To get started, I recommend using the code here with just the relay to get familiar with it. If you bought a cheap relay of Amazon it's also a good way to test if it actually works before you try to do anything to advanced: [Relay Module Code](https://github.com/iot-lnu/pico-w/tree/main/sensor-examples/P28_Relay_Module)
## Platform
To showcase the data, I chose ADAFruit IO as it has good integration with Discord. As there will be multiple people working during the dinner when the pump is used, a Discord server is the easiest way of notifying the staff when the sangria needs to be refilled. ADAFruit allows you to create your own dashboard in order to show the data in a way that makes sense for your specific project. To get set up with ADAFruit IO, follow this tutorial: [ADAfruit IO Tutorial](https://hackmd.io/@lnu-iot/r1yEtcs55?utm_source=preview-mode&utm_medium=rec)
## The Code
The entire code for this project, except the file containing WiFi and ADAFruit credentials, can be found in this GitHub repository: [Mr.Sangriapump GitHub](https://github.com/chenniebenniebingbang/Mr.Sangriapump)
The main part of the code is the logic behind controlling the pump and registering input from the sensor. The code regarding ADAFruit setup and WiFi connection was found in the course GitHub and set up using these tutorials:
- [WiFi Setup](https://hackmd.io/@lnu-iot/rJVQizwUh)
- [ADAfruit Setup](https://hackmd.io/@lnu-iot/r1yEtcs55?utm_source=preview-mode&utm_medium=rec)
## Transmitting the Data
The data is transmitted using WiFi and MQTT. I did not need to think about power consumption as the device will be used during a short amount of time and will have access to constant power. One concern is that the WiFi at the chapter hall is somewhat unreliable. This is solved by letting the device connect to a hotspot hosted by my phone. The data is sent every 8 minutes. This interval was chosen as it should take some time to drink one jug of sangria and, therefore, the data does not need to be collected in smaller intervals. To send the message to the Discord server, Webhook was used as it allows ADAFruit and Discord to be connected.
This is how a warning message in Discord looks.

## Presenting the Data
This is the layout of the dashboard.

The graph shows the consumption of sangria throughout the evening while the value will show how much sangria it is estimated to be left in the tank. The pump status allows us to control if the pump is active or not to prevent people from using it freely. The start value lets us set a starting value which will update the sangria level. This can be used when refilling the tank.
## Final Design
Since the dinner is in August, I can’t show the completely finished product. Instead, here's a picture that is as close as I can get.

This is approximately how the device is supposed to sit on the container with the sangria. In August, however, the setup will be much prettier and safer.