I have a problem with my LM35 temperature sensor

Hi guys. I made a sensor with using LCD Screen and LM35. I connected the cables accurately. LCD and LM35 are working. But the values from LM35 have gone crazy. If i unbend a light to LM35, temperature value is increasing as well as more than 10 degrees immediately. Here is codes:

#include <LiquidCrystal.h>

LiquidCrystal lcd(7,6,5,4,3,2);
const int isiPin = A0;
int isi = 0;

void setup() {
  lcd.begin(16,2);
  lcd.clear();
}

void loop() {
  isi = analogRead(isiPin);
  isi = isi * 0.48828125;

    lcd.clear();
    lcd.print("Sicaklik: ");
    lcd.print(isi);
    delay(250);
}

There are more code than it. But i think those aren’t necessary. And other codes don’t affect LM35.

And here is a video:

Please help me

try "float isi"

An LM35 should be read with 1.1volt Aref, not with the potentially unstable default 5volt Aref.
This sketch has 1.1volt Aref and smoothing.
Read ALL comments carefully. You might have to change some things.
Leo…

// Thermometer in Celcius and Fahrenheit
// displays on serial monitor and/or LCD
// TMP35 or TMP36 temp sensor connected to Analogue input A1, 3.3volt and ground
// or LM35 temp sensor connected to A1, 5volt and ground
// TMP35 and LM35 temp range ~+2C to ~+105C
// TMP36 temp range ~-40C to ~+55C
// see line 46 for TMP35/LM35/TMP36 code selection

#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // your LCD pins could be different
byte ledPin = 10; // backlight pin
const byte numReadings = 32; // number of readings for smoothing (max 64)
int readings[numReadings]; // readings from the analogue input
byte index = 0; // index of the current reading
unsigned int total = 0; // running total
int inputPin = A1; // the pin that the sensor is connected to
float Aref = 1.0759; // temp calibration | change in small 0.000x steps to the actual Aref voltage of ---YOUR--- Arduino for accurate temp readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  //analogWrite(ledPin, 200); // optional dimming
  analogReference(INTERNAL); // use the internal ~1.1volt reference | change (INTERNAL) to (INTERNAL1V1) for a Mega
  Serial.begin(115200); // ---set the serial monitor to this value---
  lcd.begin(16, 2); // shield with 2x16 characters
  lcd.print("Thermometer"); // info text
  lcd.setCursor(0, 1); // second row
  lcd.print("0-100 Celcius");
  for (index = 0; index < numReadings; index++) { // fill the array for faster startup
    readings[index] = analogRead(inputPin);
    total = total + readings[index];
  }
  index = 0; // reset
  delay(2000); // info display time
}

void loop() {
  total = total - readings[index]; // subtract the last reading
  readings[index] = analogRead(inputPin); // one unused reading to clear ghost charge
  readings[index] = analogRead(inputPin); // read from the sensor
  total = total + readings[index]; // add the reading to the total
  index = index + 1; // advance to the next position in the array
  if (index >= numReadings) // if we're at the end of the array
    index = 0; // wrap around to the beginning

  // convert value to temp | leave only one of these two lines uncommented
  tempC = total * Aref * 0.1 / numReadings; // value to celcius conversion for TMP35 or LM35
  //tempC = total * Aref * 0.1 / numReadings - 50.0; // value to celcius conversion for TMP36

  // Celcius to Fahrenheit conversion
  tempF = tempC * 1.8 + 32;

  // print to LCD
  if (total == 1023 * numReadings) { // if overflow
    lcd.clear();
    lcd.print("---TOO HOT---");
  }
  else {
    lcd.clear();
    lcd.print(tempC, 2); // two decimal places
    lcd.setCursor(6, 0); // position 6, first row
    lcd.print("Celcius");
    lcd.setCursor(0, 1); // second row
    lcd.print(tempF, 1); // one decimal place
    lcd.setCursor(6, 1); // position 6, second row
    lcd.print("Fahrenheit");
  }

  // print to serial monitor
  Serial.print("Raw average = ");
  Serial.print(total / numReadings);
  if (total == 1023 * numReadings) {
    Serial.println("  ----too hot----");
  }
  else {
    Serial.print("   The temperature is  ");
    Serial.print(tempC, 2);
    Serial.print(" Celcius  ");
    Serial.print(tempF, 1);
    Serial.println(" Fahrenheit");
  }

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

Hi, Do some bypassing too, with all the long wires you maybe having picking up electrical noise. Place a 0.1uF Capacitor across the gnd and Vcc leads of the LM35. Place a 0.1uF Capacitor across the gnd to signal out lead of the LM35.

Tom.. :)

