Temperature Sensor - Weird Measurements

Good evening all,

So I have a problem with the LM35z temp sensor. When I measure the sensor with a multimeter from base to ground it shows ie 270mV translated to 27 C (function given by constructor) but the serial monitor is reading 29 C. The weird part is that in the first measurement it shows 27 C but it alters after the second one.

Please read the "How to use this forum" post and follow the directions. Post your code, using code tags, and a hand drawn wiring diagram (not Fritzing).

What Serial Monitor displays :

zzz.png

  vread = analogRead(lm35dz);
  V = ( vread*(5.0)/(1023.0) ); 
  Temp = V/(0.01) ;
  Serial.println(Temp);

That's kind of normal for a Nano with a noisy input, which Arduino do you have?

V = ( vread*(5.0)/(1023.0) );

That assumes Aref is 5.0volt.
Is it?

Not all Arduinos are made the same.
Take a Nano. It's Aref is ~4.6volt on USB supply.
Leo..

Try this. Read the calibration line.
Leo…

// LM35 temp sensor connected to analogue input A0, +5volt and ground

unsigned int total; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt Aref | change to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  total = 0; // reset total
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total = total + analogRead(A0); // add each value
  }
  tempC = total * 0.001632; // Calibrate by changing the last digit(s)
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit

  Serial.print("The temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 1); // one decimal place
  Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code
}

Hello guys ,

First of all thanks for the replies. I have an arduino mega. I've come to the conclusion that the analogRead voltage is rising when I digital write to Leds . I think that the leds interrupt the analog reading process and change the measurements. When I tried to read the voltage of the sensor without using them as an indicator I had precised readings. Yet I don't know how to fix it.

Unlikely that sensor output voltage is changing when LEDs are used.
More likely that supply voltage drops.
How do you supply the Mega and the LEDs.

Returned A/D value (temp readout) depends on two things.

  1. sensor voltage.
  2. Aref voltage.

If Aref (= supply) drops, A/D value (temp) goes up.

Therefore I posted a sketch that doesn't use default Aref.
Did you try it, understand it, and read the comments.
This one is important.
analogReference(INTERNAL1V1); // this must be used for a Mega
And so is the calibration line.

Post your sketch if you're having trouble combining the two.
Leo..

I tried to use an AC adapter for power supply but still the same error occurs. I tried the sketch but again it has the same problem.

Here is the code:

void setup() {
   for (int i=0;i<7;i++)
  {
     pinMode(dishighbyte[i],OUTPUT);
     pinMode(dislowbyte[i],OUTPUT);
  }
  analogReference(INTERNAL1V1);
  
  
 
 Serial.begin(9600);
}

void loop() {
  total = 0; // reset total
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total = total + analogRead(A0); // add each value
  }
  tempC = total * 0.001632; // Calibrate by changing the last digit(s)
  firstdigit=tempC/10;
  seconddigit=tempC%10;
  for(int j=0;j<7;j++)
 {
  digitalWrite(dishighbyte[j],displaynumbers[firstdigit][j]);
  digitalWrite(dislowbyte[j],displaynumbers[seconddigit][j]);
 }
  
  Serial.println(tempC,1);
  delay(500);
}

The results are shown below.

tempreadings.png

Code doesn't compile.
I don't see which datatypes you have used.
Upload the full code.

So the problem is that the first one or two reading are slightly off, and then it stabilises.
Is that a problem?
Maybe try smoothing code.

Leo..

Finally the problem was fixed. I just reversed the connection of LEDs so that they bright with a logic 0.The microcontroller know does not require to output too much current and the whole system is working perfectly!

@Wawa

In post #6, you add 64 values to give total.

You then do

tempC = total * 0.001632; // Calibrate by changing the last digit(s)

Just curious how you came to this multiplier.

Fof

IamFof:
You then do

tempC = total * 0.001632; // Calibrate by changing the last digit(s)

Just curious how you came to this multiplier.

Just pre-calculating all the variables into one number, like here.
http://playground.arduino.cc/Main/LM35HigherResolution
Leo..

Thanks WaWa

That is what a guessed but couldn't come up with anything like your value.

Blind as a bat - I missed the analogReference(INTERNAL1V1). :o