Converting Celsius to Fahrenheit

I am trying to convert Celsius to Fahrenheit reading from a DHT11and displaying onto a 1602 LCD display. It continues to show "32" as the temperature, but if I have it output in Celsius its giving around 20.8.

Here is the code I am running.

#include <DHT_Async.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11
#include <LiquidCrystal.h>
static const int DHT_SENSOR_PIN = 7;

DHT_Async dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);


void setup( )
{
  lcd.begin(16, 2);
  lcd.print( "T = " );
  lcd.setCursor(10, 0);
  lcd.print( "deg. F" );
  lcd.setCursor(0, 1);
  lcd.print( "H = " );
  lcd.setCursor(10, 1);
  lcd.print( "%" );

}

static bool measure_environment( float *temperature, float *humidity )
{
  static unsigned long measurement_timestamp = millis( );


  if( millis( ) - measurement_timestamp > 3000ul )
  {
    if( dht_sensor.measure( temperature, humidity ) == true )
    {
      measurement_timestamp = millis( );
      return( true );
    }
  }

  return( false );
}

void loop( )
{

  float temperature;
  float humidity;
  float tempF;
  tempF = (temperature * 1.8)+32.0;

  if( measure_environment( &temperature, &humidity ) == true )
  {

    lcd.setCursor(4, 0);
    lcd.print( tempF );
    lcd.setCursor(4, 1);
    lcd.print( humidity );
        
  }
}

Where in the sketch do you update tempF after reading the temperature, bearing in mind that temperature is declared each time through loop() ?

You need to put something into "temperature" before you use it. There is no magic. You actually have to do the work.

I think you need to move this line:

3 Likes

C >> F

Double it and add 30.