PulsePause
I am a student at Howest in Belgium, and I have developed a project designed to help you keep your heartbeat under control through the use of music. This project incorporates a heart rate sensor, a temperature sensor, and a GPS sensor. These sensors gather real-time data that is displayed on a dedicated website.
If your heartbeat becomes too high or too low, the music playing will automatically pause, alerting you to the need to slow down to stabilize your heart rate. Once your heartbeat returns to a your chosen range, the music will resume, providing a seamless way to maintain a balanced heart rate while enjoying your favorite tunes.
Additionally, the temperature sensor and GPS sensor provide valuable context and additional data, enhancing the overall monitoring experience. This comprehensive system not only helps manage your heartbeat but also ensures you are aware of your environmental conditions and location, all accessible through the user-friendly website interface. And for now, enjoy your safe run!
Supplies
Main Controller
- Raspberry Pi: The primary controller of the system.
Power and Connectivity
- Power bank (5V-3A): Power supply for the Raspberry Pi.
- USB C cable: to connect power bank to the pi.
- Breadboard: For putting components on.
- Wires
- Resistors
- power supply(optional)
Sensors and Inputs
- LM35 Temperature Sensor
- Heartbeat sensor
- GPS sensor
- MCP3008: For SPI Interface.
Displays and Indicators
- LCD display
- USB audio adapter
- Headphones with cable
Supplies for housing
- Foam core
- Tape
- Superglue
Downloads
Circuit
It is very important when making the circuit to make sure that you are supplying the the sensors the right amount of voltage! I would suggest putting the sensors on one by one and testing if they work; so if you make a mistake than the damage is minimal. You can switch the power supply out if you are sure everything is correct and connect the power from the pi to the breadboard instead.
Setting Up Your Rapsberry Pi
Database
Tables
1. Sessions
- Columns:
- session_id (primary key)
- start_time
- end_time
- Description:
- This table represents individual sessions with a unique ID and a time span from start to end. It serves as the central table linking the other entities.
2. Actuators
- Columns:
- actuator_id (primary key)
- actuator_type
- Description:
- This table defines the types of actuators available in the system.
3. Sensors
- Columns:
- sensor_id (primary key)
- sensor_type
- Description:
- This table defines the types of sensors available in the system.
4. Actuator History
- Columns:
- actuator_history_id (primary key)
- session_id
- actuator_id
- status
- timestamp
- Description:
- This table logs the history of actuator statuses during sessions.
- Relationships:
- Linked to sessions via session_id to record which session the history belongs to.
- Linked to actuators via actuator_id to identify which actuator's status is being recorded.
5. Sensor Readings
- Columns:
- sensor_reading_id (primary key)
- session_id
- sensor_id
- value
- timestamp
- Description:
- This table records sensor readings taken during sessions.
- Relationships:
- Linked to sessions via session_id to associate readings with a specific session.
- Linked to sensors via sensor_id to identify which sensor provided the reading.
To get my database just go to my GitHub and go to database. Just copy the code and run it on MySQL.
Heartbeat Sensor
Now that that's all done, lets start with the heartbeat sensor because it is the most important one. First make sure the heartbeat sensor is connect like in the electronic scheme above. After that, you can use the following tutorial: https://tutorials-raspberrypi.com/raspberry-pi-heartbeat-pulse-measuring/. The code for this sensor is Pulse.py and the MCP3008.py on my GitHub.
Temperature Sensor (LM 35)
The LM35 is the temprature sensor I used which is connected to the MCP3008. It uses the same MCP3008.py file.
Gps Sensor
Next up is the gps sensor. I am using the GPS module u-blox NEO-7m. To be able to use this gps sensor, it is best to be outside, because inside it is hard to get signals which can cause you to not receive any data. The script for the gps sensor can be find in my app.py on my GitHub. If it doesn't seem to work, you can try following this tutorial.
Backend
Step 1: Clone Your Repository
If you haven't already, clone your repository from GitHub.
Step 2: Setting Up Apache
- Check Apache:
- Open your browser and navigate to http://192.168.168.169.
- You should see the Apache2 Debian Default Page.
- Modify DocumentRoot:
- Open a terminal and become the root user:
sudo -i
- Open the configuration file:
nano /etc/apache2/sites-available/000-default.conf
- Find the line DocumentRoot /var/www/html and change it to:
DocumentRoot /home/user/<your_repo_name>/front
- Save the file by pressing Ctrl + x, followed by Y and Enter.
- Restart Apache:
service apache2 restart
- Set Permissions for the Root Folder:
- Open the Apache configuration file:
nano /etc/apache2/apache2.conf
- Look for the following lines:
<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>
- Change them to:
<Directory />
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
- Save the file by pressing Ctrl + x, followed by Y and Enter.
- Set Proper Permissions:
sudo chmod o+x /home/user/<your_repo_name>
sudo chmod o+x /home/user/<your_repo_name>/front
- Restart Apache:
service apache2 restart
- Check if Apache is Running Correctly:
service apache2 status
- You should see an output similar to:
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since ...
Step 3: Running the Backend and Frontend
- Start the Frontend Server:
- Open a new terminal in Visual Studio Code.
- Navigate to the front directory:
cd front/
- Start the HTTP server:
python3 -m http.server 9000
- Start the Backend:
- Open a new terminal in Visual Studio Code.
- Run the app.py file:
python3 backend/app.py
Step 4: Setting Up Your Project to Auto-Start
- Create a Service File:
- Create a file named myproject.service:
nano myproject.service
- Add the following code to the file:
[Unit]
Description=ProjectOne Project
After=network.target
[Service]
ExecStart=/home/user/<your_repo_name>/<venv>/bin/python -u /home/user/<your_repo_name>/backend/app.py
WorkingDirectory=/home/user/<your_repo_name>/backend
StandardOutput=inherit
StandardError=inherit
Restart=always
User=user
CPUSchedulingPolicy=rr
CPUSchedulingPriority=99
[Install]
WantedBy=multi-user.target
- Save the file by pressing Ctrl + x, followed by Y and Enter.
- Copy the Service File to the Systemd Directory:
sudo cp myproject.service /etc/systemd/system/myproject.service
- Test the Service:
- Start the service:
sudo systemctl start myproject.service
- Stop the service:
sudo systemctl stop myproject.service
- Enable the Service to Start on Boot:
sudo systemctl enable myproject.service
- Check the Status of the Service:
sudo service myproject status
- View the Service Logs:
sudo journalctl -u myproject
Frontend
For the frontend you will just have to clone my repository and make sure the app.py is running, and then search up the Ip address from the raspberry pi (which should be displayed on the LCD display) on google.
If not, open a terminal on your Pi. Enter the command hostname -I in the terminal. Your Pi's IP address is the first part of the output: it will contain four numbers separated by periods, like so: 192. xx. x.x.
Housing
I made the housing for my project out of foam core. I stated by cutting out the sides with a cutter. I used the measurements from the file below so i would fit perfectly in my backpack. After cutting it all out, I glued it together with super glue and then taped the sides with blue tape to make it look good. After that, I made sure it fitted in my backpack so I could easily run with it .