#include <DHT.h>
#define DHTPIN 2 // Pin connected to the data pin of DHT sensor
#define DHTTYPE DHT11 // DHT11 or DHT22
DHT dht(DHTPIN, DHTTYPE);
float temperatureThreshold = 37.5; // Set a threshold temperature in °C
float humidityThreshold = 60.0; // Set a threshold humidity in %
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
// Reading temperature and humidity values
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if sensor reading failed
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Calculate stress level
int stressLevel = calculateStressLevel(temperature, humidity);
// Print data
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.print(" %, Stress Level: ");
Serial.println(stressLevel);
delay(2000); // Delay for 2 seconds
}
int calculateStressLevel(float temperature, float humidity) {
int level = 0;
// Increase stress level if temperature exceeds threshold
if (temperature > temperatureThreshold) {
level += 1;
}
// Increase stress level if humidity exceeds threshold
if (humidity > humidityThreshold) {
level += 1;
}
// You can add additional conditions to refine the stress calculation
return level;
}