#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHT_PIN 3 // Pin connected to DHT22 data pin
#define PIR_PIN 2 // Pin connected to PIR sensor output
#define LED_PIN 4 // Pin connected to the LED
#define TEMPERATURE_THRESHOLD 25.0 // Set the temperature threshold in Celsius
#define HUMIDITY_THRESHOLD 50.0 // Set the humidity threshold as a percentage
DHT dht(DHT_PIN, DHT22);
void setup() {
pinMode(PIR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
dht.begin();
}
void loop() {
int pirState = digitalRead(PIR_PIN);
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (temperature >= TEMPERATURE_THRESHOLD || humidity >= HUMIDITY_THRESHOLD || pirState == HIGH) {
Serial.println("Motion detected, temperature and humidity above thresholds!");
digitalWrite(LED_PIN, HIGH); // Turn on the LED
}
delay(1000);
}