Go Down

Topic: Improvements in "Project 03 - Love-o-meter" - Code-Description (Read 1 time) previous topic - next topic


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:
Code: [Select]

// 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:
Code: [Select]

// 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")
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up