LM35 is not stable

hai,

i'm creating a temperature controller using peltier tec12706 and LM35...my programming should be very simple the peltier will be activated whenever the temperature is below 33c. my circuit consist of relay connected to the peltier. firstly i'm using the relay module but whenever the temperature is below 33celcius and relay is actived the LM35 reading become unstable then i change my circuit without using a relay module. circuit that consist of transistor,diode,10k resistor and 5v relay. the problem still not fixed. but when i'm try stimulated it using the same circuit and coding using proteus the system work just fine.is there something wrong with my coding? i'm using arduino uno. below is my coding. thanks in advance.

// include the library code:
#include <LiquidCrystal.h>
#define sensor 0 // Define the A0 pin as “sensor”la
#define relay 8

int Vin; // Variable to read the value from the Arduino’s pin

float Temperature; // Variable that receives the converted voltage value to temperature

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
pinMode(relay,OUTPUT);
}

void loop() {
Vin = analogRead (sensor); /* Tells the Arduino to read the pin and stores the value in “Vin” */

Temperature=(5.0Vin100.0)/1024; /* Converts the voltage value into temperature and stores it into the “Temperature” variable (in ºC)*/
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(Temperature);
lcd.print(" C");
delay(1000);
if(Temperature<33)
{
digitalWrite(relay, HIGH);
lcd.print("on");
}
else{
digitalWrite(relay, LOW);
lcd.print("off");
}
}

Please give use the circuit you are using. We need to know how it is connected and powered.

The peltier is normally used for cooling though it can also be used for heating. I would rather use a resistor for heating.

Weedpharma

The LM35 is very susceptible to interferance. You can remove most of this from the signal by simply taking a whole bunch of readings and then averaging them out.

Try adding this function at the end of your sketch, then replace your original "analogRead(sensor)" with "analogAvg(sensor)"

 int analogAvg (int sensorPin)
 {
 unsigned int total=0;
 for(int n=0; n<32; n++ )
    total += analogRead (sensorPin);
 return total/32;
 }

I know that this is a very old thread, but I thought i'd post my personal findings just in case someone else is having stability issues with the LM35s.

In my project, I use 2 of these. One for the "Room" temperature and the other for the "Radiator" temperature (home heating radiator).

To assure accuracy, I have both connected and both sitting together with a small fan blowing across them so that they both receive the exact same temperature (for testing).

I had some serious instability in the temperatures, even with doing 64 fast samples (even a test with a delay of 5).

So I did the usual things:

  • Make sure the connections are SOLID! I found that if using a bread board, nothing seems to be able to stabilize them due to the really crappy boards that are out there now. They are not tight fitting. So I soldered the LM35s and on the Nano side, using an expansion board, I screwed the wires in tight.

  • Put a 1K resistor from ground to the analog pin of each LM35. (that helped a lot)

  • In my code when sampling, I used a for loop 0 to 64. In that loop, I take the results of the sensor read and add it to an "average" variable. When the loop is done, i simply divide that average by 64 to get a more stable result.

I also found and confirmed that for some reason, using A2 was causing instability to 1 of the sensors.
I moved it to A6, moded the sketch and now it's stable.

Also, where I had them connected to the 5V rail, which could fluctuate a bit due to the Nextion screen, LEDs and KY040 encoder, I moved both of their vcc inputs to the 3.3V pin on Nano. That really helped.

With all of those things, now both are stable and showing the exact same temperature.
Very rarely now, they might jump .5 degrees, but very quickly return to the correct temperature.

These things are very sensitive.
Now for my next test, is putting on at the end of a 25 foot wire (actually, a cable with 6 wires) that will be at the Radiator, have the LM35 on it as well as send 7V to the Nano and feed 3.3V to the LM35 at this end.

Hopefully, this will work and I hope this info helps others suffering with instability of these LM35s, which, are surprisingly accurate.

2 Likes

IIRC, minimum recommended supply voltage is 4V, from the datasheet:

1 Like

The LM35 must be read with one of the internal Aref voltages (1.1volt Aref on an Uno/Nano), not with default Aref (which most tutorials do).
Only then is a stable operation and a 0.1C resolution possible.

Ground of the sensor must not be shared with other sensors/users, but must go directly to an Arduino ground pin.
Still can use a breadboard, but don't connect LM35 ground to that shared breadboard ground rail.

The above, with some smoothing code, shouldn't jump by more than 0.1C.

A much easier solution is DS18B20 sensors.
Leo..

1 Like