#include "DHTesp.h"
const int pin = 14;
DHTesp sen;
TempAndHumidity data;
const int tri = 13;
const int eco = 12;
float dis;
long dur;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(tri, OUTPUT);
pinMode(eco, INPUT);
sen.setup(pin,DHTesp::DHT22);
}
void loop(){
dis = getDistanceIn();
Serial.println("distance:"+String(dis));
data = sen.getTempAndHumidity();
Serial.println("temp" + String(data.temperature,1));
Serial.println("Humi" + String(data.humidity,2));
Serial.println("---------------");
delay((1000));
}
long getDistanceIn()
{
digitalWrite(tri, LOW);
delayMicroseconds(2);
digitalWrite(tri, HIGH);
delay(10);
digitalWrite(tri, LOW);
dur = pulseIn(eco,HIGH);
return((dur*0.034/2)+1);
}