#include <DHT.h>
#include <Servo.h>
#define DHT_PIN_IN 2
#define DHT_PIN_OUT 3
#define SERVO_PIN 4
#define WINDOW_OPEN_TIME 3600000
DHT dhtIn(DHT_PIN_IN, DHT22);
DHT dhtOut(DHT_PIN_OUT, DHT22);
Servo servo;
int pinVert = 5;
int pinJaune = 6;
int pinRouge = 7;
bool window;
void setup() {
pinMode(pinVert, OUTPUT);
pinMode(pinJaune, OUTPUT);
pinMode(pinRouge, OUTPUT);
servo.attach(SERVO_PIN);
Serial.begin(9600);
}
void loop() {
float tempInt = dhtIn.readTemperature();
float tempEXT = dhtOut.readTemperature();
Serial.print("Température int : ");
Serial.println(tempInt);
Serial.print("Température ext : ");
Serial.println(tempEXT);
if (tempInt > 25 || tempInt < 38) {
openWindow();
delay(WINDOW_OPEN_TIME);
closeWindow();
}
if (window==false){
if (tempInt > 39 || tempEXT > 39) {
digitalWrite(pinVert, HIGH);
digitalWrite(pinJaune, LOW);
digitalWrite(pinRouge, LOW);
} else if (tempInt < 20 || tempEXT < 20) {
digitalWrite(pinVert, LOW);
digitalWrite(pinJaune, LOW);
digitalWrite(pinRouge, HIGH);
} else {
digitalWrite(pinVert, LOW);
digitalWrite(pinJaune, HIGH);
digitalWrite(pinRouge, LOW);
}}
}
void openWindow() {
window = true;
servo.write(90);
}
void closeWindow() {
window = false;
servo.write(0);
}