Pages: [1]   Go Down
Author Topic: Arduino and LM35DZ Centigrade thermistor.  (Read 1048 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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() {
  int Temp = analogRead(SensorPin);
    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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the LM35 output is 10mV per degree C.  You are displaying the raw value you read, and not converting it first.

Code:
  int Temp = analogRead(SensorPin);

should be something like:
Code:
  int Temp = analogRead(SensorPin) * 500 / 1024;
for Centigrade

or
Code:
  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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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;
  //int Temp = analogRead(SensorPin);
    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.
Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

There are 1024 analog " steps" read by the analog input
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
int SensorPin =A0; 
int Temp =0;

void loop() {
  int Temp = (analogRead(SensorPin)  * 900 / 1024 ) + 32;
  //int Temp = analogRead(SensorPin);
    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) ?

Your above readings of 52-53 also equate to ~.25v.
52 * 5 / 1024 = ~.254
Logged

Pages: [1]   Go Up
Jump to: