#include <Wire.h>
#include <MPU6050.h>
MPU6050 sensor;
// LED on Pin 13
int ledPin = 13;
// Low heartbeat threshold
int lowThreshold = 60;
// High heartbeat threshold
int highThreshold = 120;
// these thresholds would be determined on the size of the dog and their health
long lastMeasureTime = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
sensor.initialize();
if (sensor.testConnection()) {
Serial.println("MPU6050 connected");
}
}
void loop() {
// Collect data from sensor, in practical application this would be a ECG sensor
int16_t ax, ay, az;
sensor.getAcceleration(&ax, &ay, &az);
// Measure the number of beats per minute
if (millis() - lastMeasureTime >= 60000) {
int bpm = calculateBPM();
Serial.print("Beats Per Minute: ");
Serial.println(bpm);
// Check heart rate and notify if too high or low
if (bpm < lowThreshold) {
Serial.println("Notification: Low heart rate");
digitalWrite(ledPin, HIGH);
} else if (bpm > highThreshold) {
Serial.println("Notification: High heart rate");
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
lastMeasureTime = millis();
}
}
int calculateBPM() {
// This in practical application would calculate the beats per minute from the ECG sensor
// This is just simulating different heart beats to test the notifications
return random(50, 130);
}