LM 35 temp chip

Hi,

My code works fine but I'm curious about the LM35 analog temp chip output. It has quite a range on the output. See attachment.

Any ideas. I figure the digital chip might be better but wondering if this is normal.

It has a range of 52 to 111 degrees F. I tried two different LM35s.

Thanks,

Sid

float tempF;
#define LM35_PIN 2
unsigned long interval=1000; // the time we need to waitunsigned long previousMillis=0; // millis() returns an unsigned long.
unsigned long previousMillis=0; // millis() returns an unsigned long.

void setupLM35()
{

}

void readLM35()
{
Serial.println("*********** LM35 *********");
tempF = analogRead(LM35_PIN); //read the value from the sensor
tempF = (((5.0 * tempF * 100.0)/1024.0)*1.8)+32;
Serial.print("Temp F: ");
Serial.println(tempF); //send the data to the computer
}

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

void loop()
{
if ((unsigned long)(millis() - previousMillis) >= interval)
{ previousMillis = millis();
readLM35();
}
}

LM35 output.pdf (115 KB)

void setupLM35() 
{

}

Should there be some code in this function ?

It would be easier to read your code if it were not for the smiley in it. You did not enclose the code in code tags, hence the smiley.

I found this code and modified it somewhat. the void setupLM35() did not have any code in it. Not sure if there is supposed to be anything.

Looked all over for code tags. Looks like I need to put a #, before and after, I think.

float tempF;
#define LM35_PIN 2
unsigned long interval=1000; // the time we need to waitunsigned long previousMillis=0; // millis() returns an unsigned long.
unsigned long previousMillis=0; // millis() returns an unsigned long.

void setupLM35()
{

}

void readLM35()
{
Serial.println("*********** LM35 *********");
tempF = analogRead(LM35_PIN); //read the value from the sensor
tempF = (((5.0 * tempF * 100.0)/1024.0)*1.8)+32;
Serial.print("Temp F: ");
Serial.println(tempF); //send the data to the computer
}

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

void loop()
{
if ((unsigned long)(millis() - previousMillis) >= interval)
{ previousMillis = millis();
readLM35();
}
}

Guess I do not know how to use code tags.

Looked all over for code tags.

Not all over.
Highlight the code in the editor then click on the 7th icon from the right above the smileys. The tooltip helpfully says Code

Hi,

I highlighted code in editor. Did not see any icons or smily faces. I right clicked and saw "copy for forum". I pasted that here but now I have lots of crazy stuff in it.

Sid

float tempF;
#define LM35_PIN 2
unsigned long interval=1000; // the time we need to waitunsigned long previousMillis=0; // millis() returns an unsigned long.
unsigned long previousMillis=0; // millis() returns an unsigned long.

void setupLM35()
{

}

void readLM35()
{
Serial.println("*********** LM35 *********");
tempF = analogRead(LM35_PIN); //read the value from the sensor
tempF = (((5.0 * tempF * 100.0)/1024.0)*1.8)+32;
Serial.print("Temp F: ");
Serial.println(tempF); //send the data to the computer
}

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

void loop()
{
if ((unsigned long)(millis() - previousMillis) >= interval)
{ previousMillis = millis();
readLM35();
}
}

The editor I meant was the message editor here, not the IDE.

Copy for Forum produces gibberish, as you can see.

I just found out that using Quick reply does not give me the smiley faces or icons, only if I post a new message. I did it as a new message test just now but still get a lot of crazy stuff in the code.

When I pressed code, I got two items in brackets with the cursor in between them. I put the code between them and still got the crazy stuff.

Sorry to be a pain, I have a lot to learn.

Do it manually.
Put [code] before the code and [/code] after it but without the glow effect of course.

Thanks a lot, you have been a great help. I figured out how to use tags. The sample code I found printed out in degrees C, I changed the formula to make it read in degrees F. Seems pretty simple using this analog temperature device but the readout range is crazy.

float tempF;
#define LM35_PIN 2
unsigned long interval=1000;  // the time we need to wait unsigned long previousMillis=0; // millis() returns an unsigned long. 
unsigned long previousMillis=0; // millis() returns an unsigned long.

void setupLM35() 
{

}
 
void readLM35() 
{
  Serial.println("***********  LM35  *********");
  tempF = analogRead(LM35_PIN);           //read the value from the sensor
  tempF = (((5.0 * tempF * 100.0)/1024.0)*1.8)+32;
  Serial.print("Temp F: ");
  Serial.println(tempF);             //send the data to the computer
}
 
void setup()
{
  Serial.begin(9600);
  setupLM35();
}
 
void loop()
{
  if ((unsigned long)(millis() - previousMillis) >= interval) 
       {  previousMillis = millis(); 
          readLM35();
       }
}

tempF = (((5.0 * tempF * 100.0)/1024.0)*1.8)+32;That looks like an awfully complicated way to convert from Celsius to Fahrenheit. What is it based on ?

UKHeliBob:
tempF = (((5.0 * tempF * 100.0)/1024.0)*1.8)+32;That looks like an awfully complicated way to convert from Celsius to Fahrenheit. What is it based on ?

That looks just.... wrong. The correct conversion is:

tempC = ((tempF - 32) * 5.0) / 9.0 , or
tempF = ((tempC * 9) / 5) + 32

The above is adding 32, which is wrong.

1 degree C == 1.8 degree F

The above is mutiplying by 1.8, which is wrong

Just plugging in simple numbers (212F => 100C) gives a very incorrect result....

Regards,
Ray L.

When I was at school back in the Dark Ages I could never remember the conversion formula. I knew it involved 9/5 or 5/9 and plus or minus 32 but that was all. What I could remember was that 16C is about 61F so that if push came to shove I could work out the formula and I had a reality check by plugging in 16 or 61 to see if the answer was right.

UKHeliBob:
When I was at school back in the Dark Ages I could never remember the conversion formula. I knew it involved 9/5 or 5/9 and plus or minus 32 but that was all. What I could remember was that 16C is about 61F so that if push came to shove I could work out the formula and I had a reality check by plugging in 16 or 61 to see if the answer was right.

Yup. Pretty easy to remember, though. C degrees are larger than F degrees, so that tells you whether to use 5/9 or 9/5, depending on the direction you're converting. And, of course, F has the +32 degree offset (0C = 32 F), which you add going to F, and subtract going to C.

Regards,
Ray L.

Pretty easy to remember, though.

Agreed, it should be, but in the heat (pun intended) of an exam all bets were off for me.

0C equals 32F was handy too

9/5=1.8
add 32

I have been using this since high school, multiply by 1.8 and add 32, works fine.

I found out why I was getting a wide range in my readings. My LM35 output wire was too long acting as an antenna, increasing capacitance, etc. I soldered the LM35 right next to the Arduino pin and it works great. Good thing to know.

Thanks a lot for everyone's patience and help. It will all make me a better user.

Sid

stryzbiak:
9/5=1.8
add 32

I have been using this since high school, multiply by 1.8 and add 32, works fine.

I found out why I was getting a wide range in my readings. My LM35 output wire was too long acting as an antenna, increasing capacitance, etc. I soldered the LM35 right next to the Arduino pin and it works great. Good thing to know.

Thanks a lot for everyone's patience and help. It will all make me a better user.

Sid

First, your equation uses tempF on BOTH sides of the '='. So, as is, it is useless. Then plug in some know number, like 0C (-32F) or 100C(212F), and run through it using a calculator. The result is just wrong. I can't even figure out why the number 1024 would ever appear anywhere in a F to C or C to F conversion.

Regards,
Ray L.