LM35 is very unstable

Ds18b20 works but LM35 is unstable (I don't know why). The problem is not the analog (i tried to change to A5). The code looks ok...

#define pin_lm35 A0
#include <OneWire.h>
#include <DallasTemperature.h>
 
#define DS18B20_OneWire 12
 
OneWire oneWire(DS18B20_OneWire);
 
DallasTemperature sensortemp(&oneWire);
 
int ndispositivos = 0;
float grausC;
 
void setup()  {
  sensortemp.begin(); 
  Serial.begin(9600);
  
  pinMode(pin_lm35,INPUT); 

  Serial.println("Localizando Dispositivos ...");
  Serial.print("Encontrados ");
  ndispositivos = sensortemp.getDeviceCount();
  Serial.print(ndispositivos, DEC);
  Serial.println(" dispositivos.");
  Serial.println("");
}
 
void loop() { 

  float valor_analog_lm35 = float(analogRead(pin_lm35));
  float tensao = (valor_analog_lm35*5)/(1023);
  float temperatura = tensao / 0.010;

  Serial.print ("Temperatura ambiente = " " " );
  Serial.println(temperatura);
 
  
  sensortemp.requestTemperatures(); 
 
  for (int i = 0;  i < ndispositivos;  i++) {
    
    Serial.print("Sensor ");
    Serial.print(i+1);
    Serial.print(": ");
    grausC = sensortemp.getTempCByIndex(i);
    Serial.print(grausC);
    Serial.println("ºC");
  }
  
  Serial.println("");
  delay(3000);
}

Red jumper->5V
Orange jumper->GND
Green jumper(analog)->A0
Green jumper(DS18B20)->12

how unstable? +/- 2-3 points? 0-1023?

i got from AliExpress NPN transistors marked as LM35. Ali Judgement decide "for refund send goods back to China". i closed my account 4 years ago.

Several people have had problems with that sensor when using it on a breadboard.
Many times there is a poor connection inside the breadboard.
You have several wires for connections to ground and 5V, which increases the chance of a bad connection.

Connect the LM35 GND pin directly to the arduino GND using just one wire.
Connect the LM35 +Vs pin directly to the arduino 5V using just one wire.
Connect the LM35 out pin directly to the arduino A0 using just one wire.
Connect a 10uF capacitor directly across the LM35 +Vs pin and gnd pin

Make sure the LM35 feels like it's making a tight connection when you push it into the breadboard.

4 Likes

Change to the following. Also, check that the legs of the sensor are tightly engaged with the contacts of the breadboard.

  unsigned valor_analog_lm35 = analogRead(pin_lm35);
  float tensao = 100*(5/1023.0)*valor_analog_lm35;  
  Serial.print ("Temperatura ambiente =  " );
  Serial.println(tensao);

The LM35 has very limited current sink capability. It may take several read cycles to get a stable result if the temperature decreases.

Question to ChatGPT: How long time does LM35 take to respond to a changing temperature?

Answer from ChatGPT: In general, the LM35 is designed to have a fast response time due to its small size and structure. It's capable of responding to temperature changes within a fraction of a second to a few seconds. The datasheet for the LM35 typically provides information on the sensor's thermal time constant, which gives you an idea of how quickly it responds to temperature changes.

For example, the standard LM35 model has a thermal time constant of around 5-10 seconds. This means that it would take about 5-10 seconds for the sensor to respond and settle to approximately 63.2% of the new temperature value when subjected to a sudden temperature change.

Does ChatGPT's answer make sense? (I have not cross checked with LM35's data sheet.)

You should... Temperature doesn't change instantly and it takes time to heat-up (or cool-down) the chip inside the package. There are charts showing air (minutes) and oil (seconds) and in oil the plastic package is faster.

In other words. "I don't know... RTFM!" :smiley: :smiley: :smiley:

2 Likes

The problem I was describing is the inability to drive the ADC when voltage decreases. This is in addition to the thermal response. The problem is buried in one line on page 13 of the data sheet section 7.1.

Therefore the LM35 can only source current and it's sinking capability is limited to 1 μA.

Why do people think ChatGPT is even worth mentioning?

1 Like

Looking at the data sheet circuit examples it seems like they use a fairly small (200 ohms in some cases) load resistor. That should sink the higher voltage quite quickly.

To a sensible reader, the answer/comment of ChatGPT is really convincing; but, some of the answers prove to be wrong when put into experiment.

However, its delivery helps to begin whenever no answer is there from the Forum. For example: I asked Forum and ChatGPT for help/code about knowing the size of the off-chip flash of ESP32; it is the ChatGPT that extended the help/code.

Its polite to provide links to your parrts, like this:

That is a LOT of wires to connect to a three terminal device. You havent provided a schematic so we cant see what you have connected and I doint know what the R is for. Or its value.
Or where the thick black cable is going.

So ChatGPT is the excuse for not doing your own research?

To begin a research, one needs to start from somewhere -- the ChatGPT does provide some clues/hints. For example: When I asked it if it has some codes on the use of mutex primitive in ESP32 Platform, it totally fabricated Mutex.h Library and prepared a fantastic sketch for me which proved to be an un-compliable sketch; however, the false sketch pushed me to look into FreeRTOS where I found semaphore primitive to write my sketch.

You can just read the chip name on the chips plastic case....

The chip is located underneath the RF Shield (metallic cover) of ESP-WROOM-32 Module.
esp32AllFour

1 Like

So you ask ChatGPT, which essentally is a text searchengine + ELIZA, that gives you only one solution that usually is wrong. Does not sound like a good plan to me.

1 Like

It provides many alternative solutions -- some are meaningful and the rest are totally fabricated. However, it does provide some clues on advanced concepts which could be effectively used by consulting human-made documents/texts.

Don't let yourself get fooled. It does neither of it.

1 Like

You are guessing; whereas, I am telling from my practical observation.

ChatGPT has no intention to fool anyone; it always suggests to verify its delivery against authentic documentation.