Pages: 1 [2]   Go Down
Author Topic: Temperature Sensor LM60  (Read 2962 times)
0 Members and 1 Guest are viewing this topic.
Dallas, TX
Offline Offline
Sr. Member
****
Karma: 10
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're right. I just simplified the equation a little more.

I get the correct answer for your hypothesis of 424 mV measured with both your equation and mine, 0. Your original question implied that you were getting an error. Did you edit your original equation or just solve it incorrectly? Anyway, the answer to your original question the way it stands now is both your code's opinion and your opinion are correct.
Logged

Portugal
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You're right. I just simplified the equation a little more.

I get the correct answer for your hypothesis of 424 mV measured with both your equation and mine, 0. Your original question implied that you were getting an error. Did you edit your original equation or just solve it incorrectly? Anyway, the answer to your original question the way it stands now is both your code's opinion and your opinion are correct.

Thank you all mates! You helped me solving the problem.

 I was doing my math wrong. I was confusing ADC readings with miliVolts!!!  smiley-red

The code is this:

Code:
void WriteTemperatureOnLCD(void)
{
   
  k++;
  if (k == 50)
  {
   Vin=0;
   temp=0;
   
   for(j=0 ; j<=49 ; j++)
    {
     samples[j] = (analogRead(analogtemp)); //Here you get a value from 0 to 1023. If Vref is 1100mV, then 1023 represents a Vin = 1023*1100/1024 = 1098.93mV.
     Vin = Vin + samples[j]*1089/1024; //Here you convert from ADC to milivolt -> Voltage = ADC*Vref/1024
    }

   Vin=Vin/50;
   Serial.println(Vin);
   lcd.setCursor(9, 0);
   lcd.print(Vin, 1);
   lcd.print("mV");
  }
 
  if (k == 100)
  {
    temp = (Vin / 6.250) + minimum;

    if ( (temp >=0) & (temp <10) )
    {
      lcd.setCursor(8, 0);
      lcd.print("   ");
      lcd.print(temp, 1);   
    }

    if ( (temp >=10) & (temp <100) )
    {
      lcd.setCursor(8, 0);
      lcd.print("  ");
      lcd.print(temp, 1);
    }
   
    if (temp >=100)
    {
      lcd.setCursor(8, 0);
      lcd.print("    Hi");
    }
   
    if ( (temp >-10) & (temp <0) )
    {
      lcd.setCursor(8, 0);
      lcd.print("  ");
      lcd.print(temp, 1);
    }
   
     if (temp <=-10)
    {
      lcd.setCursor(8, 0);
      lcd.print("    Lo");
    }

Logged

Dallas, TX
Offline Offline
Sr. Member
****
Karma: 10
Posts: 318
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sometimes it helps just to think through it out loud. You don't say what type your variable "Vin" is but if it's an integer you might want to make it an unsigned int as it could, theoretically, get larger than a regular int.
Logged

Portugal
Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sometimes it helps just to think through it out loud. You don't say what type your variable "Vin" is but if it's an integer you might want to make it an unsigned int as it could, theoretically, get larger than a regular int.

Yah! You're right smiley

About Vin, I declared it as a double smiley Temp is also a double!

About variable "samples[50]"... each sample is an integer [0 - 1023].

However, adding 50 integers and then divide all by 50 the "samples" variable could NOT be an integer.

That is, if all samples are 500 (ADC). Then the sum is 50*500 = 25000. Then, dividing all by 50, the average value is 500!!! OK, it's an integer!

But if 49 samples are 500 (ADC). and the last one is 501. The average value is  500.02 smiley

If "samples[50]" is declared as a integer, it would be rounded down to 500. But the real value is 500.02.

So, I also declared it as a double!

Thank you so much for your help!

Regards.
« Last Edit: November 15, 2012, 06:18:52 am by KenshinPT » Logged

Pages: 1 [2]   Go Up
Jump to: