LM35 temperature giving weird output

My code:

float temp = 0;

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

void loop() {
  temp = analogRead(A0);
  temp = temp * 0.48828125;
  Serial.print("TEMPERATURE: ");
  Serial.print(temp);
  Serial.println(" *C");
  delay(1000);
}

I connected the LM35 to the analog A0, - to ground, and to 5v.
The problem is that it is giving me weird output in the serial monitor

This is the output:
16:41:13.114 -> TEMPERATURE: 8.30 *C
16:41:14.104 -> TEMPERATURE: 8.30 *C
16:41:15.104 -> TEMPERATURE: 7.81 *C
16:41:16.097 -> TEMPERATURE: 9.77 *C
16:41:17.126 -> TEMPERATURE: 13.67 *C
16:41:18.116 -> TEMPERATURE: 17.58 *C
16:41:19.112 -> TEMPERATURE: 21.97 *C
16:41:20.102 -> TEMPERATURE: 25.88 *C
16:41:21.120 -> TEMPERATURE: 29.79 *C
16:41:22.136 -> TEMPERATURE: 32.23 *C
16:41:23.122 -> TEMPERATURE: 32.71 *C
16:41:24.107 -> TEMPERATURE: 32.71 *C
16:41:25.126 -> TEMPERATURE: 32.71 *C
16:41:26.107 -> TEMPERATURE: 29.79 *C
16:41:27.122 -> TEMPERATURE: 26.86 *C
16:41:28.140 -> TEMPERATURE: 23.44 *C
16:41:29.125 -> TEMPERATURE: 19.53 *C
16:41:30.144 -> TEMPERATURE: 16.11 *C
16:41:31.129 -> TEMPERATURE: 13.18 *C
16:41:32.148 -> TEMPERATURE: 10.25 *C
16:41:33.124 -> TEMPERATURE: 8.30 *C
16:41:34.145 -> TEMPERATURE: 8.30 *C
16:41:35.127 -> TEMPERATURE: 8.30 *C
16:41:36.145 -> TEMPERATURE: 8.79 *C
16:41:37.124 -> TEMPERATURE: 9.77 *C
16:41:38.146 -> TEMPERATURE: 12.21 *C
16:41:39.139 -> TEMPERATURE: 15.63 *C
16:41:40.155 -> TEMPERATURE: 18.07 *C
16:41:41.150 -> TEMPERATURE: 21.97 *C
16:41:42.135 -> TEMPERATURE: 24.90 *C
16:41:43.150 -> TEMPERATURE: 27.83 *C
16:41:44.136 -> TEMPERATURE: 30.76 *C
16:41:45.154 -> TEMPERATURE: 32.71 *C
16:41:46.136 -> TEMPERATURE: 32.71 *C
16:41:47.158 -> TEMPERATURE: 32.71 *C
16:41:48.139 -> TEMPERATURE: 32.71 *C
16:41:49.157 -> TEMPERATURE: 32.23 *C
16:41:50.142 -> TEMPERATURE: 29.79 *C
16:41:51.158 -> TEMPERATURE: 27.34 *C
16:41:52.141 -> TEMPERATURE: 24.90 *C
16:41:53.162 -> TEMPERATURE: 22.46 *C
16:41:54.145 -> TEMPERATURE: 19.53 *C
16:41:55.162 -> TEMPERATURE: 17.09 *C
16:41:56.142 -> TEMPERATURE: 15.14 *C
16:41:57.161 -> TEMPERATURE: 13.18 *C
16:41:58.145 -> TEMPERATURE: 11.23 *C
16:41:59.165 -> TEMPERATURE: 9.28 *C
16:42:00.151 -> TEMPERATURE: 9.28 *C
16:42:01.170 -> TEMPERATURE: 8.79 *C
16:42:02.150 -> TEMPERATURE: 8.79 *C
16:42:03.162 -> TEMPERATURE: 8.30 *C
16:42:04.179 -> TEMPERATURE: 9.28 *C
16:42:05.161 -> TEMPERATURE: 9.77 *C
16:42:06.178 -> TEMPERATURE: 12.70 *C
16:42:07.162 -> TEMPERATURE: 14.65 *C
16:42:08.183 -> TEMPERATURE: 17.58 *C
16:42:09.168 -> TEMPERATURE: 19.04 *C
16:42:10.188 -> TEMPERATURE: 22.46 *C
16:42:11.171 -> TEMPERATURE: 24.41 *C
16:42:12.188 -> TEMPERATURE: 27.34 *C
16:42:13.169 -> TEMPERATURE: 29.79 *C
16:42:14.189 -> TEMPERATURE: 31.74 *C
16:42:15.172 -> TEMPERATURE: 32.71 *C
16:42:16.185 -> TEMPERATURE: 32.71 *C
16:42:17.171 -> TEMPERATURE: 32.71 *C
16:42:18.204 -> TEMPERATURE: 32.71 *C
16:42:19.203 -> TEMPERATURE: 32.71 *C
16:42:20.184 -> TEMPERATURE: 31.25 *C
16:42:21.203 -> TEMPERATURE: 28.81 *C
16:42:22.184 -> TEMPERATURE: 26.86 *C
16:42:23.197 -> TEMPERATURE: 24.41 *C
16:42:24.181 -> TEMPERATURE: 22.46 *C

As you can see there is a pattern, it keeps getting lower and higher.

Please help :smiley:

I hooked up a LM35 to my Uno and ran your code. The code runs fine. See output below.

TEMPERATURE: 23.44 *C
TEMPERATURE: 23.44 *C
TEMPERATURE: 23.44 *C
TEMPERATURE: 23.44 *C
TEMPERATURE: 24.41 *C
TEMPERATURE: 26.37 *C
TEMPERATURE: 27.34 *C
TEMPERATURE: 27.34 *C

So it is not the code. Check your connections. With the flat of the LM35 package facing you, Vcc is on the left, output in center and ground on the right.

Make sure the LM35 is connected correctly, check for loose jumpers, etc.
LM35pinout.png

LM35pinout.png

I completely replicated your picture (see my picture) and it is still showing the weird output

OP image. How to post images.

Have you tried different jumpers? Have you tried a different LM35? Try a different analog input (make sure to change the code).

I am a beginner lol, didn't know there was a difference between all these jumpers. And I only have this LM35, I just got it 2 days ago :stuck_out_tongue: Is there something different with the different colored cables?

s there something different with the different colored cables?

Not that I know of. Change jumpers in case one (or more) has a defect. It happens.

You might try a different analog input. Make sure to change the code if you do.

Was the LM35 ever connected backwards by accident?

Changed up all the jumpers, still getting this output:
17:46:25.445 -> TEMPERATURE: 31.25 *C
17:46:26.432 -> TEMPERATURE: 31.25 *C
17:46:27.422 -> TEMPERATURE: 31.25 *C
17:46:28.439 -> TEMPERATURE: 29.79 *C
17:46:29.433 -> TEMPERATURE: 28.32 *C
17:46:30.449 -> TEMPERATURE: 25.39 *C
17:46:31.434 -> TEMPERATURE: 13.67 *C
17:46:32.424 -> TEMPERATURE: 15.63 *C
17:46:33.442 -> TEMPERATURE: 10.25 *C
17:46:34.423 -> TEMPERATURE: 0.98 *C
17:46:35.448 -> TEMPERATURE: 1.46 *C
17:46:36.431 -> TEMPERATURE: 2.93 *C
17:46:37.452 -> TEMPERATURE: 3.91 *C
17:46:38.445 -> TEMPERATURE: 8.79 *C
17:46:39.442 -> TEMPERATURE: 15.14 *C
17:46:40.429 -> TEMPERATURE: 20.02 *C
17:46:41.459 -> TEMPERATURE: 25.39 *C
17:46:42.438 -> TEMPERATURE: 30.76 *C
17:46:43.450 -> TEMPERATURE: 31.25 *C
17:46:44.443 -> TEMPERATURE: 31.25 *C
17:46:45.436 -> TEMPERATURE: 30.27 *C
17:46:46.460 -> TEMPERATURE: 25.39 *C
17:46:47.443 -> TEMPERATURE: 20.51 *C
17:46:48.456 -> TEMPERATURE: 14.65 *C
17:46:49.449 -> TEMPERATURE: 8.79 *C
17:46:50.464 -> TEMPERATURE: 4.88 *C
17:46:51.454 -> TEMPERATURE: 1.46 *C
17:46:52.446 -> TEMPERATURE: 0.00 *C
17:46:53.464 -> TEMPERATURE: 0.00 *C
17:46:54.478 -> TEMPERATURE: 2.44 *C
17:46:55.456 -> TEMPERATURE: 8.30 *C

It seems that you have a bad LM35.

Do you have a potentiometer? Connect it in place of the LM35. What are the results?

Where did you get the LM35? These days there are vast numbers of counterfeits of all kinds of chips, you can only safely buy from a reputable electronics stockist, not eBay.

...and if you replace it, don't get an analogue dinosaur like the LM35 or TMP36.
There are much better factory calibrated digital temp sensors out there.
Leo..