The problems with the LM35 come never from the code but wiring.

I guess more components are connected to the same ground wire. Never do this: LM35 must have a ground wire only for him.

Always wire ground in star mode : Arduino board is the center of the star, each component has it own radius of the star.

Don't forget copper wires do not have zero resistance and ohms law applies. The LM35 gives "only" 10 mV per degrees.

I changed its place and reconnected the cables. Also i connected GND cable to a GND pin of arduino. Now when i unbend a light, values are changing about 5 degrees. So its better then 10 degress. But to fixing it, i wrote a code. But i dont know will it work.

I just wrote the absent codes. There are of course the first codes. I tried to do: If the value increases or decreases 5 degrees, it will be written “warning” and will be showed the last value. And here is the codes:

#include <EEPROM.h> // adding EEPROM library
int isiDeger;  // adding a new integer to be last value of LM35
void setup() {

}

void loop() {
  isi = analogRead(isiPin); // it is reading A0 pin
  EEPROM.write(1, isi); // eeprom writes the last value
  isiDeger = EEPROM.read(1); // and we are making it read.
  
  if(isi >= isi - 5 || isi <= isi + 5){  // (if temperature increase or decrease 5 or more degrees)
    lcd.clear();
    lcd.print("Dikkat!");  // warning
    lcd.setCursor(0,1);  // next line
    lcd.print("Son deger: "); // last value:
    lcd.print("isiDeger");  
  }
}

Are the codes true? Thanks for all your helps.

1) Did you understand 1.1volt Aref.

2) How long do you expect the EEPROM to last. Leo..

  1. I didnt understand 1.1volt Aref. Because i couldnt your words. I can’t speak English well.

  2. I think my codes are wrong. Uh. I want that: If the measurement is more than 5 degrees or less than 5 degress, then LCD writes “Warning!”. So when a light will be unbent, LM35 will change its value but LCD will says “warning”. I wish i have been able to explain what i want to do.

Calculate,
If measurement is more 5 degrees or less 5 degrees than the last measurement then,
Lcd.write(“Warning”);

I’m sorry but i cant speak English well. And im sorry to make you fatigue.

I think i found the solution:

  1. Last measurement = Measurement // For example 15, So Last measurement and Measurement = 15
  2. Measurement = analogWrite(LM35 Pin) // Now, calculating, and for example new value is 20
  3. If (Measurement <= Last measurement + 5 || Measurement >= Last measurement - 5){ // if Measurement–>(15) is more 5 then Last measurement–>(20) or less 5 then Last measurement–>(20)
  4. lcd.write(“Warning”);

I will upload them in my main codes. I will write the results.

aatabag: 1) I didnt understand 1.1volt Aref. Because i couldnt your words. I can't speak English well.

Small steps then. Try these two sketches, and see which one gives more A/D values. Also try the light with both sketches. Leo..

void setup() {
Serial.begin(9600); // serial monitor baud rate
}

void loop() {
Serial.println(analogRead(A0)); // read the sensor
delay(100); // slow down readings
}
void setup() {
Serial.begin(9600); // serial monitor baud rate
analogReference(INTERNAL); // switch to the more stable 1.1volt Aref
}

void loop() {
Serial.println(analogRead(A0)); // read the sensor
delay(100); // slow down readings
}

First get a stable temp readout before you think of comparing a previous temp to a new temp.

