Go Down

Topic: LM35CZ reading or calculation errors (Read 3061 times) previous topic - next topic

milo0309

Heya all,

Ive got an Arduion Uno and I've hooked up a LM35CZ +5, GRD, and Analog1.

Below is the code I'm using to produce a Celsius printout to the serial monitor

Code: [Select]

int sensorPin = A1;

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

void loop()                     
{

int reading = analogRead(sensorPin); 
float voltage = (reading * 5) / 1024.0; //voltage calculation
float temperatureC = (voltage-0.5) * 100 ;  // temp calculation (-500mV for offset)

Serial.print(voltage); Serial.println(" Volts ");
Serial.print(temperatureC); Serial.println(" degress C");
Serial.println();

delay(1000);   
}


This is the serial output

Code: [Select]

3.07 Volts
256.64 degrees C

3.07 Volts
256.64 degrees C

3.07 Volts
256.64 degrees C


Also if i put my finger on the sensor to warm it the voltage drops and the temp decreases and the opposite for cold
???

Im rather new to the Arduion and am probably missing something simple, but any guidance would be appreciated

Chagrin

Can you post a diagram or describe how you have the LM35 connected? Your results are consistent with seeing a 3V reading from the LM35 but you should not be seeing such a high value.

johnwasser

My best guess is that you have it connected incorrectly.  With the flat side facing you the pins should be: +5, output, Gnd

I also could not find the part of the datasheet that mentions the offset voltage.  The diagrams and tables seem to show that the reading only goes down to 0 unless you provide a negative current of 50 microamps to the output. Then the voltage can go to -550 millivolts but the Arduino can't read negative voltages.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

milo0309

#3
Jul 07, 2011, 06:11 pm Last Edit: Jul 07, 2011, 06:16 pm by milo0309 Reason: 1
thanks for the response,

@john, ive just had a look at the datasheet and your right about the offset. I was working off altered code and didn't double check.

ive attached a picture showing how i have the lm35 setup with my Arduino. As far as i am aware its connected correctly?? I just dont understand the high voltage output?


johnwasser

Those look like the right connections so the only other possibility is the your chip is fried.

I recommend the Maxim (formerly Dallas Semiconductor) DS18B20 thermometer chip.  You can hook as many as you want to a single pin and use the OneWire library to talk to them.  They give direct binary temperature from -55 to +125 in 16ths of a degree.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up