Go Down

### Topic: [Solved]using robs dht11 library c to f conversion is this the best way? (Read 1 time)previous topic - next topic

#### grendle

##### Jan 17, 2013, 08:27 pmLast Edit: Jan 18, 2013, 02:15 am by grendle Reason: 1
is this the easiest/best way to do C to Farenheit conversions?

Code: [Select]
` Serial.print(DHT.humidity, 1);  Serial.print(",\t");  Serial.println(DHT.temperature*1.8+32, 1);`

also, storing each in eeprom, will one byte hold the data? say 76.1? best way to do that would be appreciated thanks!

solution. changed
Code: [Select]
`Serial.print(DHT.humidity,1);`
to
Code: [Select]
`Serial.print(DHT.humidity,0);`
for the whole number. the first one gives a one place decimal point. moral of story, i learned a bit more by reading around. thank you all. kudos to rob for library, i couldnt use the dht22 library couldnt figure out conversion for life of me. this is small and compact, keep up good work you arduino folks.

#### robtillaart

#1
##### Jan 17, 2013, 08:42 pm
Hi Grendle,

This is an easy way to convert an Celsius to a Fahrenheit temperature.
It is slow as it uses floating points math, it is relative fast as it does not use division.
Because it uses floating point is is quite accurate.
The formula works for integer and float values of Celsius. Note the DHT11 only produces integer values for temp.

A far more elaborate C2F discussion can be found here - http://arduino.cc/forum/index.php/topic,139006.0.html -

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

#2

#### PaulS

#3
##### Jan 17, 2013, 09:05 pm
Quote
will one byte hold the data? say 76.1?

Will one byte, that holds an integral value in the range 0 to 255, hold 76.1? What do you think?

#### grendle

#4
##### Jan 17, 2013, 09:50 pm
sigh, well put it that way, no. maybe i asked wrong, how can i store 76.1 in eeprom, doable? no? then how to round up and down in code?

#### PaulS

#5
##### Jan 17, 2013, 09:58 pm
Given that the sensor only returns integer values, why would you want to store a 4 byte float in EEPROM instead of a 2 byte int? Storing a 2 byte int is easy - use highByte() and lowByte() to get the bytes.