Do you want to compare the measured temp with a fixed temp. Or do you want to compare a new temp to a temp from a while ago. How long ago. Put the old temp in a variable, and compare it to a new reading. Update the old temp after some time has passed (with millis).

Don't use EEPROM for that. Writing to EEPROM will burn it out in a short time.

Post the results of post#9. Leo..

I added the first code and the values in serial port screen are : 58,59,59... In Lcd: 26 degree When i unbend a light, values are changing in LCD (normally: 26, with light: 24,36,35,28..) but when i unbend a light, values aren't changing in serial port screen (still 58,59...)

Serial port and lcd without light:

|500x281 |500x281

Serial port and lcd with light:

|500x281 |500x281

I added the second code and the values in serial port screen are: 281,282,282... In Lcd: 12 degree When i unbend a light, values are changing in LCD (normally 12, with light: 13,14,11) but when i unbend a light, values aren't changing in serial port screen (still 281,282...).

Serial port and lcd without light:

|500x281 |500x281

Serial port and lcd with light:

|500x281 |500x281

Difference of between LCD and Serial Port Screen is: In serial port screen, the value is directly from LM35; but in Lcd screen, the value that from LM35 is being multiply by 0.48828125.

I see you are using map to convert to temp.
That is a bad way that looses accuracy.
Look at this sketch.
rawValue is converted to tempC with one multiplication.
tempC can then be printed directly to LCD and serial monitor.

float tempC;

void setup() {
  Serial.begin(9600); // serial monitor baud rate
  analogReference(INTERNAL); // switch to the more stable 1.1volt Aref
}

void loop() {
  tempC = analogRead(A0) * 0.1025; // calibrate temp here <<<<<<<<
  Serial.print("Sicaklik: ");
  Serial.print(tempC, 1); // one decimal place
  Serial.println("C");
  delay(1000); // slow down readings
}

Post your full code.
Leo…

Oh im sorry i didn’t say that map code belongs to LDR Light sensor :slight_smile:
Codes are Turkish. Here is the all codes with converted to English:

#include <LiquidCrystal.h>

LiquidCrystal lcd(7,6,5,4,3,2);
const int tempPin = A0;
int temp = 0;
const int ldrPin = A1;
const int buzzer = 8;
const int led = 9;
const int button1 = 10;
int button1count = 0;
int button1state = 0;
int button1last = 0;
const int button2 = 11;
int button2count = 0;
int button2state = 0;
int button2last = 0;

int C=262; // Do
int D=294; // Re
int E=330; // Mi
int F=349; // Fa
int G=392; // Sol
int A=440; // La
int B=494; // Si
int C_=523; // Do

byte ldrsymbol1[8] = 
{
   B11111,
   B01110,
   B00000,
   B00000,
   B00100,
   B00000,
   B00000,
   B00000
};
byte ldrsymbol2[8] = 
{
   B11111,
   B01110,
   B00000,
   B00100,
   B01110,
   B10001,
   B00000,
   B00000
};
byte ldrsymbol3[8] = 
{
   B11111,
   B01110,
   B00000,
   B00100,
   B01110,
   B11011,
   B10001,
   B00000
};
byte ldrsymbol4[8] = 
{
   B11111,
   B01110,
   B00000,
   B00100,
   B01110,
   B11111,
   B11011,
   B10001
};
byte tempsymbol[8]=
{
   B11100,
   B10100,
   B11100,
   B00000,
   B00000,
   B00000,
   B00000,
   B00000
};
byte enterance[8]=
{
   B11111, //1
   B10001, //2
   B01001, //3
   B11101, //4
   B11101, //5
   B01001, //6
   B10001, //7
   B11111  //8
};
byte enterance2[8]=
{
   B11111, //1
   B10001, //2
   B10010, //3
   B10111, //4
   B10111, //5
   B10010, //6
   B10001, //7
   B11111  //8
};
byte tempsymbol2[8] =  // TERMOMETER
{ 
  B01110,
  B01010,
  B01010,
  B01010,
  B01010,
  B11011,
  B10001,
  B01110
};
byte tempsymbol3[8] = 
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00010,
  B00001
};
byte tempsymbol4[8] = 
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00010,
  B00001,
  B00010,
  B00001
};
byte tempsymbol5[8] = 
{
  B00000,
  B00000,
  B00010,
  B00001,
  B00010,
  B00001,
  B00010,
  B00001
};
byte tempsymbol6[8] = 
{
  B00010,
  B00001,
  B00010,
  B00001,
  B00010,
  B00001,
  B00010,
  B00001
};
byte tempsymbol3r[8] = 
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B01000,
  B10000
};
byte tempsymbol4r[8] = 
{
  B00000,
  B00000,
  B00000,
  B00000,
  B01000,
  B10000,
  B01000,
  B10000
};
byte tempsymbol5r[8] = 
{
  B00000,
  B00000,
  B01000,
  B10000,
  B01000,
  B10000,
  B01000,
  B10000
};
byte tempsymbol6r[8] = 
{
  B01000,
  B10000,
  B01000,
  B10000,
  B01000,
  B10000,
  B01000,
  B10000
};


