Taupunktmessung.ino

Aus WiebelPedia
Zur Navigation springen Zur Suche springen
// Based on the DHT-library of ladyada, by bastelator.de

#include "DHT.h"
#include <LiquidCrystal.h>

#define DHTPINA 11     // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dhta(DHTPINA, DHTTYPE);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

double dewPointFast(double celsius, double humidity)
{
	double a = 17.271;
	double b = 237.7;
	double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
	double Td = (b * temp) / (a - temp);
	return Td;
}

double dewPoint(double celsius, double humidity)
{
	// (1) Saturation Vapor Pressure = ESGG(T)
	double RATIO = 373.15 / (273.15 + celsius);
	double RHS = -7.90298 * (RATIO - 1);
	RHS += 5.02808 * log10(RATIO);
	RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
	RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
	RHS += log10(1013.246);

        // factor -3 is to adjust units - Vapor Pressure SVP * humidity
	double VP = pow(10, RHS - 3) * humidity;

        // (2) DEWPOINT = F(Vapor Pressure)
	double T = log(VP/0.61078);   // temp var
	return (241.88 * T) / (17.558 - T);
}

void setup() {
  
  lcd.begin(16, 2);
  
  Serial.begin(9600); 
  Serial.println("DHTxx test!");
 
  dhta.begin();

}

void loop() {
  
  
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float ha = dhta.readHumidity();
  float ta = dhta.readTemperature();
  float da = dewPoint(ta, ha);

  
  lcd.setCursor(0,0);
  lcd.print("T: ");
  lcd.print((int)ta);
  lcd.write(0b11011111);
  lcd.print("C, H: ");
  lcd.print((int)ha);
  lcd.print("%");
  lcd.setCursor(0,1);
  lcd.print("Taupunkt ");
  lcd.print(da);
  lcd.write(0b11011111);
  lcd.print("C ");

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(ta) || isnan(ha)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print("Aussen RLF: "); 
    Serial.print(ha);
    Serial.print(" %\t");
    Serial.print("Temperatur: "); 
    Serial.print(ta);
    Serial.print(" *C");
    Serial.print(" \t");
    Serial.print("Taupunkt: ");  
    Serial.print(da);
    Serial.println(" *C");
    delay(2000);
  }
}