Getting inaccurate temperature readings using the LM35 and LCD display

The LM35 is BAD.
Buy a new one

I just wanted to show you a pic of my board and its connections. I am certain it is connected correctly in accordance to the schematic diagram provided on the exemplar project i was following.

It may be hard to see, but can you just confirm for me please if it looks accurate enough to you?

Can't tell. Try a picture from a different angle

It looks OK

Let do a quick test:
Remove the black wire that is connect to the center pin of the LM35 and connect it to gnd.
The LCD should read 0 degrees.

Thanks for confirming.

I think i have got it working. I think the wires are very loose and when you position them a certain way, it displays accurate enough temperatures.

i am however, getting weird symbols instead of the degrees symbol.

I changed my code to this:

#include <LiquidCrystal_I2C.h> // LCD I2C library

#define ADC_VREF_mV    5000.0 // in millivolt
#define ADC_RESOLUTION 1024.0

#define PIN_LM35 A0 // pin connected to LM35 temperature sensor

LiquidCrystal_I2C lcd(0x3F, 16, 2);  // LCD I2C address 0x27, 16 column and 2 rows

void setup() {
  Serial.begin(9600);

  lcd.init();      // initialize the lcd
  lcd.backlight(); // open the backlight
}

void loop() {
  int adcVal = analogRead(PIN_LM35);
  // convert the ADC value to voltage in millivolt
  float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
  // convert the voltage to the temperature in Celsius
  float tempC = milliVolt / 10;
  float tempF =  (tempC * 9/5) + 32; // convert Celsius to Fahrenheit

  lcd.clear();
  lcd.setCursor(0, 0); // start to print at the first row
  lcd.print(tempC);    // print the temperature in Celsius
  lcd.write((byte)223);
  lcd.print("C");
  lcd.setCursor(0, 1); // start to print at the second row
  lcd.print(tempF);   // print the temperature in Fahrenheit
  lcd.write((byte)223);
  lcd.print("F");

  

  delay(500);
}

but it hasn't inserted the degrees symbol.

unfortunately it still displays inaccurate temperatures even after removing the black wire. e.g. it now says 120 degrees.

Back in post #7 I asked you to wiggle things around to see if anything was loose.
So the LM35 is good, just put the black wire back to where ir was.

I think the code for the degree symbol is 248

The wire from the GND pin to the breadboard has the LCD current flowing through it.

This current flowing through the wiring will cause a voltage drop along the wire due to the resistance of this wire plus the contact resistance of the breadboard connections.

Thus the voltage at the LM35 GND pin will be several/many millivolts above the voltage at the Arduino GND pin, giving rise to a higher than actual temperature reading.

Connect the LM35 to it's own GND connection on the Arduino - I can see the GND pin between D13 and AREF is only about an inch away - transfer the wire from the LM35 GND pin directly to this Arduino GND pin.

I had done this a few times, it just happened to be on this occasion that it started to display the right temperatures. It seems very loose and temperamental.

It reminds me of worn out iPhone charging cables having to be at a certain position to charge.

thanks, i'll try this

A GOOD quality breadboard that won't give any problems will cost $30-$40 USD

unfortunately using 248 now just outputs an 'R' instead of the degrees symbol.

It depends on the LCD.
Try 178

According to the Winstar datasheet the code for a degree symbol is 0xDF = 223

See the character set on page 14.

@JohnLincoln I agree but it looks like it's showing the greek lettter alfa for 223

Thanks everyone for your responses.

I just wanted to ask, are these sensors generally a bit inaccurate? I have also made a temperature sensor with the TMP36 sensor. For example, I tested it this morning alongside a digital thermometer. The digital thermometer gave a reading of 20 degrees Celsius whereas the LCD on the Arduino board gave a reading of between 11-13 degrees Celsius.

Is this generally the way they are? My board seems like it is wired properly.

From TI:
0.5°C Ensured Accuracy (at 25°C)

I think we have already concluded that you have a bad breadboard.

If you solder everything together on a protoboard and you have not damaged the LM35, then you should see accurate results