Temperature display on LCD using LM35

I made a thermometer using LM35 that displays temperature on 16x2 LCD.When i power both the sensor and LCD by same supply of 5V from arduino pin the temperature is different when i only power the LM35 by 5V and check it on Serial monitor rather displaying on LCD and the difference is high as 5 °C.
Can anybody help me with this????

Not without seeing your code.

The code should use the internal 1.1volt Aref for two reasons.

  1. isolated from 5volt supply variations.
  2. five times higher resolution

Try this sketch. It uses 1.1volt Aref and averaging.
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.0; // 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
}

Why you are using analogrefference() ?What's that????

The LCD is causing a volt drop due to the current demand. Power the LCD from a separate 5V supply

Wawa:
Not without seeing your code.

The code should use the internal 1.1volt Aref for two reasons.

  1. isolated from 5volt supply variations.
  2. five times higher resolution

Try this sketch. It uses 1.1volt Aref and averaging.
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.0; // 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
}

I also have a question about this analogReference. What you do when you want to measure other analog sensor ? Because it gives me because of INTERNAL analog reference wrong measurment.

Mjafko:
I also have a question about this analogReference. What you do when you want to measure other analog sensor ? Because it gives me because of INTERNAL analog reference wrong measurment.

What analogue sensors. OP was only using one LM35.
If you use more than one type of sensor, you might not be able to use 1.1volt Aref.
Leo..

MarkDerbyshire:
The LCD is causing a volt drop due to the current demand. Power the LCD from a separate 5V supply

That thing is solved by supplying LCD with external 5V supply.....:slight_smile: Thanx..

Wawa:
Not without seeing your code.

The code should use the internal 1.1volt Aref for two reasons.

  1. isolated from 5volt supply variations.
  2. five times higher resolution

Try this sketch. It uses 1.1volt Aref and averaging.
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.0; // 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
}

Here is my code (you may find it odd)

int lm=0;//ADC reading
float temp=0;//temperature in °C

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

}

void loop() {
// put your main code here, to run repeatedly:
lm=analogRead(A0);

temp=lm0.48875855; //lm5000/1023 mv ,further dividing this by 10 as 10mv gives 1°C rise

delay(1000);
Serial.println(temp);

}

The above code does not use 1.1volt Aref, so is supply dependent (the LCD problems) and has a 5x lower resolution than this attached sketch. Sketch with averaging (post#1) is more stable though).
Leo..

// LM35 temp sensor connected to analogue input A0, +5volt and ground
void setup() {
 analogReference(INTERNAL); // use 1.1volt bandgap Aref
 Serial.begin(9600);
}
void loop() { // calibrate temp by changing the last digit(s) of 0.1039x
 Serial.println((analogRead(A0) * 0.1039), 1);
 delay(1000);
}

Wawa:
The above code does not use 1.1volt Aref, so is supply dependent (the LCD problems) and has a 5x lower resolution than this attached sketch. Sketch with averaging (post#1) is more stable though).
Leo…

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

void setup() {
analogReference(INTERNAL); // use 1.1volt bandgap Aref
Serial.begin(9600);
}
void loop() { // calibrate temp by changing the last digit(s) of 0.1039x
Serial.println((analogRead(A0) * 0.1039), 1);
delay(1000);
}

I have two questions regarding your first code

  1. T he for loop you used for temp is that you are averaging ? and if yes then how it works?
  2. What is analogrefernce() and how it is connected with ADC and resolution thing?
  1. Less temp variation if you take several readings and average them.

  2. Default Aref is the MCU supply (~5volt). 1024 A/D values (10-bit A/D) are spread over 5volt.
    Each value/step is about ~5000/1024 = 5mV. The LM35 outputs 10mV per degreeC, so temp granularity is ~0.5C.

If the internally generated ~1.1 Aref is used (code), 1024 A/D values are spread over 0-1.1volt.
Each A/D step becomes ~1100/1024 = ~1mV. Temp granularity of the LM35 changes from 0.5C to a much better 0.1C.

Temp readout depends on two things.

  1. Output voltage of the LM35
  2. Aref.
    If Aref goes down by 5%, temp display goes up by 5%.
    Supply (default Aref) is usually less stable (e.g. USB supply) than the internally generated 1.1volt Aref.
    One small problem is that each Arduino has a slightly different 1.1volt Aref (e.g. 1.074volt), so you need to calibrate.
    Leo..

david18992015:
Hi,
Here it the demo code of 1602 LCD. Maybe you may need to check again the hardware connection.

david18992015:
Hi,
Here it the demo code of 1602 LCD. Maybe you may need to check again the hardware connection.

Thanx, there is no problem in hardware but code…

Wawa:

  1. Less temp variation if you take several readings and average them.

  2. Default Aref is the MCU supply (~5volt). 1024 A/D values (10-bit A/D) are spread over 5volt.
    Each value/step is about ~5000/1024 = 5mV. The LM35 outputs 10mV per degreeC, so temp granularity is ~0.5C.

If the internally generated ~1.1 Aref is used (code), 1024 A/D values are spread over 0-1.1volt.
Each A/D step becomes ~1100/1024 = ~1mV. Temp granularity of the LM35 changes from 0.5C to a much better 0.1C.

Temp readout depends on two things.

  1. Output voltage of the LM35
  2. Aref.
    If Aref goes down by 5%, temp display goes up by 5%.
    Supply (default Aref) is usually less stable (e.g. USB supply) than the internally generated 1.1volt Aref.
    One small problem is that each Arduino has a slightly different 1.1volt Aref (e.g. 1.074volt), so you need to calibrate.
    Leo..

Thanx for all the information...