[text] lick

Viewer

  1. #include <DHT.h>
  2.  
  3. #define DHTPIN 7     // Digital pin connected to the DHT sensor
  4. #define DHTTYPE DHT11   // DHT 11
  5.  
  6. DHT dht(DHTPIN, DHTTYPE);
  7.  
  8. void setup() {
  9.   Serial.begin(9600);
  10.   dht.begin();  // Initialize DHT sensor
  11. }
  12.  
  13. void loop() {
  14.   delay(2000);  // Wait for 2 seconds
  15.   float h = dht.readHumidity();    // Read humidity
  16.   float t = dht.readTemperature(); // Read temperature in Celsius
  17.   
  18.   if (isnan(h) || isnan(t)) {
  19.     Serial.println("Failed to read from DHT sensor!");
  20.     return;
  21.   }
  22.   
  23.   Serial.print("Humidity: ");
  24.   Serial.print(h);
  25.   Serial.print("% - Temperature: ");
  26.   Serial.print(t);
  27.   Serial.println("°C");
  28. }
  29.  

Editor

You can edit this paste and save as new:


File Description
  • lick
  • Paste Code
  • 28 Mar-2024
  • 662 Bytes
You can Share it: