Analog input always 1023

I am trying to connect the LM35 temperature sensor to the pin A0, but whenever i use the analogRead() i get 1023 instead of the temperature value. can anyone help please?

Here is the code im using.

#include <LiquidCrystal.h>
LiquidCrystal lcd (8, 9, 4, 5, 6, 7);
float temp = 0;
void setup() {
   pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT); 
   lcd.begin (16, 2);
Serial.begin(9600);
}

void loop() {
digitalWrite(10,HIGH); //Turns on the Laser Pointer for accurate aiming
temp = analogRead(A0);
 temp = (temp * 500) / 1023;
  lcd.setCursor (0,0); // Display (first LCD line)
  lcd.print ("Temp = ");
  lcd.print (temp);
  lcd.print ("");
  lcd.write (0xDF); // Degree sign
  lcd.print ("C");
 Serial.println(temp);
  if(temp < 37.5){//Turns on the RGB based on the temp range
  digitalWrite(11,HIGH);
  digitalWrite(12,LOW);
  digitalWrite(13,LOW);}
  else if(37.5 <= temp < 38.5){
  digitalWrite(11,LOW);
  digitalWrite(12,HIGH);
  digitalWrite(13,LOW);}
  else if (temp >= 38.5){
  digitalWrite(11,LOW);
  digitalWrite(12,LOW);
  digitalWrite(13,HIGH);}
  
  
  delay(1000);            
  lcd.clear();
}

I dont know if the connections are correct so here is a picture of the proteus simulation

I don't know what laserpointer you're using but it probably uses more than the 40mA an Arduino Nano digital pin can drive.

BTW, your Nano isn't powered in the wiring diagram. Did you forget any other connection?

If your formula was correct, the measured temperatures all are positive. But the LM35 starts at -55°C.

I guess 1023 is a missing LM35 ground.
Check your wires/breadboard, or upload a 'real' picture of the setup.

You might want to change the LM35 part of the sketch after you have it working.
temp = (temp * 500) / 1023; // is potentially poor/unstable/inaccurate code
Leo..

pylon:
But the LM35 starts at -55°C.

:o

Have you measured the Vin to your Arduino? The 1023 lends me to believe and maximum input to your ADC. You have checked the pinout of the LM35? The code math is fine from what I can see.

Ron

Connect +Vs pin to +5 volts, GND pin to ground, wait 5 minutes for handling heat to dissipate, read the voltage between Vout pin and ground with your voltmeter, should read room temperature times 10 milliVolts. If room temperature is 25 degrees C, you should read near 250 milliVolts. If not, you may have a counterfeit (fake).
LM35pinout.png

LM35pinout.png

If room temperature is 25 degrees C, you should read near 250 milliVolts.

According to the datasheet, this is only true for a LM35D but not for a LM35.

Where did you see that in the datasheet.
They both are 10mV/°C, and have the same 0°C offset.
Leo…