1.5.7. fejezet, Hőmérséklet, páratartalom és légnyomás

Hőmérséklet és páratartalom mérése DHT22-vel

#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT22
 
DHT dht(DHTPIN, DHTTYPE);
 
void setup() {
  Serial.begin(9600);
  Serial.setTimeout(2000);
 
  // Wait for serial to initialize.
  while(!Serial) { }
 
  Serial.println("Device Started");
  Serial.println("-------------------------------------");
  Serial.println("Running DHT!");
  Serial.println("-------------------------------------");
}
 
int timeSinceLastRead = 0;
void loop() {
  if(timeSinceLastRead > 2000) {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    float h = dht.readHumidity();
    // Read temperature as Celsius (the default)
    float t = dht.readTemperature();
    // Read temperature as Fahrenheit (isFahrenheit = true)
    float f = dht.readTemperature(true);
 
    // Check if any reads failed and exit early (to try again).
    if (isnan(h) || isnan(t) || isnan(f)) {
      Serial.println("Failed to read from DHT sensor!");
      timeSinceLastRead = 0;
      return;
    }
 
      // Compute heat index in Fahrenheit (the default)
    float hif = dht.computeHeatIndex(f, h);
    // Compute heat index in Celsius (isFahreheit = false)
    float hic = dht.computeHeatIndex(t, h, false);
 
    Serial.print("Humidity: ");
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(t);
    Serial.print(" *C ");
    Serial.print(f);
    Serial.print(" *F\t");
    Serial.print("Heat index: ");
    Serial.print(hic);
    Serial.print(" *C ");
    Serial.print(hif);
    Serial.println(" *F");
 
    timeSinceLastRead = 0;
  }
  delay(100);
  timeSinceLastRead += 100;
}

És miért is a 4-es a programban a bemeneti láb miközben a d2-re csatlakoztattuk? Vessünk egy pillantást az alábbi lábkiosztás térképre:

Hasonló projektek