DHT11 to print temp to LCD

I love this forum :smiley:

Im stuck, trying to get the DHT11 sensor to print the temp to the LCD screen.

#include <LiquidCrystal_I2C.h>

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);
}


#include "DHT.h"

#define DHTPIN 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)


// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

//DHT dht(DHTPIN, DHTTYPE, 30);

int intakefan = 2;  //  Intake fan for Humid box and dry box
int humidv = 3;     //  Valve for humud intake
int dryv = 4;       // dry box valve
int exfan = 5;      // exhaust fan
int exv = 6;        // exhaust valve
int returnfan = 7;  // fan to bring air from inside box
int returnv = 8;   //  return valve, air from inside box

int DHTpower = 12;  // constant 5v to DHT11

LiquidCrystal_I2C lcd(0x27, 16, 2);  // Set the LCD address to 0x27 for a 16x2 display

void setup() {
  pinMode(intakefan, OUTPUT);
  pinMode(humidv, OUTPUT);
  pinMode(dryv, OUTPUT);
  pinMode(exfan, OUTPUT);
  pinMode(exv, OUTPUT);
  pinMode(returnfan, OUTPUT);
  pinMode(returnv, OUTPUT);
  pinMode(DHTpower, OUTPUT);

  digitalWrite(intakefan, LOW);
  digitalWrite(humidv, LOW);
  digitalWrite(dryv, LOW);
  digitalWrite(exfan, LOW);
  digitalWrite(exv, LOW);
  digitalWrite(returnfan, LOW);
  digitalWrite(returnv, LOW);
  digitalWrite(DHTpower, HIGH);

  Serial.begin(9600);
  lcd.init();       // Initialize the LCD
  lcd.backlight();  // Turn on the backlight
  lcd.clear();      // Clear the LCD screen
  lcd.setCursor(3, 0);
  lcd.print("The Green");
  lcd.setCursor(4, 1);
  lcd.print("Ninja");
  delay(1000);  // Display the startup message for 2 seconds
  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(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
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  float f = dht.readTemperature(true);
  float currentDew = dewPoint(t, h);  // Dew Point for setting pins high

  // 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!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  float hi = dht.computeHeatIndex(f, h);
  float hiDegC = dht.convertFtoC(hi);


  delay(50);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Checking");
  lcd.setCursor(0, 1);
  lcd.print("Dew Point");
  delay(800);
  lcd.clear();
  //Serial.print(f);
  //Serial.print(" *F\t");
  //Serial.print("Heat index: ");
  // Serial.print(hiDegC);
  // Serial.print(" *C ");
  // Serial.print(hi);
  // Serial.print(" *F ");
  lcd.print("Dew Point (*C): ");
  lcd.print(dewPoint(t, h));


  if (currentDew > 11 && (currentDew < 13))  // Level to aim for dew point 12
  {
    digitalWrite(intakefan, LOW);
    digitalWrite(humidv, LOW);
    digitalWrite(dryv, LOW);
    digitalWrite(exfan, LOW);
    digitalWrite(exv, LOW);
    digitalWrite(returnfan, LOW);
    digitalWrite(returnv, LOW);
    lcd.print("Dew point OK");
    lcd.print(dewPoint(t, h));
  }
  if (currentDew > 13) {  //   High dew point, send to dry box
    digitalWrite(humidv, LOW);
    digitalWrite(dryv, HIGH);
    digitalWrite(exv, HIGH);
    digitalWrite(returnv, HIGH);
    lcd.clear();
    lcd.print("Dew Point");
    lcd.print(dewPoint(t, h));
    lcd.setCursor(0,1);
    //lcd.print(dht.readTemperature);  ///  ????
    delay(3000);
    digitalWrite(intakefan, HIGH);
    digitalWrite(exfan, HIGH);
    digitalWrite(returnfan, HIGH);
  }
  if (currentDew < 13) {  // Dew point low, send to humid box

    digitalWrite(humidv, HIGH);
    digitalWrite(dryv, LOW);
    digitalWrite(exfan, LOW);
    digitalWrite(exv, HIGH);
    digitalWrite(returnfan, LOW);
    digitalWrite(returnv, LOW);
    lcd.print("Dew point OK");
    lcd.print(dewPoint(t, h));
    delay(3000);
    digitalWrite(intakefan, HIGH);
    digitalWrite(exfan, HIGH);
  }
}

Where exactly are you stuck ?

cant remember the answer

Hi, @matt82060

What do you mean?

What happens if you make it;

lcd.print(dht.readTemperature); 

Tom.. :grinning: :+1: :coffee: :australia:

I get this

C:\Users\Admin\Documents\Arduino\libraries\DHT_sensor_library/DHT.h:67:9: note: declared here
float readTemperature(bool S = false, bool force = false);
^~~~~~~~~~~~~~~

exit status 1

Compilation error: invalid use of non-static member function 'float DHT::readTemperature(bool, bool)'

Or even

lcd.print(dht.readTemperature());

you champion, that did it

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.