Improvements in "Project 03 - Love-o-meter" - Code-Description

Hello,

a few days ago I got my Starter Kit and began with the first projects. Unfortunately I think there are two passages in the code which I would explain in a different way.

The first passage is a little mistake in the conversion of sensorVal into voltage:

// original code
float voltage = (sensorVal/1024.0) * 5.0;
// my code
float voltage = (sensorVal/1023.0) * 5.0;

I changed 1024 into 1023 because the description of the Analog-to-Digital-Converter (ADC) (page 43) says: "...Analog in pins A0-A5 can report back a value between 0-1023, which maps to a range from 0 volts to 5 volts. ..." So the maximum ADC value is 1023 and 1023/1023*5=5V.

The second passage is the conversion of voltage into temperature:

// original code
float temperature = (voltage - .5) * 100;
// my code
float 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.

The first passage is a little mistake in the conversion of sensorVal into voltage:

Nope, sorry, don't see the mistake there.
Imagine you had a one bit converter, instead of a ten bit converter.
If it reads zero, that could be interpreted as zero volts.
But what would a reading of one signify?
(No points for answering "five volts")

earstreet:
The second passage is the conversion of voltage into temperature:

// original code

float temperature = (voltage - .5) * 100;
// my code
float 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.

Hey, for it's worth, that is the exact formula I arrived at after also looking at the data sheet.

The text for this project could definitely use a better explanation of the seemingly random .5 "offset factor".

Hi
Im new here to. The offset does seem random to me to.

I have another question about this project.
My temp sensor reads a value of around 600 as soon as I turn it on. This converts to around 250 degrees for some reason. I know this is wrong. Also im not sure if the sensor can pick its own heat up because it heats up very quickly. I touched it and it was way too hot. I cant figure out the problem, I think I might need to add a resistor to it.
I did change the power supply to 3.3V and that changed the sensor value to around 160. But it was still wrong.
Can someone tell me whats wrong I followed the guide stpe by step but I can figure it out.
Thanks

At a guess you had the TMP36 connected incorrectly. And from my experience you probably need a new one.

I thought that and checked it made sure it was right and it was. you are right about needing a new one this one melted the plastic around the pins it was in.

I'd suggest looking up DS18B20 - it's a digital temperature sensor. Completely different to the TMP36 so it's not simply a plug in replacement.