void setup() {
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(4,0);
  lcd.print("Program");
  lcd.setCursor(2,1);
  lcd.print("is starting "); 
  delay(2000);
  lcd.createChar(2, enterance2);
  lcd.setCursor(0,1);
  lcd.write(2);
  lcd.createChar(1, enterance);
  lcd.setCursor(15,1);
  lcd.write(1);
  delay(1000);
  lcd.clear();
}

void loop() {
  
  Serial.println(analogRead(A0)); // read the sensor
  delay(100); // slow down readings
  
  button1state = digitalRead(button1);
  button2state = digitalRead(button2);
  int ldr = analogRead(ldrPin);
  ldr = map(ldr,0 , 1023,0, 100);
  temp = analogRead(tempPin);
  temp = temp * 0.48828125;

  if(button1state != button1last) {
    button1count++;
  }
  if(button2state != button2last) {
    button2count++;
  }
  delay(50);

  button1last = button1state;
  button2last = button2state;


  if (ldr<25){
    digitalWrite(led, HIGH);
  }
  else{
    digitalWrite(led, LOW);
  }
  if (button2count % 4 == 0){
        if(temp>35 && temp<=39) {
          tone(buzzer, C);
          delay(100);
          noTone(buzzer);
          delay(50);
        }
        if(temp>39 && temp<=45) {
          tone(buzzer, E);
          delay(75);
          noTone(buzzer);
          delay(25);
        }
        if(temp>45 && temp<=49) {
          tone(buzzer, G);
          delay(50);
          noTone(buzzer);
          delay(10);
        }
        if(temp>49) {
          tone(buzzer, A);
          delay(25);
          noTone(buzzer);
          delay(10);
        }
        if(temp<=35){
          noTone(buzzer);
        }
      }
      else{
        noTone(buzzer);
      }
      
  if (button1count % 4 == 0){
    lcd.clear();
    lcd.print("Temperat: ");
    lcd.print(temp);
      if(temp<10){
        lcd.createChar(1, tempsymbol);
        lcd.setCursor(11,0);
        lcd.write(1);
      }
      else if(temp>10){
        lcd.createChar(1, tempsymbol);
        lcd.setCursor(12,0);
        lcd.write(1);
      }
      
    if(temp<=10){
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14,0);
      lcd.write(3);
    }
    if(temp<=20 && temp>10){
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14,0);
      lcd.write(3);
      lcd.createChar(4, tempsymbol3);
      lcd.createChar(5, tempsymbol3r);
      lcd.setCursor(13,0);
      lcd.write(4);
      lcd.setCursor(15,0);
      lcd.write(5);
    }
    if(temp<=30 && temp>20){
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14,0);
      lcd.write(3);
      lcd.createChar(4, tempsymbol4);
      lcd.createChar(5, tempsymbol4r);
      lcd.setCursor(13,0);
      lcd.write(4);
      lcd.setCursor(15,0);
      lcd.write(5);
    }
    if(temp<=40 && temp>30){
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14,0);
      lcd.write(3);
      lcd.createChar(4, tempsymbol5);
      lcd.createChar(5, tempsymbol5r);
      lcd.setCursor(13,0);
      lcd.write(4);
      lcd.setCursor(15,0);
      lcd.write(5);
    }
    if(temp>40){
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14,0);
      lcd.write(3);
      lcd.createChar(4, tempsymbol6);
      lcd.createChar(5, tempsymbol6r);
      lcd.setCursor(13,0);
      lcd.write(4);
      lcd.setCursor(15,0);
      lcd.write(5);
    }

    delay(250);
  }

  
  else{
    
    if(ldr<=25){
       lcd.clear();
       lcd.print("Light level:  ");
       lcd.setCursor(0,1);
       lcd.print("Dark");
       lcd.setCursor(11,1);
       lcd.print("%");
       lcd.print(ldr);
       lcd.createChar(1, ldrsymbol1);
       lcd.setCursor(15,1);
       lcd.write(1);
    }
    if(ldr<=50 && ldr>25){
       lcd.clear();
       lcd.print("Light level:  ");
       lcd.setCursor(0,1);
       lcd.print("Normal");
       lcd.setCursor(11,1);
       lcd.print("%");
       lcd.print(ldr);
       lcd.createChar(1, ldrsymbol2);
       lcd.setCursor(15,1);
       lcd.write(1);
     }
     if(ldr<=70 && ldr>50){
       lcd.clear();
       lcd.print("Light level:  ");
       lcd.setCursor(0,1);
       lcd.print("Bright");
       lcd.setCursor(11,1);
       lcd.print("%");
       lcd.print(ldr);
       lcd.createChar(1, ldrsymbol3);
       lcd.setCursor(15,1);
       lcd.write(1);
     }
     if(ldr>70){
       lcd.clear();
       lcd.print("Light level:  ");
       lcd.setCursor(0,1);
       lcd.print("Too Bright");
       lcd.setCursor(11,1);
       lcd.print("%");
       lcd.print(ldr);
       lcd.createChar(1, ldrsymbol4);
       lcd.setCursor(15,1);
       lcd.write(1);
     }
     delay(100);

  }
}

