Go Down

### Topic: Improvements in "Project 03 - Love-o-meter" - Code-Description (Read 4336 times)previous topic - next topic

#### earstreet

##### Dec 19, 2013, 09:22 pm
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: [Select]
`// original codefloat voltage = (sensorVal/1024.0) * 5.0;// my codefloat 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 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.

#### AWOL

#1
##### Dec 22, 2013, 12:43 am
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")
"Pete, it's a fool (who) 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.
I speak for myself, not Arduino.

#### image2x

#2
##### May 20, 2015, 02:20 amLast Edit: May 20, 2015, 02:22 am by image2x
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.
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".

#### ahuss

#3
##### May 20, 2015, 03:02 am
Hi
Im new here to. The offset does seem random to me to.

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

#### dannable

#4
##### May 20, 2015, 09:53 am
At a guess you had the TMP36 connected incorrectly. And from my experience you probably need a new one.
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

#### ahuss

#5
##### May 20, 2015, 04:59 pm
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.

#### dannable

#6
##### May 20, 2015, 05:43 pm
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.
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

Go Up