Inaccurate temperature readings from TMP36

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Inaccurate temperature readings from TMP36

Postby MrGlass » Mon Aug 22, 2011 11:30 pm

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 2:50 am

Re: Inaccurate temperature readings from TMP36

Postby adafruit_support_bill » Tue Aug 23, 2011 4:56 am

Code: Select all
//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: 16017
Joined: Sat Feb 07, 2009 9:11 am

Re: Inaccurate temperature readings from TMP36

Postby scott-42 » Tue Aug 23, 2011 11:07 am

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
analogReference(INTERNAL);

Then you can read in the voltage and do the math:
Code: Select all
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 9:46 am
Location: Santa Clara, CA

Re: Inaccurate temperature readings from TMP36

Postby MrGlass » Tue Aug 23, 2011 3: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 2:50 am


Re: Inaccurate temperature readings from TMP36

Postby MrGlass » Tue Aug 23, 2011 4: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 2:50 am

Re: Inaccurate temperature readings from TMP36

Postby scott-42 » Tue Aug 23, 2011 5: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 9:46 am
Location: Santa Clara, CA

Re: Inaccurate temperature readings from TMP36

Postby duckie » Tue Aug 23, 2011 6: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: 7
Joined: Sun Jul 10, 2011 9:35 am

Re: Inaccurate temperature readings from TMP36

Postby nisongers » Mon Jun 25, 2012 10: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 9:57 pm

Re: Inaccurate temperature readings from TMP36

Postby adafruit_support_bill » Wed Jun 27, 2012 5: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: 16017
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino

Who is online

Users browsing this forum: mibignistinly and 9 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [102]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[60]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]