#include <WiFi.h>
#include <DHT.h>
#include <Wire.h>
// Uncomment one of the lines below for whatever DHT sensor type you're using!
//#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
// DHT Sensor
uint8_t DHTPin = 4;
int RELAY = 27;
// Initialize DHT sensor.
DHT dht(DHTPin, DHTTYPE);
float Temperature;
float Humidity;
unsigned long next_time; // время очередного переключения первого светодиода
int timeout = 10000; // половина периода мигания
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(100);
pinMode(DHTPin, INPUT);
pinMode(RELAY, OUTPUT);
dht.begin();
}
void loop() {
int now_time = millis(); // текущее время
if( now_time >= next_time ){ // если текущее время превысило намеченное время, то
next_time = now_time + timeout; // вычисляем время следующего переключения
//Serial.print("Temperature: ");
// Serial.println(Temperature);
// Serial.print("Humidity: ");
// Serial.println(Humidity);
}
delay(100);
Temperature = dht.readTemperature(); // Gets the values of the temperature
Humidity = dht.readHumidity(); // Gets the values of the humidity
if(Temperature >= 26){
delay(100);
digitalWrite(RELAY, HIGH);
}
}