#include"DHTesp.h"
const int trig =13;
const int echo =12;
const int pin1 =15;
DHTesp dhtsensor;
TempAndHumidity data;
float distance;
long duration;
void setup() {
Serial.begin(115200);
dhtsensor.setup(pin1,DHTesp::DHT22);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
data= dhtsensor.getTempAndHumidity();
Serial.println("temp : "+String(data.temperature));
Serial.println("humidity : " +String(data.humidity));
distance=getdistance();
Serial.println("Distance : " +String(distance));// put your main code here,
ThingSpeak.setField(1, dis);
ThingSpeak.setField(2, data.temperature);
ThingSpeak.setField(3,data.humidity);
statusCode = ThingSpeak.writeFields(myChannelNumber,myWriteAPIKey);
delay(5000); // this speeds up the simulation
}
long getdistance()
{
digitalWrite(trig, LOW);
delayMicroseconds(5);
digitalWrite(trig, HIGH);
delay(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
return(duration*0.034/2+1);
}