LM35 fluctuating between 30-33 degrees, then dropping to 0 degrees

hi, singaporean student here. Doing a project for school but can't seem to get this right. using an LM35 temperature sensor to detect air temp, microcontroller is Arduino Uno. 5v power source is usb from my Macbook air to the uno, pins from left to right are 5v, analog pin A1, and ground. switched between 3 lm35s but all seem to have the same issue. there are various components connected but specifically used the code for only temp sensor. the deadline is soon so someone please help me solve this issue :frowning:

code is below here

int raw = 0;
float temp = 0;

void setup() {
    Serial.begin(9600);
    pinMode( A1, INPUT );
}
void loop() {
    raw = analogRead(A1);
    temp = (raw/1023.0 )*5.0*1000/10;
    Serial.println(temp);
    delay(1000); 
}

this is the image of the output

I can provide pictures of circuit if needed

If you are going to post a picture of the circuit then please make sure that all the connections are clear to see

A picture of a hand drawn schematic would be even better

The output suddenly dropping off to zero is likely to be due to an intermittent connection somewhere in your circuit.

is this clear enough?

should be

temp = (raw/1024.0 )*5.0*100;

but that is not your problem

good to know anyway thx

Does it always just print 6 good temperatures then go to zero or is it different everytime you start the UNO?

Hi, @gamefluf102
Welcome to the forum.

Where did you purchase your LM35 sensors?

The fact that you have a falling temperature reading with no change in temperature at the sensor tends to think you may have counterfeit components.

Tom... :smiley: :+1: :coffee: :australia:

ill check when im back at the lab on Monday, but I've used several different codes from different sources and all of them give me similar outputs, such as a 8-10 good values then drops to 0

oops I got mine from this website called shopee, possible scam...

anyway thx for the accurate article, will definitely test out the sensor first then follow this guys advice, thx tom!

Looks like you are powering the LM34 with 3.3V, 4V is minimum, power it with 5V.

I think it is connected to the 5V pin, and that it is a parallax error that make the red wire line up with the 3.3V text.

You can verify this by counting the unused pins.

You're prob'ly right.

yes its connected to 5v. However, I read that I should power the circuit with a more stable power source like a dc power supply and not rely on the usb from the computers power. is this true? or the computer is good enough

all good, finally got it to work! output shows constant temperature and increases and decreases as I hold on to the sensor and let go! thx for all your help!

Hi, @gamefluf102

Good to hear.
Now in the spirit of the forum, please tell us all the things you had to do to fix your problem.

Along with a schematic.
An image of a hand drawn schematic will be fine, include ALL power supplies, component names and pin labels.

This is so the thread can be of assistance to others who may have a similar problem.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

I was also about to give up thinking I got a cheap fake knock off part, but it wasn't.

I got it to work in the end after an hour or so.

I disconnected everything except the LM35 sensor, then noticed in the Serial Monitor that the sensor reading values were now stable, and no longer fluctuating randomly up or down.

In my case the culprit was the LCD.
I had a single ground to the bread board, and both the LM35 and LCD was connected to it.
I disconnected the ground of the LCD from the bread board, then connected directly to another GND in the Adruino.

Boom, LCD was now displaying the correct temperature stably.

Hope this helps others.

I have posted the requirement to give an LM35 it's own ground maybe 100 times on this forum over the last years. If you had done a search, you would have found it.

You would also have found that code with analogReference(INTERNAL); in setup() gives you a supply voltage independent readout and a 5 times higher temp resolution. Only with that you can have a stable one decimal place readout.
Basic example attached.
Leo..

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

void loop() {
  float tempC = analogRead(A0) * 0.1039;
  Serial.print(tempC, 1);
  Serial.println(" C");
  delay(1000);
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.