#include <LiquidCrystal_I2C.h>
 #include <Servo.h>
 #include <DHT.h>
 #include <Wire.h>
 Servo myservo;
 LiquidCrystal_I2C LCD(0x27,20,4);
 int trig=15;
 int echo=14;
 int time;
 double distant;
 int DHTpin=9;
  DHT mydht(DHTpin,DHT22);
 float HUM;
 float TEMP;

 void setup() {
  // put your setup code here, to run once:
LCD.init();
  LCD.backlight();
  LCD.begin(16,2);
  myservo.attach(10);
mydht.begin();
   pinMode(trig, OUTPUT);
    pinMode(echo, INPUT);

}

void loop() {

  digitalWrite(trig, LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
time=pulseIn(echo,HIGH);
distant=(time*0.034/2);

 if (distant<=50)
 myservo.write(180);
 else if (distant>=150)
 myservo.write(0);

 HUM=mydht.readHumidity();
  TEMP=mydht.readTemperature();
LCD.setCursor(0,0);
  LCD.print("distant ");
LCD.print(distant);
LCD.println("cm");
LCD.setCursor(0,1);
LCD.print("Temp= "); 
LCD.print(TEMP);
LCD.print("c");
LCD.setCursor(0,2);
LCD.print("Humidity= "); 
LCD.print(HUM);
LCD.print("%");
delay(500);
LCD.clear();
}