TMP 36 Sensor readings

Hello, I have tried with 2 TMP36 sensor now as I thought the first one was faulty. I am using the code from the RedBoard SIK and simply plugging the TMP36 sensor into GND, +5V and the middle leg to A0. Polling every second I am getting this:

voltage: 2.70 deg C: 220.02 deg F: 428.04
voltage: 1.43 deg C: 92.58 deg F: 198.64
voltage: 0.21 deg C: -28.52 deg F: -19.33
voltage: 1.96 deg C: 146.29 deg F: 295.32
voltage: 2.34 deg C: 183.89 deg F: 363.00
voltage: 3.14 deg C: 264.45 deg F: 508.02
voltage: 3.60 deg C: 309.86 deg F: 589.75
voltage: 1.78 deg C: 128.22 deg F: 262.80
voltage: 2.59 deg C: 209.28 deg F: 408.70
voltage: 1.44 deg C: 94.04 deg F: 201.28
voltage: 2.97 deg C: 247.36 deg F: 477.25
voltage: 0.84 deg C: 33.98 deg F: 93.17
voltage: 3.97 deg C: 347.46 deg F: 657.43
voltage: 2.68 deg C: 217.58 deg F: 423.64
voltage: 2.41 deg C: 191.21 deg F: 376.18
voltage: 4.85 deg C: 435.35 deg F: 815.63

These readings are all over the place. I have checked the voltage coming from the Arduino and it's 5v or 3.3 volt depending on which pin I use. But stable. I have also tested the TMP36 with a multimeter and it still gives erratic readings. Any ideas as this is driving me nuts!

Thanks - Geoff

have you checked output TMP36 with multimeter after applying power to it
is it having constant output or erratic output?

Here is code:
/*
SparkFun Inventor's Kit
Example sketch 07

TEMPERATURE SENSOR

Use the "serial monitor" window to read a temperature sensor.

The TMP36 is an easy-to-use temperature sensor that outputs
a voltage that's proportional to the ambient temperature.
You can use it for all kinds of automation tasks where you'd
like to know or control the temperature of something.

More information on the sensor is available in the datasheet:

Even more exciting, we'll start using the Arduino's serial port
to send data back to your main computer! Up until now, we've
been limited to using simple LEDs for output. We'll see that
the Arduino can also easily output all kinds of text and data.

Hardware connections:

Be careful when installing the temperature sensor, as it is
almost identical to the transistors! The one you want has
a triangle logo and "TMP" in very tiny letters. The
ones you DON'T want will have "222" on them.

When looking at the flat side of the temperature sensor
with the pins down, from left to right the pins are:
5V, SIGNAL, and GND.

Connect the 5V pin to 5 Volts (5V).
Connect the SIGNAL pin to ANALOG pin 0.
Connect the GND pin to ground (GND).

This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
This code is completely free for any use.
Visit http://learn.sparkfun.com/products/2 for SIK information.
Visit http://www.arduino.cc to learn about the Arduino.

Version 2.0 6/2012 MDG
*/

// We'll use analog input 0 to measure the temperature sensor's
// signal pin.

const int temperaturePin = 0;

void setup()
{
// In this sketch, we'll use the Arduino's serial port
// to send text back to the main computer. For both sides to
// communicate properly, they need to be set to the same speed.
// We use the Serial.begin() function to initialize the port
// and set the communications speed.

// The speed is measured in bits per second, also known as
// "baud rate". 9600 is a very commonly used baud rate,
// and will transfer about 10 characters per second.

Serial.begin(9600);
}

void loop()
{
// Up to now we've only used integer ("int") values in our
// sketches. Integers are always whole numbers (0, 1, 23, etc.).
// In this sketch, we'll use floating-point values ("float").
// Floats can be fractional numbers such as 1.42, 2523.43121, etc.

// We'll declare three floating-point variables
// (We can declare multiple variables of the same type on one line:)

float voltage, degreesC, degreesF;

// First we'll measure the voltage at the analog pin. Normally
// we'd use analogRead(), which returns a number from 0 to 1023.
// Here we've written a function (further down) called
// getVoltage() that returns the true voltage (0 to 5 Volts)
// present on an analog input pin.

voltage = getVoltage(temperaturePin);

// Now we'll convert the voltage to degrees Celsius.
// This formula comes from the temperature sensor datasheet:

degreesC = (voltage - 0.5) * 100.0;

// While we're at it, let's convert degrees Celsius to Fahrenheit.
// This is the classic C to F conversion formula:

degreesF = degreesC * (9.0/5.0) + 32.0;

// Now we'll use the serial port to print these values
// to the serial monitor!

// To open the serial monitor window, upload your code,
// then click the "magnifying glass" button at the right edge
// of the Arduino IDE toolbar. The serial monitor window
// will open.

// (NOTE: remember we said that the communication speed
// must be the same on both sides. Ensure that the baud rate
// control at the bottom of the window is set to 9600. If it
// isn't, change it to 9600.)

// Also note that every time you upload a new sketch to the
// Arduino, the serial monitor window will close. It does this
// because the serial port is also used to upload code!
// When the upload is complete, you can re-open the serial
// monitor window.

// To send data from the Arduino to the serial monitor window,
// we use the Serial.print() function. You can print variables
// or text (within quotes).

Serial.print("voltage: ");
Serial.print(voltage);
Serial.print(" deg C: ");
Serial.print(degreesC);
Serial.print(" deg F: ");
Serial.println(degreesF);

// These statements will print lines of data like this:
// "voltage: 0.73 deg C: 22.75 deg F: 72.96"

// Note that all of the above statements are "print", except
// for the last one, which is "println". "Print" will output
// text to the SAME LINE, similar to building a sentence
// out of words. "Println" will insert a "carriage return"
// character at the end of whatever it prints, moving down
// to the NEXT line.

delay(1000); // repeat once per second (change as you wish!)
}

float getVoltage(int pin)
{
// This function has one input parameter, the analog pin number
// to read. You might notice that this function does not have
// "void" in front of it; this is because it returns a floating-
// point value, which is the true voltage on that pin (0 to 5V).

// You can write your own functions that take in parameters
// and return values. Here's how:

// To take in parameters, put their type and name in the
// parenthesis after the function name (see above). You can
// have multiple parameters, separated with commas.

// To return a value, put the type BEFORE the function name
// (see "float", above), and use a return() statement in your code
// to actually return the value (see below).

// If you don't need to get any parameters, you can just put
// "()" after the function name.

// If you don't need to return a value, just write "void" before
// the function name.

// Here's the return statement for this function. We're doing
// all the math we need to do within this statement:

return (analogRead(pin) * 0.004882814);

// This equation converts the 0 to 1023 value that analogRead()
// returns, into a 0.0 to 5.0 value that is the true voltage
// being read at that pin.
}

// Other things to try with this code:

// Turn on an LED if the temperature is above or below a value.

// Read that threshold value from a potentiometer - now you've
// created a thermostat!

And yes, I have tested with 2AA batteries connected to the appropriate pins. Still erratic.

you have done a dry test or tested it with your board

Both. Dry test and also on board with sketch. Dry test yields same results. Multimeter tests voltage as stable and not fluctuating.

then try this out

initialize all the variables in your code to 0

Still no luck. voltage = 0;
degreesC = 0;
degreesF = 0;

check out the below code it should give output in degree celcius , 5 volt at Vcc of tmp36

int temp_analog=A0;

void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);

}

void loop()
{
int sensor_value;
float temp;

sensor_value = analogRead(temp_analog);
temp=((5.0*sensor_value)/1024)*100;
Serial.println("Temperarure is");
Serial.println(temp);
delay(1000);

}

Done, simple code but still this silly error? My voltage is a constant 5.05 volts (multimeter hooked up to +5v and GND)

Temperarure is
99.12
Temperarure is
122.56
Temperarure is
80.08
Temperarure is
175.78
Temperarure is
200.20
Temperarure is
237.30
Temperarure is
282.71
Temperarure is
339.36
Temperarure is
393.55
Temperarure is
435.06
Temperarure is
484.38
Temperarure is
498.05
Temperarure is
499.02
Temperarure is
480.47
Temperarure is
415.53
Temperarure is
314.94
Temperarure is
196.78
Temperarure is
91.31
Temperarure is
58.11
Temperarure is
95.21
Temperarure is
201.17

Serial.println(temp_analog);
returns 14 all the time. Different temps (as above) but always 14

I have tested this code on my board it works fine ...

I think you are having some kind of hardware problem..

try with another power supply or another sensor or any hardware you can replace

It is returning pin number of A0 which is 14

This sensor is brand new today. I bought is specifically to test this! Same result.

try it out on different analog pins ...

on my board my code works fine with LM60.

do you have any other hardware interfaced to board as well..?

Board is new (1 week) and I just tried with another PC's USB cable and then a different USB cable. Same results. Do I have to use resistors? Pin A5 same.

let's do a thing try this out
you will get ADC output on serial and you can debug where your code is misbehaving
if you get erratic values of sensor_value then your ADC is misbehaving

int temp_analog=A0;

void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);

}

void loop()
{
int sensor_value;
float temp;

sensor_value = analogRead(temp_analog);
Serial.println(sensor_value);
temp=((5.0*sensor_value)/1024)*100;
Serial.println("Temperarure is");
Serial.println(temp);
delay(1000);

}

Still all over the place. How do I fix this? New board?

please post the output you are getting

Temperarure is
0.00
3
Temperarure is
1.46
4
Temperarure is
1.95
4
Temperarure is
1.95
0
Temperarure is
0.00
1
Temperarure is
0.49
3
Temperarure is
1.46
2
Temperarure is
0.98
4
Temperarure is
1.95
5
Temperarure is
2.44
4
Temperarure is
1.95
1
Temperarure is
0.49
3
Temperarure is
1.46
1
Temperarure is
0.49
4
Temperarure is
1.95
1
Temperarure is
0.49