Heartrate Monitor RaspberryPI Website

by WarreSnaet in Circuits > Raspberry Pi

33 Views, 0 Favorites, 0 Comments

Heartrate Monitor RaspberryPI Website

finished.jpg

An advanced heart rate monitor specifically designed for sports enthusiasts who want to track their heart rate while exercising. We all know how important it is to stay within your physical limits, and this app helps you do just that. It not only measures your heart rate in real time, but also lets you know when you are going too fast by a rumble motor that will vibrate and a buzzer that will make a sound. when the heart rate is too high. Perfect for anyone who wants to stay healthy while working on their fitness. The idea will be that you can put this on around your chest with some kind of a soft piece of ribbon.

It's not just about heart rate. The app also provides insight into other important health aspects, such as ambient temperature and CO2 levels, which can tell you something about the quality of the air you're exercising in. Additionally, it checks how well the blood is transporting oxygen by measuring oxygen saturation.

Setup RaspberryPI

RaspberryPiconnected.jpg

Before you power on the raspberryPi, you would want to insert your sd card into the back of your raspberryPI. After that you want to have your Laptop and raspberry connected with an ethernetcable. This way you will be able to setup a connection to write code on your raspberryPI.


Now you can plug in your official RaspberryPi cable in your raspberryPI to power it on.


You want to follow these instructions to have the right configuration of your raspberryPI


Configuration Instructions

  1. WiFi Setup on the Pi for Home:
  • Gain administrator rights: sudo -i
  • Configure WiFi: wpa_passphrase <your_SSID@Home> <your_wifi-password> >> /etc/wpa_supplicant/wpa_supplicant.conf
  • Replace <your_SSID@Home> with your home network name and <your_wifi-password> with the corresponding password.
  • Reload wireless network: wpa_cli -i wlan0 reconfigure
  • Test internet connection: wget www.google.com
  1. System Update and Upgrade:
  • Check available updates: apt update
  • Install available updates: apt upgrade
  • Confirm with Y if prompted.
  • Wait for updates to complete.
  1. Install rpi-lgpio Library:
  • Remove the default RPi.GPIO library: apt remove python3-rpi.gpio -y
  • Install the new RPi-lgpio library: apt install python3-rpi-lgpio -y
  • Ensure the old RPi.GPIO library is not installed via pip:
  • Uninstall libraries: pip3 uninstall rpi-lgpio RPi.GPIO
  • Install the new library: pip3 install rpi-lgpio
  1. Install Apache:
  • Install Apache web server: apt install apache2 -y
  • Adjust permissions for the project directory:
  • sudo chmod o+x /home/user
  • sudo chmod o+x /home/user/"name repo"
  • sudo chmod o+x /home/user/"name repo"/front
  1. MariaDB Setup:
  • Install MariaDB: apt install mariadb-server mariadb-client -y
  • Secure MariaDB installation: mysql_secure_installation
  • Press Enter for current root password.
  • Set a new root password.
  • Remove anonymous users: y
  • Disallow root login remotely: y
  • Remove test database: y
  • Reload privilege tables: y
  • Create MariaDB user:
  • Access MariaDB server: mysql -u root -p
  • Create a new user: grant all on *.* to 'dbuser'@'localhost' identified by 'P@ssw0rd'; grant grant option on *.* to 'dbuser'@'localhost';
  • Reload privileges: flush privileges
  • Exit MariaDB: exit
  1. Configure MySQL Workbench:
  • Start MySQL Workbench on your laptop.
  • Create a new connection:
  • Connection Method: Standard TCP/IP over SSH
  • SSH Hostname: 192.168.168.169
  • SSH Username: user
  • SSH Password: P@ssw0rd
  • MySQL Hostname: 127.0.0.1
  • MySQL Server Port: 3306
  • Username: dbuser
  • Password: P@ssw0rd
  1. Configure Visual Studio:
  • Open Visual Studio.
  • Install the Remote-SSH extension.
  • Press F1 and type SSH.
  • Select Remote-SSH: Add New SSH Host.
  • Enter ssh user@192.168.168.169 -A.
  • Save the configuration.
  • Connect to the host via SSH.
  • Enter the password: P@ssw0rd.
  1. Clone GitHub Repository:
  • In Visual Studio Code, go to Source Control and select Clone Repository.
  • The repositorylink: https://github.com/SnaetWarre/ProjectOneDownload
  1. Setup Project Environment:
  • Create a new virtual environment:
  • For Windows: py -m venv venv
  • For Mac: python3 -m venv venv
  • Install required packages:
  • For Windows: pip install -r ./requirements.txt
  • For Mac: pip install -r requirements.txt
  • Create and configure the database in MySQL Workbench.
  • Copy config_example.py to config.py and update the database password.
  • Update the Flask secret in app.py.
  1. Run the Application:
  • Run app.py in Visual Studio Code.
  • Ensure the Python extension is installed for the remote environment.
  • Activate the virtual environment:
  • For Windows: py -m venv venv_p1demo
  • For Mac: python3 -m venv venv_p1demo

By following these instructions, you should have a fully configured development environment with necessary services and tools.

Making the Electronical Setup

volledigeschakeling.jpg
ProjectOne_Breadbord_bb.png
ProjectOne_schematic_schem.png

