Hello All and thanks for the help in advance
As mentioned in the book (page 48), every 10 millivolt represents 1 Celsius, which's mean to get the temperature, I write the following formula:
float temperature = voltage * 0.01;
Instead, it's written in the book as following:
float temperature = (voltage - 0.5) * 100;
Could someone please explain why?
You need to multiply by 100, not divide by 100, to convert 10mV (0.010V) to 1 degree.
Subtracting 0.5 from the voltage is to correct for a 500mV offset voltage on the sensor output.
Thanks for the explanation but I can't seem to figure out what you mean and where to figure out the 500mV offset voltage.
The book explains this -.5 is needed in the formula because it needs to offset the values below freezing.
I can't seem to understand either your or the book's explanation.
I found the temperature conversion stated in the book was incorrect, or maybe just gave F values when it claimed to give C values. Tbh, there are a few errors or typos in the book and I am just up to Chapter 3..not sure if this is due to my starter kit being the Arduino SRL version.
I ended up changing the code to:
// convert the voltage to temperature, then from degrees F to C
float temperature = ((((voltage - 0.5) * 100) - 32) * 5) /9;
which gave the correct Celcius values.
You should lookup the datasheet for your specific temperature sensor online - they typically show charts indicating the voltage and corresponding temperature. For the TMP36 (which is what came with my kit), the data-sheet shows that they report 0.75 volts at 25C, and the chart shows a linear relationship between voltage and temperature. So 0.75 - 0.5 will give you 0.25. When you multiply that by 100 you get 25 (which is the temperature in C). If you saw a voltage of 0.80, that would correspond to another 5C above that (since 10 mV per C would be an additional 5C above 25C, which adds up nicely).
Here's a link to the TMP36 datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/TMP35_36_37.pdf
Hope that helps