// original codefloat voltage = (sensorVal/1024.0) * 5.0;// my codefloat voltage = (sensorVal/1023.0) * 5.0;
// original codefloat temperature = (voltage - .5) * 100;// my codefloat temperature = (voltage - .75) * 100 + 25;
The first passage is a little mistake in the conversion of sensorVal into voltage:
The second passage is the conversion of voltage into temperature:Code: [Select]// original codefloat temperature = (voltage - .5) * 100;// my codefloat temperature = (voltage - .75) * 100 + 25;The description of the TMP36-sensor says (http://arduino.cc/documents/datasheets/TEMP-TMP35_36_37.pdf):"...The TMP36 is specified from ?40°C to +125°C, provides a 750 mV output at 25°C, and operates to 125°C from a single 2.7 V supply. The TMP36 is functionally compatible with the LM50. Both the TMP35 and TMP36 have an output scale factor of 10 mV/°C. ..."That means: 0.75V=25°C, 0.76V=26°C, 0.77V=27°C, ...In my calculation I do exactly what is described in the datasheet of the sensor. The solution is the same. So it's ok but I think in a book for newbies the equations should be comprehensible.Maybe somebody can improve it in a next edition of the book.