Get 12% off, TODAY ONLY 12/12 – use the code TWELVE on check out! Some restrictions apply!

Inaccurate temperature readings from TMP36
Moderators: adafruit_support_bill, adafruit

Inaccurate temperature readings from TMP36

by MrGlass on Tue Aug 23, 2011 12:30 am

I got a large box of goodies from adafruit last week, including a full ARDX kit, LCD screen, and various other odds and ends. For my first off tutorial project, I decided to build myself a simple thermostat.

I hooked up the TMP36 according to the ARDX tutorial here: http://www.oomlout.com/a/products/ardx/circ-10
And then hooked up my LCD according to the adafruit tutorial here: http://www.ladyada.net/learn/lcd/charlcd.html

I mashed up the sample code from those pages and ended up with a fairly simple sketch: http://pastie.org/private/h3eoxvac1wsdwvnlwdnpyg

The problem is I am getting some pretty erratic readings, usually ranging +/- 2 degrees Fahrenheit, sometimes spiking >10 degrees above/below the average temp. I know these aren't super accurate sensors, but I thought they were accurate to ~.1 degrees, and that is not at all what I am seeing.

Is there some method for getting a more accurate reading? Could my LCD be causing some sort of interference? my wires are pretty closely grouped together on my breadboard, and right next to the TMP36 sensor, could they be causing some interference?
MrGlass
 
Posts: 90
Joined: Tue Jun 03, 2008 3:50 am

Re: Inaccurate temperature readings from TMP36

by adafruit_support_bill on Tue Aug 23, 2011 5:56 am

Code: Select all | TOGGLE FULL SIZE
//getvoltage function
float getVoltage(int pin){
  return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range        // to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}


You are losing a some precision by doing this conversion first. When working with small-ish numbers, you want to do your multiplies before your divides.

Also you should consider taking the average of multiple readings to help filter out noise.
Breadboard wiring can be flakey too. Separate analog wires, recheck your connections and make sure all wires are well seated.
User avatar
adafruit_support_bill
 
Posts: 32597
Joined: Sat Feb 07, 2009 10:11 am

Re: Inaccurate temperature readings from TMP36

by scott-42 on Tue Aug 23, 2011 12:07 pm

I would also suggest using the lower voltage range for the analog reading if it can meet your measurement needs. This will give you a better resolution in the analog conversion.

For example, use the 1V1 reference voltage on an Arduino Uno:
Code: Select all | TOGGLE FULL SIZE
analogReference(INTERNAL);

Then you can read in the voltage and do the math:
Code: Select all | TOGGLE FULL SIZE
int sensorValue = analogRead(A0);
float voltage = (sensorValue / 1024.0) * 1.1;
float tempC = (voltage - 0.5) * 100.0;
float tempF = tempC * 1.8 + 32.0;

Using the lower voltage range will limit the upper measurable value to 60°C or 140°F. For my indoor and outdoor monitoring that was well within the expected range. If you need to measure higher values, you can always use an external voltage reference around the high end of your measurement range. For example using 1V8 will get you to 130°C or 266°F.
scott-42
 
Posts: 123
Joined: Mon May 30, 2011 10:46 am
Location: Santa Clara, CA

Re: Inaccurate temperature readings from TMP36

by MrGlass on Tue Aug 23, 2011 4:27 pm

I switched up my conversion code so that the division comes last,& rewired my breadboard so that the TMP36 is off on its own. So far, I still am getting similar results.

Scott-42: That sounds like it might be helpful. Right no I have my tmp36 hooked up to 5V. Do I need to use a diff output from my arduino?
MrGlass
 
Posts: 90
Joined: Tue Jun 03, 2008 3:50 am

Re: Inaccurate temperature readings from TMP36

by adafruit on Tue Aug 23, 2011 4:37 pm

we have a tutorial for using this sensor
http://www.ladyada.net/learn/sensors/tmp36.html
User avatar
adafruit
 
Posts: 11778
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Inaccurate temperature readings from TMP36

by MrGlass on Tue Aug 23, 2011 5:49 pm

I looked over the adafruit tutorial (thanks!), and tried using the 3.3v output as reference. It seems to be a bit more stable, though it still ranges around a bit, and will still spike >10 degrees. I guess between this and averaging reading I can get a fairly accurate reading.

In case anyone has more input about accuracy, heres my code so far: http://pastie.org/private/8y1rcaeicwxtyjevsz5nta
MrGlass
 
Posts: 90
Joined: Tue Jun 03, 2008 3:50 am

Re: Inaccurate temperature readings from TMP36

by scott-42 on Tue Aug 23, 2011 6:33 pm

MrGlass wrote:Do I need to use a diff output from my arduino?

Nope, you can use the 5V or the 3V3 output to power the sensor, it is the amount of current that is coming back that makes a difference in the measurement. If you switch to the internal 1V1 reference voltage, you are basically measuring the output of the sensor against 1V1 and it gives you a value from 0-1023. As long as your measuring temperatures within the range I previously quoted, you should get a much higher resolution reading and much more accurate.
scott-42
 
Posts: 123
Joined: Mon May 30, 2011 10:46 am
Location: Santa Clara, CA

Re: Inaccurate temperature readings from TMP36

by duckie on Tue Aug 23, 2011 7:22 pm

I have found the internal 1.1v reference to vary quite a bit over time. I am using the 3.3v for a reference and am getting good readings on several tmp 36's
Duckie
duckie
 
Posts: 11
Joined: Sun Jul 10, 2011 10:35 am

Re: Inaccurate temperature readings from TMP36

by nisongers on Mon Jun 25, 2012 11:00 pm

I am having the same problem. I just got my Arduino, TMP36 and LCD. My temps were going up and down erratically. I switched to serial output and unplugged my LCD. The temps stabalized immediately. It seems the LCD is causing noise that is effecting the TMP36. Any ideas on isolating the LCD from the TMP36?
nisongers
 
Posts: 1
Joined: Mon Jun 25, 2012 10:57 pm

Re: Inaccurate temperature readings from TMP36

by adafruit_support_bill on Wed Jun 27, 2012 6:55 am

Any ideas on isolating the LCD from the TMP36?

Keep your jumpers short and separate the LCD wires from the TMP-36 wires as much as possible. Use the 3.3v voltage reference and ground your TMP36 directly to the Arduino - don't share the ground wire with the LCD.
User avatar
adafruit_support_bill
 
Posts: 32597
Joined: Sat Feb 07, 2009 10:11 am

Re: Inaccurate temperature readings from TMP36

by nihaoma on Sun Dec 29, 2013 12:21 am

Hello,

I recently bought a TMP36. I hooked it up to a voltmeter as instructed in the website, but I'm getting innacurate readings. For room temp, I get 16.4*C (when it should be around 22*C). I compared it to an Acurite reading in various conditions (inside the fridge, etc.) and it's off 7*C to 10 *C. I used both 3.3V and 5V supply to no avail.

What are the "possibilites" of getting a defective sensor? Have you guys ever gotten a defective one?
How "sensitive" is this sensor (inner circuitry?) to drops to the floor?

I know my questions are very broad, but I would appreciate comments about your experience with this sensor.
nihaoma
 
Posts: 5
Joined: Sun Dec 29, 2013 12:12 am

Re: Inaccurate temperature readings from TMP36

by adafruit_support_bill on Sun Dec 29, 2013 7:44 am

There is some variability in all sensors. But 7 degrees is more than usual for these sensors. The first thing I would do is make sure you have fresh batteries in your meter and check it against a known source voltage. Many meters will read slightly high or low as the batteries fade and even a small voltage error can skew the temperature calculation.

Dropping a reasonable distance (e.g. from a table to the floor) should not harm the sensor. It is more likely to get damaged by a static discharge.
User avatar
adafruit_support_bill
 
Posts: 32597
Joined: Sat Feb 07, 2009 10:11 am

Re: Inaccurate temperature readings from TMP36

by nihaoma on Mon Dec 30, 2013 2:43 am

Checked my meter against my computer's USB port and my arduino's 5V, reading 5V on both.

I heard that if one touches the three leads of a sensor with one's fingers, it can damage due to static discharges. Is this true? In what ways can I damage a temperature sensor by static discharge? I've also heard that it's a good idea to store components (like a MOSFET) on a breadboard by shorting all three leads. These two ideas seem to be in conflict, can you clarify?
nihaoma
 
Posts: 5
Joined: Sun Dec 29, 2013 12:12 am

Re: Inaccurate temperature readings from TMP36

by adafruit_support_bill on Mon Dec 30, 2013 8:01 am

I heard that if one touches the three leads of a sensor with one's fingers, it can damage due to static discharges. Is this true? In what ways can I damage a temperature sensor by static discharge? I've also heard that it's a good idea to store components (like a MOSFET) on a breadboard by shorting all three leads. These two ideas seem to be in conflict, can you clarify?

Voltage is a relative thing and static charges can create very large voltage differences between two objects. If you have a static charge built up in your body (e.g. from walking across a carpeted floor) and you touch a grounded metal object, you get a shock as the charge drains from your body. If there were an electronic device in that path, it could be seriously damaged.

For example, if you have the sensor sitting on a surface and you touch one of the leads, any difference in static charge between you and that surface will flow through the sensor. To protect against that (especially in the winter months when the air is dry) it is best to work on a conductive surface such as an anti-static mat. Before touching any electronic device, first equalize the charges by touching the mat.

Standard industry practice for critical assembly work requires additional precautions such as anti-static floor mats, wrist straps and conductive shoes. See these links for more detail
http://www.nxp.com/documents/handling_i ... PTER_3.pdf
http://literature.rockwellautomation.co ... _-en-p.pdf
User avatar
adafruit_support_bill
 
Posts: 32597
Joined: Sat Feb 07, 2009 10:11 am

Re: Inaccurate temperature readings from TMP36

by aadams1278 on Sat Mar 29, 2014 3:11 pm

I am in the same situation as the others here with unstable temperature readings from the TMP36 with an LCD display. Using short leads is not going to work for my project (I need about 2 foot leads). I am using shielded wire and it has not helped. Power to the TMP36 is from the 5V arduino pin.

I have noticed something very odd. I am using the adafruit 9V 1A switching power supply. When I tried it with a 9V battery the raw readings are almost rock solid. Why would a battery vs power supply of the same voltage make a difference? I need to use a plug in power supply for this project.

Full disclosure: I am using a non-genuine arduino uno. I don't think that should make a difference because it can produce steady readings when powered via 9V battery. Is this an issue with a poor voltage regulator on the arduino or something?
aadams1278
 
Posts: 2
Joined: Sat Mar 08, 2014 6:20 pm