#include <SPI.h>
#include <Wire.h>
#include <DHTesp.h>
#include <ESP32Servo.h>
#include <LiquidCrystal_I2C.h>
#define DHT_PIN 12
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHTesp dhtSensor;
Servo myservo;
int pos = 0;
void setup() {
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
myservo.attach(13);
pinMode(15, INPUT);
pinMode(2, OUTPUT);
pinMode(14, INPUT);
lcd.init();
lcd.backlight();
}
void loop() {
lcd.setCursor(0,0);
lcd.println("VU TIEN PHAT");
TempAndHumidity data = dhtSensor.getTempAndHumidity();
// lcd.clear();
lcd.setCursor(0,1);
lcd.print(String(data.temperature, 1) + " do C");
lcd.setCursor(10,1);
lcd.println(String(data.humidity, 1) + "%");
delay(1000);
if((data.temperature>60 && data.temperature < 80) ||digitalRead(15) == HIGH){
myservo.write(180);
digitalWrite(2,HIGH);
delay(10);
}
else {
myservo.write(0);
digitalWrite(2,LOW);
delay(10);
}
if( digitalRead(14) == HIGH){
myservo.write(180);
delay(10);
}
}