Pages: [1]   Go Down
Author Topic: LM35CZ reading or calculation errors  (Read 2887 times)
0 Members and 1 Guest are viewing this topic.
Cape Town, South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino Uno
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
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
Logged

Dubuque, Iowa, USA
Offline Offline
Edison Member
*
Karma: 45
Posts: 2467
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Cape Town, South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino Uno
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

« Last Edit: July 07, 2011, 11:16:35 am by milo0309 » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8690
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: