#define TEMP_PIN 34
#define LIGHT_PIN 35
#define PIR_PIN 32
#define LED_PIN 25
#define BUZZER_PIN 26
float prevTemp = 0;
float alpha = 0.7; // smoothing factor
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
float readTemperature() {
int value = analogRead(TEMP_PIN);
float voltage = value * (3.3 / 4095.0);
float temp = voltage * 100; // simulated temp
return temp;
}
void loop() {
// 🔹 Read sensors
float temp = readTemperature();
int light = analogRead(LIGHT_PIN);
int motion = digitalRead(PIR_PIN);
// 🔹 Smooth temperature
float filteredTemp = alpha * temp + (1 - alpha) * prevTemp;
// 🔹 Decision logic
String stress = "LOW";
if (filteredTemp > 30 && light < 1500 && motion == 0) {
stress = "HIGH";
} else if (filteredTemp > 28) {
stress = "MEDIUM";
}
// 🔹 Output control
if (stress == "HIGH") {
digitalWrite(LED_PIN, HIGH);
digitalWrite(BUZZER_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
digitalWrite(BUZZER_PIN, LOW);
}
// 🔹 Serial output
Serial.print("Temp: ");
Serial.print(filteredTemp);
Serial.print(" | Light: ");
Serial.print(light);
Serial.print(" | Motion: ");
Serial.print(motion);
Serial.print(" | Stress: ");
Serial.println(stress);
prevTemp = filteredTemp;
delay(1000);
}