You can make the exact same elektronical setup as me if you follow the screenshot from above. I have a schematic version and a breadbord version for a more physical interpretation.


I was able to make the whole setup on 1 breadbord by using a T-piece to easily connect al GPIO-pins from the raspberryPi on the breadbord.


If you would like to make the same casing as me you will have to put everything on 1 breadbord to fit everything.


For most of the wiring it just easily to follow. There is just 1 flaw about this. The potentiometer that is connected to the V0 on the lcd screen. Why you may ask yourself?


Well the potentiometer is used to control the contrast of the lcd screen. If you don't calibrate it right you will never be able to see anything on the display. So it is important to play with it for a little bit so you can see the text on it.

Making of the Casing

3dprint.jpg

So I made this case using the program Blender. As you can see there is quite a big gap in the middle of it. There has gone something wrong while printing the 3D-model. I don't think that there is an issue with the blender file itself (I could be wrong, as I'm very new to using it).

You can find the 3d-model on the same github link: https://github.com/SnaetWarre/ProjectOneDownload

(deksel.blend = the cover, ProjectOne.blend = the body)


If you would like to make something else in blender that is totally fine. Here are some measurements I made to make sure that everything (sensors + actuators) are able to stick out of the body without having to make any adjustments after the printing.


Measurments sensors & actuators:


- button: (2cm diameter)

- air quality sensor (0.9 cm diameter)

- heartrate sensor (0.7cm x 0.4cm)

- Temperatur sensor (0.8cm diameter)

- vibration motor (you don't need to make a hole for this -> will be glued against the body on the inside)

- buzzer (1.2 cm diameter)

Making Everything Work

Finished(3).jpg

If you have done everthing correctly you can now actually start using it. If you go into the backend folder in the repository you will find a file called "app.py"


In summary, this script sets up a Flask web server that interacts with various hardware components to monitor and report health metrics such as heartbeat, temperature, and air quality, providing a real-time interface through web sockets and an LCD display.


After running this file there will eventually show up a Ip adress. In your browser on your laptop I want you to go surf to that address. Normally Apache will show the default debian page. Follow these instructions to setup apache2 to show your html page that you cloned from the repository.


Configuration Instructions for Front End with Apache

  1. Display Front End in Apache:
  • Access your Pi's Apache server on your PC: http://192.168.168.169
  • You should see the Apache2 Debian Default Page, located at /var/www/html/ on the Pi.
  • We will use the front-end folder from the cloned repo instead.
  • Gain administrator rights if needed: sudo -i
  • Open the Apache configuration file: nano /etc/apache2/sites-available/000-default.conf
  • Change the DocumentRoot directive:
  • From DocumentRoot /var/www/html
  • To DocumentRoot /home/user/<name_of_your_repo>/front
  • Save the changes: Ctrl + x, followed by Y and Enter
  • Restart Apache: service apache2 restart
  1. Set Root Folder Permissions:
  • Open the Apache configuration file: nano /etc/apache2/apache2.conf
  • Modify the <Directory /> section:
  • From:

<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
  • To:

<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
  • Save the changes: Ctrl + x, followed by Y and Enter
  • Set the permissions:
  • sudo chmod o+x /home/user/<name_of_your_repo>
  • sudo chmod o+x /home/user/<name_of_your_repo>/front
  • Restart Apache: service apache2 restart
  • Check Apache status: service apache2 status
  • You should see output indicating Apache is active and running.



If you want to make the project startup automatically when you turn the raspberryPi on you can follow these instructions:



  1. Automatic Project Startup:
  • Create a service file named mijnproject.service with the following content:

[Unit]
Description=ProjectOne Project
After=network.target

[Service]
ExecStart=/home/user/<name_of_your_repo>/<venv>/bin/python -u /home/user/<name_of_your_repo>/backend/app.py
WorkingDirectory=/home/user/<name_of_your_repo>/backend
StandardOutput=inherit
StandardError=inherit
Restart=always
User=user
CPUSchedulingPolicy=rr
CPUSchedulingPriority=99

[Install]
WantedBy=multi-user.target
  • Copy the service file to the system directory:
  • sudo cp mijnproject.service /etc/systemd/system/mijnproject.service
  • Test the service by starting it:
  • sudo systemctl start mijnproject.service
  • Stop the service:
  • sudo systemctl stop mijnproject.service
  • Enable the service to start on boot:
  • sudo systemctl enable mijnproject.service
  • Check the status of your service:
  • sudo service mijnproject status
  • View the logs of your service:
  • sudo journalctl -u mijnproject




Finished

finished.jpg
addingstickers.jpg
addingstickerswithmom.jpg

If you have done everything correctly you will have the exact same working project as me. The website is quite basic I agree but I really pushed hard to make it a good and stable working website. The login system on the site has no passwords as well, just making a user with username for register, and you can login into the user by just using the right username.


I added some stickers to the case as well to make it a bit more funny looking. Just all black was a bit boring to me. I made the stickers in Canva (the design itself is only available using pro edition) So I can't really link that if you would like the exact same. (thank you mom for cutting out those stickers)


I hope you guys were able to make the project using my instructions, if you have any feedback for me feel free to leave a comment down below :)