LM34 Temp Sensor

OK i have this code

//Inializes or Defines what Pin is output for LM34 Temp Sensor

int outputpin=0;

//This sets the Ground pin to LOW and the Input Voltage Pin to HIGH

void setup()
{
Serial.begin(9600);
}

//Main Loop

void loop()
{
int rawvoltage=analogRead(outputpin);
float millivolts=(rawvoltage/1024.0)*5000;
float fahrenheit=millivolts/10;
Serial.print(fahrenheit);
Serial.print("degrees Fahrenheit,");

Serial.print((fahrenheit -32)*5/9);
Serial.println("degrees Celsius");
delay(20000);

}
Now my problem is when I had first hooked it (LM34 and Arduino Nano) up according to the PDF -Texas Instruments supplied. The GRND and the Vs were switched not my mistake! It got real hot, Thank GOd didn't Burn up my arduino, or blow the pin, so I hooked it up the other way, Opened serial window and it worked! The problem is it's not 128 degrees in my shop! So I changed the Lm34 thinking I fried that one. I had 2, so hooked it up right the first time. AND QUESS WHAT SAME THING!?!?!?!? WHAT IS WRONG PLEASE SOMEONE SAVE ME! IS the code wrong??? DId I get some wacky sensors???

ANYBODY ANY IDEAS AS TO WHAT IS WRONG!! PLEASE =(

Your raw reading should be close to 160 (at 77F)
If it is not, try filter power supply and the output
=>Datasheet says 75 Ohn series ca. 1/2 uF at output

Firstly if the package is getting hot, you must have shorted it. It uses around 200mA max of current...which would barely make an LED hot!
If it is still getting hot after removing it, it will have been damaged so I would not rely on it anyway.

A) What value is it giving you? (in the 10bit input or the actual voltage out).
B) What is the supply voltage? How are you powering the device?

 //Inializes or Defines what Pin is output for LM34 Temp Sensor

int outputpin=0;

//This sets the Ground pin to LOW and the Input Voltage Pin to HIGH

void setup()
{
  Serial.begin(9600);
}

//Main Loop

void loop()
{
  int rawvoltage=analogRead(outputpin);
  float millivolts=(rawvoltage/1024.0)*5000;
  float fahrenheit=millivolts/10;
  Serial.print(fahrenheit);
  Serial.print("degrees Fahrenheit,");
  
  Serial.print((fahrenheit -32)*5/9);
  Serial.println("degrees Celsius");
  delay(20000);
  

}

I think this code is defunct regardless.

a) It needs the sensor pin to defined as an input:
pinMode(outputpin,INPUT);

b) The line about outputpin=0; is useless. All it has done is set the int variable outputpin to equal 0. It hasn't done anything "mechanical."

c) Pin 0 is NOT an analog pin. You can not read an analog voltage from pin0. Only pins Ax (where x is a number) will work.

Regarding a and c in previous reply, no you don’t have to set the pin as an input and yes you can reference an analog pin as 0. The analogRead takes care of it realising it’s analog pin 0 not digital pin 0.

I have this in code for example, and don’t set the pin as input first:

  temp=0;
  for(byte i=0; i<5; i++)  //average 5 reads
  {
    temp=temp + analogRead(0)/2;  // should be 500/1024 but wth its close enough
    delay(100);
  }

Run this: (then what is the output=)
Then change to pin A1 , repeat

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println(analogRead(0)); // switch to other pin for verification
  delay(500);

So I know this, The first sensor I probly fried. The second sensor read the same temp as the fried sensor!WHAT?! I had it connected as such the Analog pin A0 on my Nano was goin to Vo(Volt Output) on the sensor, GND on nano to GND on sensor And I used Usb to power Nano board so the V+ on sensor went to 5v pin on board. Where I am stumped is I have seen this work on a UNO, with the same connections, and same EXACT CODE!!! I am an arduino noob, Though Trying Really hard to learn fast, Still Stumped! To those who have commented TY for being nice, and so helpful but can you DUMB it down for me :roll_eyes: Feeling Stupid