#include<Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Adafruit_AHT10.h>
Adafruit_AHT10 aht;
int relay = 26;
const int trigPin = 5;
const int echoPin = 18;
#define SOUND_SPEED 0.034
#define CM 1
long duration;
float distanceCm;
void setup() {
Serial.begin(115200);
Serial.println("Adafruit AHT10 demo!");
if (! aht.begin()) {
Serial.println("Could not find AHT10? Check wiring");
while (1) delay(100);
}
Serial.println("AHT10 found");
lcd.init();
lcd.backlight();
pinMode(relay, OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * SOUND_SPEED / 2;
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
Serial.print("Temp:");
Serial.print(temp.temperature);
Serial.print(" ํC");
Serial.print(" Humi:");
Serial.print(humidity.relative_humidity);
Serial.println("%Rh");
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
lcd.setCursor(0, 0);
lcd.print("T:");
lcd.print(temp.temperature, 1);
lcd.setCursor(7, 0);
lcd.write( 223);
lcd.print("C");
lcd.setCursor(10, 0);
lcd.print("H:");
lcd.print(humidity.relative_humidity, 1);
lcd.print(" %");
lcd.setCursor(0, 1);
lcd.print("D:");
lcd.print(distanceCm, 1);
lcd.setCursor(7, 1);
lcd.print("cm");
if (temp.temperature <= 25) {
digitalWrite(relay, 0);
lcd.setCursor(10, 1);
lcd.print("R:ON ");
}
if (temp.temperature >= 26) {
digitalWrite(relay, 1);
lcd.setCursor(10, 1);
lcd.print("R:OFF");
}
delay(500);
}