Lesson 11 DHT11 Temperature and Humidity Sensor

Hello,

I am currently trying to make the Arduino read in Fahrenheit instead of Celsius. At the moment I have no clue what to do. The code that I am using is located below. If possible can someone please explain to me how you got the answer? I would like to understand the programming language better.

Thanks.

//www.elegoo.com
//2018.10.25

#include <dht_nonblocking.h>
#define DHT_SENSOR_TYPE DHT_TYPE_11

static const int DHT_SENSOR_PIN = 2;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );

/*

  • Initialize the serial port.
    */
    void setup( )
    {
    Serial.begin( 9600);
    }

/*

  • Poll for a measurement, keeping the state machine alive. Returns
  • true if a measurement is available.
    */
    static bool measure_environment( float *temperature, float *humidity )
    {
    static unsigned long measurement_timestamp = millis( );

/* Measure once every four seconds. */
if( millis( ) - measurement_timestamp > 3000ul )
{
if( dht_sensor.measure( temperature, humidity ) == true )
{
measurement_timestamp = millis( );
return( true );
}
}

return( false );
}

/*

  • Main program loop.
    */
    void loop( )
    {
    float temperature;
    float humidity;

/* Measure temperature and humidity. If the functions returns
true, then a measurement is available. */
if( measure_environment( &temperature, &humidity ) == true )
{
Serial.print( "T = " );
Serial.print( temperature, 1 );
Serial.print( " deg. C, H = " );
Serial.print( humidity, 1 );
Serial.println( “%” );
}
}

If I gave you a temperature in Celsius, say 100, how would you convert it to its Fahrenheit equivalent using maths ?

I know how to do the conversion mathematically, that is easy. (100°C × 9/5) + 32 = 212°F When I tried adding this formula to the code it did not work for me. I tried a lot of variations but every time I uploaded the code it just kept giving me Celsius and not Fahrenheit. I’m still learning C. I tried looking online for help but could not find anything or at least I found stuff but could not get it to work.

thehomiedaniel:
I know how to do the conversion mathematically, that is easy. (100°C × 9/5) + 32 = 212°F When I tried adding this formula to the code it did not work for me. I tried a lot of variations but every time I uploaded the code it just kept giving me Celsius and not Fahrenheit. I'm still learning C. I tried looking online for help but could not find anything or at least I found stuff but could not get it to work.

Show that code. That's the code that has the mistake. That's the one you need help with. Otherwise the only advice is to use basic math.

What might be even easier would be to read the documentation on the library you're using there. It might have a function for getting temp in F.