# Guided Breathing Station for Stress Management - Tutorial **By:** Maya Kubajima Mattsson (mk226ce) ## Project Description This project aims to build a device that guides a user through a breathing exercise to lower stress levels. It will work like this: 1. The stressed user places their finger on the temperature sensor to confirm contact. 2. The user then knocks on the knock sensor to start the breathing guide. 3. A buzzer will make an initial sound and an LED will start blinking blue to guide trough the breathing exercise. Meanwhile, the temperature sensor will continously measure temperature to ensure the user is still there. If the finger is removed, the exercise will pause and the device notifies this through buzzer sound, or stop entirely after 10 seconds of inactivity. 4. The LED will be lit green and the buzzer will make another sound to indicate the breathing guide is done. The chosen breathing exercise for this was the 4-7-8 exercise, where your breathe in for 4 seconds, hold for 7 seconds and breathe out for 8 seconds. The time needed to make this project is estimated to be approximately 5-10 hours, depending on former experience and luck :). ## Objective Student health is something that is becoming increasingly an issue in our society since stress and mental health problems seems to be increasing in students. It is something that I care a lot about and stress is definitely something I have encountered a lot during my years in school and now university. This project can be a way for stressed students to manage their stress better by performing breathing exercises, which is a known and used method to manage stress. With this project it will provide insight in how to build an IoT device by using different types of components and learning how to connect everything and collect and present data. It might also provide insight in how to do future and more improved, or large scale devices regarding stress management. ## List of Materials | Material | Description/Use | Where I bought them | Price | | --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ---------- | | ***Raspberry Pi Pico WH*** | The main component that is mandatory for this course. This is a microcontroller, needed to upload and run the written code that controls the device. | Electrokit | 99 SEK | | ***Breadboard*** | Used to be able to connect the Raspberry Pi Pico with the sensors and other components. | Electrokit | 69 SEK | | ***Male-to-Male Jumper Wires*** | Is used to connect sensors to the Pico and the Pico to ground and power. | Already owned, but can also be found at Electrokit | -/52 SEK | | ***Female-to-Male Jumper Wires*** | Is used to connect sensor to the pico. | Electrokit | 49 SEK | | ***DS18B20 Temperature Sensor*** | Consists of a DS18B20 single-bus digital temperature sensor, a LED and a resistor. Is used to measure body temperature of the user. | Electrokit (art nr: 41015731) | 42 SEK | | ***Knock sensor*** | Has a switch with two terminals that are shorted together when sufficient force is transferred onto it. Is used to start the breathing guide. | Electrokit (art nr: 41015735) | 39 SEK | | ***Active Piezo (buzzer)*** | Buzzer that produces a single-tone sound when signal is high. Is used to indicate when breathing exercise is beginning, ending and if paused or aborted. | Electrokit (art nr: 41015713) | 32 SEK | | ***Resistors (330 Ω) x3*** | Is used for the RGB LED | Electrokit (art nr: 41023160) | 1 SEK | | ***RBG LED*** | This RBG LED is common anode and is used to either signal that the user is calm by being lit green or start the breathing guide by blinking blue and turning off in a sequence. | Already owned, but a variant can also be found at Electrokit (art nr: 40307100) | -/6.50 SEK | | ***Foam sponge*** | This is used to place the temperature sensor in a more practical and stable place. | Electrokit (this was the sponge attached to the Pico) | - | | ***Tape*** | Is used to tape the sensor to the foam. | Already owned | - | | **Total cost:**| | | 389.5 SEK I bought the start kit (349 SEK) and the sensor kit (299 SEK) from Electrokit, and used things already at home to make this device, but the components should be available to buy separately if needed. ## Computer Setup In this project, I chose to use Visual Studio Code (or VS Code) as my IDE with the extension Pymakr to be able to use MicroPython. To install Visual Studio Code and Pymakr, you can follow this tutorial: [Installing VS Code IDE Tutorial](https://hackmd.io/@lnu-iot/rkiTJj8O9) ## Putting everything together These are the main steps to follow to do this project: - Install IDE (and extension), more on that is in the section above. - Install firmware on Pico, to do that follow this tutorial: [Raspberry Pi Pico Firmware Tutorial](https://hackmd.io/@lnu-iot/rkFw7gao_) - Build the device on the breadboard - Set up Wi-Fi - Send and display data ### Build the device This is a hand-drawn circuit diagram:![1000001503](https://hackmd.io/_uploads/Hy0E5FnBxx.jpg) ### Explanation 1. Press the Raspberry Pi Pico into on of the breadboard ends so that the micro-USB port is turned outwards. 2. Connect one cable to GND (for example pin 38) and one cable to power (3V3(OUT)), or pin 36. A tip: use a black cable for GND and a red one for power, or at the very least two distinct colors for each. 3. Connect the RGB LED according to your version. In my case, it meant connecting the slightly longer leg to power and the three other legs to pins on the Pico (GP18-20) via resistors (!). I used resistors with 330 ohm. Tip: if you do not know which resistance a resistor has, you can look at the coloring, since the different bands of color mean different things. 4. Connect the temperature sensor DS18B20 correctly. For my component that meant connecting the S-side (signal side) to the Pico, the middle to power and the left side to ground. I connected it to the GP26 on the Pico. 5. Connect the active piezo/buzzer correctly. For my component that meant connecting the S-side to the Pico (I chose GP2) and the left side to ground. A picture of the pin out diagram: ![Skärmbild 2025-07-10 013729](https://hackmd.io/_uploads/BkFPpOhrgg.png) Here are some electrical calculations on the resistors to ensure that the resistance is enough: This is an example with red LED: $R = {3.3 - 2.0 \over 0.015}= {1.3 \over 0.015} \approx 87 \ \Omega$ I used generalized values for the LED since the one I had, I had no true specifications for. You generally don't want to go over 20 mA for LEDs, so I chose 15 mA and 3.3V since that is what the Pico has from my understanding. Since the closest I had to that was 330 $\Omega$, that is what I used and hoped that it wouldn't dim the lights to much, which they did not do in the end. A tip is to remember that in the micropython code you should refer the pin number to the GP-number and not confuse it with the "actual" pin number 1-40. ### Set up Wi-Fi To set up Wi-Fi I used this guide: [Using Wi-Fi](https://hackmd.io/@lnu-iot/rJVQizwUh). I also used the code from this [GitHub](https://github.com/iot-lnu/pico-w/tree/main/network-examples/N1_WiFi_Connection). This was not very difficult, but do remember to not share any file that holds your Wi-Fi information like your SSID or password. ### Send and display data For this, I used this guide: [Introduction to TIG-stacks](https://hackmd.io/@lnu-iot/BkwDAimvn). My biggest tip for this part is to truly go through the config-files and make sure your IP-address is in the relevant places like the Telegraf-config and when you create you MQTT client in your code. Also, make sure that you allow for the right data types in your Telegraf config, that is something that I missed and it was a bit troubling to troubleshoot. Another tip if the syntax for Flux, or similar, is a bit tricky is to play around with it in InfluxDB (not in Grafana) and then converting it to script and copy-paste in into the query in Grafana. Of course, do not forget to docker-compose down and docker-compose up -d whenever you have changed in your config-files. ## Platform To collect, store, and display data from the Raspberry Pi Pico, I used a TIG (Telegraf, InfluxDB, Grafana) stack through the transport protocol MQTT (Mosquitto). The platform is run through Docker Compose installed on a local computer running on Windows OS. This means that the system is self-hosted and therefore works without an Internet connection as long as the network is active. ### Functionality of TIG-stack This is how it works: - **Mosquitto** handles real-time communication through MQTT - **Telegraf** acts as a middle-hand and subscribes on MQTT messages - **InfluxDB** stores all the measurement data as time series - **Grafana** displays the data in a dashboard in real-time This enables real-time monitoring of temperature and breathing exercise status, visualisation of events (starting, pausing, ending, aborting etc.), and easy data export if you want to analyze for a longer time period. The main reason I chose this platform was for the complexity and the possibility to learn more. Other reasons include the fact that you gain full control of all the data transmitted which is good from an integrity perspective. The platform is also quite flexible once set up and you can design your dashboard to your liking. Another reason I chose this was because it is free. I considered trying to implement Adafruit IO as well, but due to a lack of time I chose to only implement one solution. It would have been interesting to learn both and compare, and I might do that in the future. For scalability you could implement a way to have access to the dashboard on mobile, and you could also move to a managed IoT platform like Azure IoT Hub or Google Cloud IoT. You could also use a cloud server instead of a local installation, where the TIG-stack is run around the clock. ## The Code The code for this project can be found on GitHub: [IoT ST2025 Project Code](https://github.com/mayakm/IoT-ST25) ## Connectivity The data is transmitted at intervals of approximately 2 seconds for live temperature monitoring and event-driven messages for state changes (exercise started, paused, resume etc.). This project used Wi-Fi as the wireless protocol, connecting to the local WLAN network. This means that it used Wi-Fi as wireless communication between the device and the server. As mentioned earlier though, all data transmission is done in a local network without the need for an Internet connection. This is possible because the MQTT-broker (Mosquitto), the database (InfluxDB) and the dashboard (on Grafana) are run on the same Wi-Fi network as the device. Thus, though both Grafana and InfluxDB are are used through a web browser, data collection, storage and visualisation can all be done without Internet, as long as all the devices all are on the same local network. As mentioned earlier, the chosen transport protocol was MQTT. This was a pretty natural choice since it was included in the [tutorial on TIG-stacks](https://hackmd.io/@lnu-iot/BkwDAimvn). Wi-Fi was chosen mostly for its simplicity and compatability with the local network, providing suffiecent range for indoor use, which is appropriate for this project. If the device would have been battery-powered LoRa might have been considered for its long range and low power, but it was not applicable here. From a security standpoint, MQTT has the advantage of supporting username/password authentication and also Wi-Fi is secured via WPA2. Since the data sent is not of an extremely sensitive character, this security should be sufficient. ## Data Presentation The database of choice is naturally InfluxDB since it is a part of the chosen platform TIG-stack. InfluxDB is optimized for time-series data, allowing for efficient data storage, and visualization of continuous measurements. Data is stored each time a MQTT message is published, resulting in approximately one record every 2 seconds for temperature and additional records for event changes. Automation is implemented through Grafana's live dashboard updates and potential alert triggers based on thresholds (triggered from removing the hand). No additional automation was implemented beyond visualization and logging. Here is an example of what the dashboard looks like: ![dashboardIoT](https://hackmd.io/_uploads/r1xRgu3Hxx.png) ## Final Design Here is a picture of the final project: ![20250710_005644 (1)](https://hackmd.io/_uploads/SJ5oN_3Bxe.jpg) I think that the project went okay, but there are definitely improvements that can be made. I did in general not have much difficulty assembling the device on the breadboard, probably because of prior experience. The thing I found the trickiest about this part is the RGB LED since it was a random thing I found at home and did not know if it was common anode or common cathode (and I did not even know what that was before this project). I also usually try to avoid using resistors when I can, so not being able to do that this time was a little scary since I did not want to hurt any component. One thing that I struggled with was the buzzer for some reason. If I would have had the time, I would probably tinker more on it to get it to work better, or change to the other buzzer I owned. That would also have the benefit of being able to customize the actual sounds a bit, since that is what the passive buzzer enables. Another thing I would change is to not use the knock sensor and instead just use a common button. It was difficult and annoying trying to make the knock sensor actually sense my knocks and it would have been so much easier and comfortable with a button. In general, this was not the most comfortable design and if I were to actually make this at a larger scale or in a more "real" project I would probably invest in designing the device a bit more so that you could easily place your finger somewhere (on the temperature sensor) without having to hold it or be worried about reliability too much because of how you might be holding it. The last thing that was the trickiest was probably the TIG-stack and more specifically troubleshooting when data did not show up correctly. It was difficult to know if it was a connectivity issue, a config-issue or a syntax issue in Flux, since that is a language I have not worked with at all. I am not sure if this is a project suited for "the real world" but if I wanted to build upon this I would definitely make sure to tinker with the sound effects since I think those are important for the experience of actually feeling like a device for a breathing guide. It is also a bit precise since you want to have different sounds for different states, and also have it be calming enough not to further stress. I would also probably try to figure out how the heartbeat sensor works, which was my original project idea, to be able to monitor stress levels in the first place so you could automatically start the breathing guide if stress is detected. This however, proved to be quite difficult with the cheap heartbeat sensor I own.