This guide will help you build an IoT-Based Heart Attack Detection and Heart Rate Monitoring System using Raspberry Pi. The system will monitor heart rate in real-time and detect potential symptoms of a heart attack, sending alerts if any abnormal readings are detected.
Components Required
- Raspberry Pi (Model 3 or later)
- Heart rate sensor (e.g., MAX30100 or MAX30102)
- Electrocardiogram (ECG) sensor (optional, e.g., AD8232)
- Relay module (for triggering alarms or notifications)
- Connecting wires and breadboard
- Power supply (for Raspberry Pi and sensors)
- Cloud service account (e.g., AWS IoT, Google Cloud IoT, ThingSpeak)
- Buzzer or alarm (optional, for local alerts)
Setting Up the Hardware
Follow these steps to set up the hardware:
-
Connect the Heart Rate Sensor
Connect the heart rate sensor to the Raspberry Pi using GPIO pins or I2C interface. This sensor will measure the patient's heart rate.
-
Connect the ECG Sensor (Optional)
If using an ECG sensor, connect it to the Raspberry Pi to monitor the electrical activity of the heart. This can help in detecting abnormal heart rhythms.
-
Integrate the Relay Module
Connect the relay module to the Raspberry Pi. The relay can be used to trigger an alarm or notification if abnormal heart rates or ECG patterns are detected.
-
Power the System
Ensure the Raspberry Pi and sensors are properly powered. Verify all connections before powering on the system.
Programming the Raspberry Pi
Write the code to read data from the heart rate and ECG sensors and send alerts to the cloud if abnormal readings are detected. Below is a basic example using Python:
import time
import requests
from max30100 import MAX30100
import board
import adafruit_dht
# Configuration
CLOUD_URL = "https://api.example.com/update?api_key=YOUR_API_KEY"
HEART_RATE_SENSOR = MAX30100()
ECG_SENSOR = adafruit_dht.DHT22(board.D4) # Replace with actual ECG sensor
def send_alert(heart_rate):
if heart_rate < 60 or heart_rate > 100: # Example thresholds
response = requests.post(CLOUD_URL, json={
"heart_rate": heart_rate,
"alert": "Heart rate abnormal"
})
print(f"Alert sent to cloud: {response.status_code}")
try:
while True:
# Read sensors
heart_rate = HEART_RATE_SENSOR.get_heart_rate()
# Optionally read ECG sensor data
# ecg_data = ECG_SENSOR.read()
# Send data to cloud
send_alert(heart_rate)
# Wait before the next reading
time.sleep(60) # Adjust as necessary
except KeyboardInterrupt:
print("Program interrupted")
This code reads data from the heart rate sensor and optionally from the ECG sensor. If the heart rate is outside of normal ranges, it triggers an alert and sends the data to the cloud for monitoring.
Setting Up Cloud Integration
To monitor and receive alerts, integrate your system with a cloud service. Configure the cloud service to receive health data from the Raspberry Pi and set up dashboards or notifications based on the data received.
Testing and Calibration
Test the system by simulating different heart rate values and verifying that the data is correctly sent to the cloud. Adjust the thresholds and sensor readings as needed for accurate heart attack detection and monitoring.
Conclusion
The IoT-Based Heart Attack Detection and Heart Rate Monitoring System provides a crucial tool for real-time health monitoring. By integrating heart rate and optional ECG sensors with Raspberry Pi and cloud services, this system enables early detection of potential heart attacks and proactive health management.