#define BLYNK_TEMPLATE_ID "TMPL3byTYwj6x"
#define BLYNK_TEMPLATE_NAME "ultrasonic"
#define BLYNK_AUTH_TOKEN "3r9UY-MJ1diTSBqTRrKjKxPL5nh8IMWm"
#include <WiFi.h>
#include <BlynkSimpleLib.h>
#include <MAX30100PulseOximeter.h> // Replace with your sensor library
// Blynk app credentials (replace with your values)
char auth[] = "YOUR_BLYNK_AUTH_TOKEN";
// WiFi network credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";
// Sensor pin connections (modify as needed)
const int pulsePin = 32; // A/D pin for pulse sensor
const int spo2LEDPin = 33; // LED pin for MAX30100
const int spo2DataPin = 34; // Data pin for MAX30100
WiFiClient client;
BlynkSimpleLib Blynk(client);
MAX30100PulseOximeter pulseOximeter(pulsePin, spo2LEDPin, spo2DataPin, client);
double heartRate, spo2;
int thresholdHeartRate = 80; // Set your desired heart rate threshold
int thresholdSpo2 = 95;   // Set your desired SpO2 threshold
void setup() {
  Serial.begin(115200);
  delay(100);
  Blynk.begin(auth);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to WiFi network with IP: ");
  Serial.println(WiFi.localIP());
                              // Initialize sensor (refer to sensor library documentation)
  pulseOximeter.begin();
  }
void loop() {
  Blynk.run();
  // Read sensor data
  pulseOximeter.update();
  if (pulseOximeter.isHeartRateValid()) {
  heartRate = pulseOximeter.getHeartRate();
  Blynk.virtualWrite(V1, heartRate); // Send heart rate to Blynk virtual pin V1
  }
  if (pulseOximeter.isSpO2Valid()) {
  spo2 = pulseOximeter.getSpO2();
  Blynk.virtualWrite(V2, spo2);  // Send SpO2 to Blynk virtual pin V2
  }
  // Check for emergency conditions
  if (heartRate < thresholdHeartRate || spo2 < thresholdSpo2) {
  Serial.println("Emergency! Low heart rate or SpO2 detected.");
  // Add emergency alert logic here (e.g., Blynk notification, buzzer, SMS)
  Blynk.virtualWrite(V3, 1); // Set a virtual pin to 1 for emergency indication (optional)
  } else {
  Blynk.virtualWrite(V3, 0); // Reset emergency pin (optional)
  }
  delay(1000); // Adjust delay based on desired data acquisition rate
  }