Go Down

### Topic: Temperature Sensor LM60 (Read 5462 times)previous topic - next topic

#### Papa G

#15
##### Nov 14, 2012, 11:16 pm
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.

#### KenshinPT

#16
##### Nov 15, 2012, 01:40 am

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!!!

The code is this:

Code: [Select]
`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");     }`

#### Papa G

#17
##### Nov 15, 2012, 01:56 am
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.

#### KenshinPT

#18
##### Nov 15, 2012, 11:44 amLast Edit: Nov 15, 2012, 12:18 pm by KenshinPT Reason: 1

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

About Vin, I declared it as a double 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

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.

Go Up

Please enter a valid email to subscribe

To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy