ESP8266 + DHT... Temperature conversion

Post Reply
jovosm
Noob
Posts: 3
Joined: Fri Jun 28, 2019 3:10 pm

ESP8266 + DHT... Temperature conversion

Post by jovosm » Fri Jun 28, 2019 3:13 pm

In a sketch for ESP8266 + DHT, how to change temperature from Celsius to Fahrenheit?

AskGuru
Site Admin
Posts: 6
Joined: Sat Dec 15, 2018 5:14 pm

Re: ESP8266 + DHT... Temperature conversion

Post by AskGuru » Fri Jun 28, 2019 11:11 pm

Hi jovosm,

Thanks for trying AskSensors. Could you please specify the ESP8266+DHT sketch do you use?

Thanks

jovosm
Noob
Posts: 3
Joined: Fri Jun 28, 2019 3:10 pm

Re: ESP8266 + DHT... Temperature conversion

Post by jovosm » Tue Jul 02, 2019 3:07 pm

It's example sketch how to connect ESP8266 and DHT sensor and how to connect to asksensor.com and see temperature and humidity.
https://github.com/asksensors/AskSensors-ESP8266-DHT

Guru
Simple
Posts: 13
Joined: Tue Dec 18, 2018 11:36 pm
Contact:

Re: ESP8266 + DHT... Temperature conversion

Post by Guru » Thu Jul 04, 2019 11:49 am

jovosm,
You can convert the temperature from degrees Celsius to Fahrenheit just after reading it from the sensor and before sending it to the AskSensors cloud: by multiplying by 1.8 (or 9/5) and adding 32.

here is an example:

Code: Select all

 // Get temperature event and print its value.
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println("Error reading temperature!");
  }
  else {
    // Update temperature and humidity
    myTemperature = (float)event.temperature;
    myTemperature = (float) (32 + myTemperature  * 9/5);
    Serial.print("Temperature: ");
    Serial.print(myTemperature);
    Serial.println(" C");
}


jovosm
Noob
Posts: 3
Joined: Fri Jun 28, 2019 3:10 pm

Re: ESP8266 + DHT... Temperature conversion

Post by jovosm » Fri Jul 05, 2019 3:14 pm

It works now.
Thank You!

Guru
Simple
Posts: 13
Joined: Tue Dec 18, 2018 11:36 pm
Contact:

Re: ESP8266 + DHT... Temperature conversion

Post by Guru » Thu Jul 11, 2019 10:23 pm

Great!

Post Reply