These are all of my codes with translated to English. I have checked them. There is no problem in codes. Even you can try this if you want and so you can see the problem with your eyes. If you want to do this, i can say the pins of the tools (lcd, ldr, lm35, led, buttons).

Just realised that you use an LDR on A1.
Those raw LDR readings will also change (~5x) if you enable 1.1volt Aref.

You can fix that by using a larger value pull up resistor.
And connecting the pull up resistor to 3.3volt. Not to 5volt

The LDR could also influence the reading of the temp sensor.
Use a 100n capacitor from A0 (temp sensor) to ground and a 47k or 100k resistor from A0 to ground to avoid this.

Here is the sketch with the temp changes.
Read through it. You might have to change some LCD positions.
Leo…

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
const int tempPin = A0;
float temp; // changed this to float
const int ldrPin = A1;
const int buzzer = 8;
const int led = 9;
const int button1 = 10;
int button1count = 0;
int button1state = 0;
int button1last = 0;
const int button2 = 11;
int button2count = 0;
int button2state = 0;
int button2last = 0;

int C = 262; // Do
int D = 294; // Re
int E = 330; // Mi
int F = 349; // Fa
int G = 392; // Sol
int A = 440; // La
int B = 494; // Si
int C_ = 523; // Do

byte ldrsymbol1[8] =
{
  B11111,
  B01110,
  B00000,
  B00000,
  B00100,
  B00000,
  B00000,
  B00000
};
byte ldrsymbol2[8] =
{
  B11111,
  B01110,
  B00000,
  B00100,
  B01110,
  B10001,
  B00000,
  B00000
};
byte ldrsymbol3[8] =
{
  B11111,
  B01110,
  B00000,
  B00100,
  B01110,
  B11011,
  B10001,
  B00000
};
byte ldrsymbol4[8] =
{
  B11111,
  B01110,
  B00000,
  B00100,
  B01110,
  B11111,
  B11011,
  B10001
};
byte tempsymbol[8] =
{
  B11100,
  B10100,
  B11100,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000
};
byte enterance[8] =
{
  B11111, //1
  B10001, //2
  B01001, //3
  B11101, //4
  B11101, //5
  B01001, //6
  B10001, //7
  B11111  //8
};
byte enterance2[8] =
{
  B11111, //1
  B10001, //2
  B10010, //3
  B10111, //4
  B10111, //5
  B10010, //6
  B10001, //7
  B11111  //8
};
byte tempsymbol2[8] =  // TERMOMETER
{
  B01110,
  B01010,
  B01010,
  B01010,
  B01010,
  B11011,
  B10001,
  B01110
};
byte tempsymbol3[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00010,
  B00001
};
byte tempsymbol4[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00010,
  B00001,
  B00010,
  B00001
};
byte tempsymbol5[8] =
{
  B00000,
  B00000,
  B00010,
  B00001,
  B00010,
  B00001,
  B00010,
  B00001
};
byte tempsymbol6[8] =
{
  B00010,
  B00001,
  B00010,
  B00001,
  B00010,
  B00001,
  B00010,
  B00001
};
byte tempsymbol3r[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000,
  B01000,
  B10000
};
byte tempsymbol4r[8] =
{
  B00000,
  B00000,
  B00000,
  B00000,
  B01000,
  B10000,
  B01000,
  B10000
};
byte tempsymbol5r[8] =
{
  B00000,
  B00000,
  B01000,
  B10000,
  B01000,
  B10000,
  B01000,
  B10000
};
byte tempsymbol6r[8] =
{
  B01000,
  B10000,
  B01000,
  B10000,
  B01000,
  B10000,
  B01000,
  B10000
};


void setup() {
  analogReference(INTERNAL); // switch to the more stable 1.1volt Aref
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(4, 0);
  lcd.print("Program");
  lcd.setCursor(2, 1);
  lcd.print("is starting ");
  delay(2000);
  lcd.createChar(2, enterance2);
  lcd.setCursor(0, 1);
  lcd.write(2);
  lcd.createChar(1, enterance);
  lcd.setCursor(15, 1);
  lcd.write(1);
  delay(1000);
  lcd.clear();
}

void loop() {
  button1state = digitalRead(button1);
  button2state = digitalRead(button2);
  int ldr = analogRead(ldrPin);
  ldr = map(ldr, 0 , 1023, 0, 100);
  
  temp = analogRead(A0); // dummy read
  temp = analogRead(A0) * 0.1025; // calibrate temp here <<<<<<<<
  Serial.print("Sicaklik: ");
  Serial.print(temp, 1); // one decimal place
  Serial.println("C");

  if (button1state != button1last) {
    button1count++;
  }
  if (button2state != button2last) {
    button2count++;
  }
  delay(50);

  button1last = button1state;
  button2last = button2state;


  if (ldr < 25) {
    digitalWrite(led, HIGH);
  }
  else {
    digitalWrite(led, LOW);
  }
  if (button2count % 4 == 0) {
    if (temp > 35.0 && temp <= 39.0) {
      tone(buzzer, C);
      delay(100);
      noTone(buzzer);
      delay(50);
    }
    if (temp > 39.0 && temp <= 45.0) {
      tone(buzzer, E);
      delay(75);
      noTone(buzzer);
      delay(25);
    }
    if (temp > 45.0 && temp <= 49.0) {
      tone(buzzer, G);
      delay(50);
      noTone(buzzer);
      delay(10);
    }
    if (temp > 49.0) {
      tone(buzzer, A);
      delay(25);
      noTone(buzzer);
      delay(10);
    }
    if (temp <= 35.0) {
      noTone(buzzer);
    }
  }
  else {
    noTone(buzzer);
  }

  if (button1count % 4 == 0) {
    lcd.clear();
    lcd.print("Temperat: ");
    lcd.print(temp, 1); // temp with one decimal place
    if (temp < 10.0) {
      lcd.createChar(1, tempsymbol);
      lcd.setCursor(11, 0); // might have to change these positions <<<
      lcd.write(1);
    }
    else if (temp > 10.0) {
      lcd.createChar(1, tempsymbol);
      lcd.setCursor(12, 0);
      lcd.write(1);
    }

    if (temp <= 10.0) {
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14, 0);
      lcd.write(3);
    }
    if (temp <= 20.0 && temp > 10.0) {
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14, 0);
      lcd.write(3);
      lcd.createChar(4, tempsymbol3);
      lcd.createChar(5, tempsymbol3r);
      lcd.setCursor(13, 0);
      lcd.write(4);
      lcd.setCursor(15, 0);
      lcd.write(5);
    }
    if (temp <= 30.0 && temp > 20.0) {
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14, 0);
      lcd.write(3);
      lcd.createChar(4, tempsymbol4);
      lcd.createChar(5, tempsymbol4r);
      lcd.setCursor(13, 0);
      lcd.write(4);
      lcd.setCursor(15, 0);
      lcd.write(5);
    }
    if (temp <= 40.0 && temp > 30.0) {
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14, 0);
      lcd.write(3);
      lcd.createChar(4, tempsymbol5);
      lcd.createChar(5, tempsymbol5r);
      lcd.setCursor(13, 0);
      lcd.write(4);
      lcd.setCursor(15, 0);
      lcd.write(5);
    }
    if (temp > 40.0) {
      lcd.createChar(3, tempsymbol2);
      lcd.setCursor(14, 0);
      lcd.write(3);
      lcd.createChar(4, tempsymbol6);
      lcd.createChar(5, tempsymbol6r);
      lcd.setCursor(13, 0);
      lcd.write(4);
      lcd.setCursor(15, 0);
      lcd.write(5);
    }

    delay(250);
  }


  else {

    if (ldr <= 25) {
      lcd.clear();
      lcd.print("Light level:  ");
      lcd.setCursor(0, 1);
      lcd.print("Dark");
      lcd.setCursor(11, 1);
      lcd.print("%");
      lcd.print(ldr);
      lcd.createChar(1, ldrsymbol1);
      lcd.setCursor(15, 1);
      lcd.write(1);
    }
    if (ldr <= 50 && ldr > 25) {
      lcd.clear();
      lcd.print("Light level:  ");
      lcd.setCursor(0, 1);
      lcd.print("Normal");
      lcd.setCursor(11, 1);
      lcd.print("%");
      lcd.print(ldr);
      lcd.createChar(1, ldrsymbol2);
      lcd.setCursor(15, 1);
      lcd.write(1);
    }
    if (ldr <= 70 && ldr > 50) {
      lcd.clear();
      lcd.print("Light level:  ");
      lcd.setCursor(0, 1);
      lcd.print("Bright");
      lcd.setCursor(11, 1);
      lcd.print("%");
      lcd.print(ldr);
      lcd.createChar(1, ldrsymbol3);
      lcd.setCursor(15, 1);
      lcd.write(1);
    }
    if (ldr > 70) {
      lcd.clear();
      lcd.print("Light level:  ");
      lcd.setCursor(0, 1);
      lcd.print("Too Bright");
      lcd.setCursor(11, 1);
      lcd.print("%");
      lcd.print(ldr);
      lcd.createChar(1, ldrsymbol4);
      lcd.setCursor(15, 1);
      lcd.write(1);
    }
    delay(100);

  }
}

OH finally.. THANK YOU

The problem was the LDR. When i removed the LDR, LM35 began to work without any problem.

As i understand it, i need 100n capacitor and 47k or 100k resistor to use LDR and LM35 at the same time.

And when i change the codes, there is no problem.

You used so much your time to fix my problem.

Thank you, Adem