#include <Servo.h>
#include <DHT.h>
#define DHTPIN 8
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
const int led1 = 2;
const int led2 = 3;
const int fanLed = 4; // LED simulating the fan
const int button1 = 6;
const int button2 = 7;
Servo thermostat;
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(fanLed, OUTPUT); // Setup for fan simulation LED
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
thermostat.attach(9);
dht.begin();
Serial.begin(9600);
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
// Simulating temperature change manually for testing
t = 30; // Manually set temperature to 30°C for testing
// Display temperature and humidity
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
// Automatic control based on temperature
if (t > 25) {
digitalWrite(fanLed, HIGH); // Turn on fan simulation LED
thermostat.write(0); // Set thermostat to cool
} else {
digitalWrite(fanLed, LOW); // Turn off fan simulation LED
thermostat.write(180); // Set thermostat to heat
}
// Manual control via buttons
if (digitalRead(button1) == LOW) {
digitalWrite(led1, !digitalRead(led1));
delay(500);
}
if (digitalRead(button2) == LOW) {
digitalWrite(led2, !digitalRead(led2));
delay(500);
}
delay(2000); // Delay for readability
}