Go Down

### Topic: Arduino and LM35DZ Centigrade thermistor. (Read 1 time)previous topic - next topic

#### axo95b

##### Apr 14, 2012, 06:40 am
Ok I can't figure out what im doing wrong here. I have this thermistor on a bread board I have +5v from arduino going to the +Vs I have Vout going into the Arduino analog port A0 and the ground going to arduino's ground. Here is the data sheet for the LM35DZ (http://www.ti.com/lit/ds/symlink/lm35.pdf). Here is the Code I am using to see the output.

int SensorPin =A0;
int Temp =0;

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

void loop() {
Serial.println (Temp);
delay (600);
}

Here is what I get back.

53
52
53
52
52
52
52
52
52
53
52
52
52
52

What am I doing wrong? Im just confused because a few hours ago I was working on this and it was about 65 degrees F in here and my reading was 64-63 and now Im still messing with it trying to figure out what is going on 4 hours later it is 53 degrees F roughley and It's reading this. It is like the V out is being converted to fahrenheit or something.

#### n1spx

#1
##### Apr 14, 2012, 07:20 am
the LM35 output is 10mV per degree C.  You are displaying the raw value you read, and not converting it first.

Code: [Select]
`  int Temp = analogRead(SensorPin);`

should be something like:
Code: [Select]
`  int Temp = analogRead(SensorPin) * 500 / 1024;`

or
Code: [Select]
`  int Temp = (analogRead(SensorPin)  * 900 / 1024 ) + 32;`
for Fahrenheit
That is a rearrangement of * 5 / 1024 * 100  and    (* 9 / 5) + 32

* 5 / 1024 gives the actual voltage on the pin.
* 100 converts that to the number of 10 mV steps
(* 9 / 5) + 32 converts C to F if desired

Note: as wired, you cannot measure less than 0c
Note: change 5 in the above formulas if the arduino is changed from running at 5v.

#### axo95b

#2
##### Apr 14, 2012, 07:50 am
Hey thanks for the response I have no idea where you are getting the number 1024. I took the code you gave me and put it in like this.

Quote

int SensorPin =A0;
int Temp =0;

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

void loop() {
int Temp = (analogRead(SensorPin)  * 900 / 1024 ) + 32;
Serial.println (Temp);
delay (600);
}

Now my output in the serial monitor is around 13 or 14. and My Vout is .25v ( on my multi- meter) I assume the /1024 has something to do with the resolution on the analog header but my mind cant grasp why I would divide it by the total resolution.

#### Boffin1

#3
##### Apr 14, 2012, 08:36 am
45 years of editing projects with a knife and soldering iron, then I found Arduino !

#### n1spx

#4
##### Apr 14, 2012, 06:09 pm
Quote

int SensorPin =A0;
int Temp =0;

void loop() {
int Temp = (analogRead(SensorPin)  * 900 / 1024 ) + 32;
Serial.println (Temp);
delay (600);
}

It shouldn't matter, but you are defining Temp twice.  Remove the "int" before Temp =  in the loop.

Quote

Now my output in the serial monitor is around 13 or 14.

I'm not sure why that is yet.

Quote
My Vout is .25v ( on my multi- meter)

Is your room 25C (~80F) ?

52 * 5 / 1024 = ~.254

Go Up

Please enter a valid email to subscribe