Created
March 23, 2020 14:24
-
-
Save ahmetus/a5b1c2022f91ad44ad54295d87abf886 to your computer and use it in GitHub Desktop.
Esp32-DHT11 Sıcaklık ve Nem Bilgisini Seri Monitöre Yazdırma
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_Sensor.h> | |
#include <DHT.h> | |
#define DHTPIN 27 // Digital pin connected to the DHT sensor | |
#define DHTTYPE DHT11 // DHT 11 | |
DHT dht(DHTPIN, DHTTYPE); | |
String readDHTTemperature() { | |
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) | |
// Read temperature as Celsius (the default) | |
float t = dht.readTemperature(); | |
// Read temperature as Fahrenheit (isFahrenheit = true) | |
//float t = dht.readTemperature(true); | |
// Check if any reads failed and exit early (to try again). | |
if (isnan(t)) { | |
Serial.println("DHT sensorden sicaklik bilgisi alinamadi!"); | |
return "--"; | |
} | |
else { | |
Serial.print("Sicaklik : "); | |
Serial.print(t); | |
Serial.println(" Derece"); | |
//Serial.print("Derecesi : "); | |
return String(t); | |
} | |
} | |
String readDHTHumidity() { | |
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) | |
float h = dht.readHumidity(); | |
if (isnan(h)) { | |
Serial.println("DHT sensorden nem bilgisi alinamadi!!"); | |
return "--"; | |
} | |
else { | |
Serial.print("Nem Oranı : "); | |
Serial.print(h); | |
Serial.println(" Gram/metrekup"); | |
//Serial.print("Gram/metrekup olcusunde : "); | |
return String(h); | |
} | |
} | |
void setup() { | |
// Serial port for debugging purposes | |
Serial.begin(115200); | |
dht.begin(); | |
Serial.println(readDHTTemperature()); | |
Serial.println(readDHTHumidity()); | |
} | |
void loop() { | |
delay(2000); | |
setup(); | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment