// ESP32 Smart Temperature & Heart Rate Alert System
// Sensor behavior simulated using potentiometers
#define TEMP_PIN 34
#define HR_PIN 35
#define BUZZER_PIN 25
#define LED_PIN 26
#define BUZZER_CHANNEL 0
#define BUZZER_FREQ 2000 // 2 kHz
#define BUZZER_RESOLUTION 8 // 8-bit PWM
const float TEMP_HIGH = 37.5;
const float TEMP_LOW = 36.0;
const int HR_LOW = 60;
const int HR_HIGH = 100;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
// ✅ PWM
ledcAttach(BUZZER_PIN, BUZZER_FREQ, BUZZER_RESOLUTION);
digitalWrite(LED_PIN, LOW);
ledcWrite(BUZZER_PIN, 0); // Buzzer OFF
Serial.println("Vital Signs Monitoring Simulation Started");
}
void loop() {
int tempRaw = analogRead(TEMP_PIN);
int hrRaw = analogRead(HR_PIN);
float temperature = map(tempRaw, 0, 4095, 30, 42);
int heartRate = map(hrRaw, 0, 4095, 50, 120);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C | Heart Rate: ");
Serial.print(heartRate);
Serial.println(" bpm");
if (temperature > TEMP_HIGH || temperature < TEMP_LOW ||
heartRate < HR_LOW || heartRate > HR_HIGH) {
digitalWrite(LED_PIN, HIGH);
ledcWrite(BUZZER_PIN, 128); // 🔊 Sound ON
Serial.println("⚠ ALERT: Abnormal Condition Detected");
} else {
digitalWrite(LED_PIN, LOW);
ledcWrite(BUZZER_PIN, 0); // 🔇 Sound OFF
Serial.println("✔ Status: Normal");
}
Serial.println("----------------------------------");
delay(2000);
}