Pages: [1]   Go Down
Author Topic: Improvements in "Project 03 - Love-o-meter" - Code-Description  (Read 1519 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
Code:
// 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:
// 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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26489
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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")
Logged

"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.

Pages: [1]   Go Up
Jump to: