Temperature/Humidity-Arduino
Sun Jun 09 2024 04:49:01 GMT+0000 (Coordinated Universal Time)
Saved by
@user01
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN,DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
float h= dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if(isnan(h)||isnan(t)||isnan(f))
{
Serial.println(F("Failed to read fromDHT sensor !"));
return;
}
Serial.print(F("Humidity : "));
Serial.print(h);
Serial.print(F("% Temperature : "));
Serial.print(t);
Serial.print(F(" C : "));
Serial.print(f);
Serial.print(F(" F : "));
Serial.println(" ");
}
content_copyCOPY
Comments