WeMOS D1 mini: DHT11 read suhu dan humidity

From OnnoWiki
Revision as of 10:58, 1 June 2023 by Onnowpurbo (talk | contribs) (Created page with "Sumber: https://dewo.wordpress.com/2016/07/10/pemantau-suhu-kelembaban-udara-dengan-wemos-d1-mini-dht11/ DHT11 Wemos VCC 3.3V DATA D2 GND GND #include #define DHTP...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Sumber: https://dewo.wordpress.com/2016/07/10/pemantau-suhu-kelembaban-udara-dengan-wemos-d1-mini-dht11/


DHT11	Wemos
VCC	3.3V
DATA	D2
GND	GND


#include


#define DHTPIN D2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
/* Parameters:
* t = temperature
* h = humidity
* i = ID
*/

void setup() {
  Serial.begin(115200);
  delay(10);
  dht.begin();
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("Gagal membaca sensor DHT");
    return;
  }
 
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C. Humidity: ");
  Serial.println(h);
  
  delay(2000); // Beri delay 2 detik sebelum polling berikutnya
}



Referensi