Reading a temperature value from a TMP36 sensor

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Reading a temperature value from a TMP36 sensor

Post by blmorris » Thu Aug 07, 2014 2:56 pm

Using the ADCs on the pyboard there will always be a 3.3/4096 factor because the ADCs use 3.3V as the reference voltage.

User avatar
JonHylands
Posts: 69
Joined: Sun Dec 29, 2013 1:33 am

Re: Reading a temperature value from a TMP36 sensor

Post by JonHylands » Thu Aug 07, 2014 4:36 pm

More specifically, the voltage that the sensor outputs is not relative to the input, so Vin is irrelevant.

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: Reading a temperature value from a TMP36 sensor

Post by UltraBob » Sun Aug 10, 2014 11:03 am

Great, that is helpful to know, but can I still obviously don't quite have a handle on it because I still have this stupid question: why on the arduino do I have to calculate with 5 volts. Is it just a matter of the the adc converting the stir ee voltage range based on a different reference voltage? Maybe I need to get busy with a multimeter to understand what's really going on?

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Reading a temperature value from a TMP36 sensor

Post by dhylands » Mon Aug 11, 2014 5:11 am

UltraBob wrote:Great, that is helpful to know, but can I still obviously don't quite have a handle on it because I still have this stupid question: why on the arduino do I have to calculate with 5 volts. Is it just a matter of the the adc converting the stir ee voltage range based on a different reference voltage? Maybe I need to get busy with a multimeter to understand what's really going on?
The 5v on the Arduino is because you're using a 5v Arduino device.

With a 5v Arduino device you get a value of 0 when 0 volts are present, and you get a value of 1023 when 5v is present.
With a 3.3v Arduino device you get a value of 0 when 0 volts are present, and you get a value of 1023 when 3.3v is present.
With the pyboard you get a value of 0 when 0 volts is present, and you get a value of 4095 when 3.3v is present.

Any voltage between 0 and max should be a linear interpolation between those end points.

A voltage of 0.5v will be read as 102 on a 5v Arduino.
A voltage of 0.5v will be read as 155 on a 3.3v Arduino.
A voltage of 0.5v will be read as 620 on a 3.3v pyboard.

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: Reading a temperature value from a TMP36 sensor

Post by UltraBob » Mon Aug 11, 2014 5:34 am

OK, I just tried to sit down with the datasheet and figure out how all this stuff reconciles, and it seems like what I suspected is true, must be true. Please correct me if this is incorrect:

25 degrees Celsius on this particular sensor is equal to 750mV and it has a scale factor of 10mV / degree Celsius.
The operating range is between -40 and 125 degC
there is a 100 degree difference between 25 and 125 so 100 * 10 = a maximum voltage output of 1.75V
the low voltage 750 - (65 * 10) = 100mV

Is it then true, that most sensors like this that report analog values via voltage range, will have a range of 100-1750mV? If not, how does the board know what the range is?

thanks!

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Reading a temperature value from a TMP36 sensor

Post by dhylands » Mon Aug 11, 2014 6:54 am

UltraBob wrote:OK, I just tried to sit down with the datasheet and figure out how all this stuff reconciles, and it seems like what I suspected is true, must be true. Please correct me if this is incorrect:

25 degrees Celsius on this particular sensor is equal to 750mV and it has a scale factor of 10mV / degree Celsius.
The operating range is between -40 and 125 degC
there is a 100 degree difference between 25 and 125 so 100 * 10 = a maximum voltage output of 1.75V
the low voltage 750 - (65 * 10) = 100mV

Is it then true, that most sensors like this that report analog values via voltage range, will have a range of 100-1750mV? If not, how does the board know what the range is?

thanks!
Every sensor is different. The board doesn't know the range.

It's up to the person wiring things up to ensure that the voltage range from the sensor fits in a suitable range for the device.

In your example, you have a range of 100mV to 1750mV, which would correspond to values of 124 thru 2171, or 2047 values over 165 degreess. This looks pretty decent (about 0.08 degree resolution).

If you want higher resolution, then you need to offset/scale the voltage so that it covers more of the 3.3v range. Something like an op-amp would be useful for this.

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: Reading a temperature value from a TMP36 sensor

Post by UltraBob » Mon Aug 11, 2014 7:25 am

OK, I think I get it now. Thanks for humoring me on the long path there. :oops:

Post Reply