#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
int led=7;
DHT dht(DHTPIN,DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
Serial.println("dht22 reading ....");
pinMode(led,OUTPUT);
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
// this speeds up the simulation
delay(200);
float humidity=dht.readHumidity();
float temperature=dht.readTemperature();
if(isnan(humidity)||isnan(temperature)){
Serial.println("failed to read from sensor");
return;
}
Serial.print("humidity:");
Serial.println(humidity);
Serial.println("%");
digitalWrite(led,HIGH);
Serial.println("temperature:");
Serial.println(temperature);
Serial.println("'C");
}