The sensor as a very big error.... I know that!!!
But when the ADC reads (right or wrong) 424mV ... Which temperature reading shoud I get?
In my oppinion: 0ºC
In my code oppinion: -4ºC
And in your oppinion?
To conclude, in my oppinion, if the ADC reads 424mV... whatever the error the sensor and/or Vref has, the temperature should follow the formula and point to 0ºC !! Or not?
MarkT:
We need to see all the code - for instance is Vin declared as "int" or "unsigned int" or "long" or what?
const int analogtemp=6; // This is the analog pin which is measuring the input voltage from the LM60 temperature sensor
double temp=0, Vin=0, samples[50];
double minimum = (-424.0/6.25);
MarkT:
And how is this wired up? long cables? Power source?
It's wired correctly, regular cables and USB powered.
MarkT:
Have you checked the accuracy specification for the sensor?
The accuracy here is irrelevant... If I measure a wrong value but if the ADC says it's 424mV the temperature in the LCD (after formula calculation) should be 0ºC, right? And it's not! It's -4ºC.
MarkT:
Have you calibrated analogRead() with a known voltage?
I used the internal reference without any calibration. My multimeter says that Vref is 1088mV, instead of 1100mV.
Yah, I know the sensor has error but for this issue is irrelevant, I think
The error in the sensor is for this example: The real temperature is 0ºC, but the ADC is measuring 580mV, then the LCD shows 25ºC.
The measured -4°C should be correct.
Reason: The reference voltage for the AD converter has been defined by yourself with 1100mV.
According to the datasheet of the sensor, the voltage which will be provided by the sensor at +125°C will be 1205mV (1205mV > VRef).
The maximum voltage which will be converted by the ADC is 1100mV. In case you will set 1205mV on the ADC pin, I would expect that there will be an overflow in the µC. Due to that the reference voltage has not been adapted to the max sensor voltage, you will get a lower temparetaure as expected.
Also the behaviour U=f(T) of the sensor is not linear according the reference points you mentioned from the datasheet.
The measured -4°C should be correct.
Reason: The reference voltage for the AD converter has been defined by yourself with 1100mV.
According to the datasheet of the sensor, the voltage which will be provided by the sensor at +125°C will be 1205mV (1205mV > VRef).
The maximum voltage which will be converted by the ADC is 1100mV. In case you will set 1205mV on the ADC pin, I would expect that there will be an overflow in the µC. Due to that the reference voltage has not been adapted to the max sensor voltage, you will get a lower temparetaure as expected.
Also the behaviour U=f(T) of the sensor is not linear according the reference points you mentioned from the datasheet.
I agree with you, I am using Vref = 1100mV but the real value is 1088 (assuming my multimeter is correct).
But, to explain the real problem, imagine this:
Forget the LM60.
I use my stable power supply, and adjust the ouput voltage with the help of my multimeter to 424mV.
Then I apply that voltage to the analog input.
The real voltage is 424mV. The ADC has error (because of Vref) and measures 400mV.
So far so good.
But, then I use the formula to convert from voltage do temperature:
KenshinPT, I believe the problem you are seeing is in your equation. To get the correct answer, you must subtract the offset from your mv reading before you divide it by 6.25.
An adc reading of X would translate into 1100/1023*X=?
Thanks
There are 1024 intervals in a 10 bit ADC, right?
So:
if V=1100mV -> ADC=1023
and
if V= 0.000mV -> ADC=0
Thanks
For a 10-bit ADC with an 1100 mV reference, the most you can measure without saturating the ADC would be (1100 mV - 1100/1024 mV) = 1098.9 mV.
In other words, a reading of 1023 from your ADC equals (1023 * 1100/1024 mV) equals 1098.9 mV. Remember, 10 bits can only represent a value as large as
b1111111111 or decimal 1023.
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.
PapaG:
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:
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");
}
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.
PapaG:
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.