LM35 temperature sensor and Arduino Nano

Hi everyone! I know that there are plenty of tutorials what teach how this little sensor works. I have now watched two days different tutorials and topics, without solutions. Something is still wrong..

I have tried to power that many ways. Arduino own 5V, Stable 5V (from 9V step down to 5V). I have tried many scripts but all my temperatures have been between 100-500 degree. (Should be 24)

I check the datasheet may times that the wiring is ok + I have tried four different sensor and all of them gives just random values

So do you have any idea where I can continue the troubleshooting?

Current setup:
9V battery -> Stepdown 5V
Arduino nano get the power from battery + USB
Short wiring in breadboard.

Voltmeter shows:
9V battery -> 8.70V
After Stepdown -> 5V
+Vs + GND -> 4.997V
GND + Vout -> 0.034V to 0.108V (I think this should be 0.25V? but it's not..?(And even I make it cooler or warmer I don't see any logic how the voltage should change))

When I connect LM35 to analoguepin0 and run ReadAnalogVoltage script. I will got results 2.09V to 1.18V or AnalogRedSerial gives values 181 to 453. There is no sense how it jumps.

What causes this? Power source gives stable 5V to Arduino and LM35, but still somehow the voltage jumps?

The last code what I have used is from Adafruit

//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures
 
/*
 * setup() - this function runs once when you turn your Arduino on
 * We initialize the serial connection with the computer
 */
void setup()
{
  Serial.begin(9600);  //Start the serial connection with the computer
                       //to view the result open the serial monitor 
}
 
void loop()                     // run over and over again
{
 //getting the voltage reading from the temperature sensor
 int reading = analogRead(sensorPin);  
 
 // converting that reading to voltage, for 3.3v arduino use 3.3
 float voltage = reading * 5.0;
 voltage /= 1024.0; 
 
 // print out the voltage
 Serial.print(voltage); Serial.println(" volts");
 
 // now print out the temperature
 float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((voltage - 500mV) times 100)
 Serial.print(temperatureC); Serial.println(" degrees C");
 
 // now convert to Fahrenheit
 float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
 Serial.print(temperatureF); Serial.println(" degrees F");
 
 delay(1000);                                     //waiting a second
}

I attached two pictures from different setups, none of those are working..

Thank you for you time if you have any clue where I should continue troubleshooting

  • Jay Salonen

Hi Jay,

I'm not sure of your setup, but those LM temp sensors have always been VERY unstable for me. If you look online, you'll see a lot of suggestions to filter the input power with capacitors. I've followed that advice that with only minimal success. I've usually just ended up reporting the running average.

You use an LM35, but you post a sketch for a TMP36.
This sketch should work for an LM35.
Leo..

// LM35 temp sensor connected to analogue input A0, +5volt and ground

unsigned int total; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit

void setup() {
  analogReference(INTERNAL); // use the internal ~1.1volt Aref | change to (INTERNAL1V1) for a Mega
  Serial.begin(9600);
}

void loop() {
  total = 0; // reset total
  for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
    total = total + analogRead(A0); // add each value
  }
  tempC = total * 0.001632; // Calibrate by changing the last digit(s)
  tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit

  Serial.print("The temperature is  ");
  Serial.print(tempC, 1); // one decimal place
  Serial.print(" Celcius  ");
  Serial.print(tempF, 1); // one decimal place
  Serial.println(" Fahrenheit");

  delay(1000); // use a non-blocking delay when combined with other code
}

Here's an LM35 + Nano sketch I wrote, with smoothing, the LM35 is "naked", no caps or resistors. I include a monitor copy showing the output at 1 second interval, you can see where I put my finger on it for a few seconds.
Columns are: raw ADC, sum of 8 samples, temp C, temp F.

/*
 LM35 thermometer, no floats, no delays

  http://www.ti.com/lit/gpn/lm35
*/


const byte sampleBin = 8, // number of samples for smoothing
           aInPin = A0;

const int fudge = 170; // adjust for calibration 

const int kAref = 1090, // analog ref voltage * 1000
          kSampleBin = sampleBin * 1000,
          tEnd = 2000; // update time in mS
int tempC,
    tempF;
    
uint32_t total,  // sum of samples
         tStart; // timer start

void setup()
{
  Serial.begin(9600);
  analogReference(INTERNAL); // use 1.1V internal ref
  analogRead(aInPin);
  for(int i = 0;i < sampleBin;i++) // for smoothing, fill total
    total += analogRead(aInPin);   // with sampleBin * current
                                   // reading
}
void loop()
{
  if(millis() - tStart > tEnd)
  {
    tStart = millis(); // reset timer 
    total -= (total / sampleBin); // make room for new reading
    total += analogRead(aInPin); // add new reading
    tempC = total * kAref / (kSampleBin + fudge);
    tempF = (tempC * 18 + 3200) / 10;
    Serial.print(analogRead(aInPin));
    Serial.print("\t");
    Serial.print(total); // sum of samples
    Serial.print("\t");
    prntTemp(tempC);
    prntTemp(tempF);
    Serial.println();
  }
}
    
void prntTemp(int temp){
  Serial.print(temp / 10); // whole degrees
  Serial.print(".");
  Serial.print(temp % 10); // tenths
  Serial.print("\t");
}

Output:

256 2048 27.3 81.1 
256 2047 27.3 81.1 
257 2049 27.3 81.1 
256 2049 27.3 81.1 
257 2049 27.3 81.1 
257 2050 27.3 81.1 
257 2051 27.3 81.1 
258 2052 27.3 81.1 
260 2055 27.4 81.3 
265 2062 27.5 81.5 
266 2072 27.6 81.6 
271 2084 27.8 82.0 
272 2095 27.9 82.2 
273 2106 28.0 82.4 
274 2116 28.2 82.7 
275 2126 28.3 82.9 
277 2137 28.5 83.3 
277 2148 28.6 83.4 
278 2159 28.8 83.8 
279 2169 28.9 84.0 
280 2180 29.0 84.2 
279 2187 29.1 84.3 
278 2191 29.2 84.5 
277 2194 29.2 84.5 
276 2195 29.2 84.5 
274 2196 29.2 84.5 
274 2196 29.2 84.5 
273 2195 29.2 84.5 
271 2193 29.2 84.5 
270 2190 29.2 84.5 
270 2188 29.1 84.3 
269 2184 29.1 84.3 
268 2181 29.0 84.2 
268 2177 29.0 84.2 
267 2172 28.9 84.0 
267 2168 28.9 84.0 
266 2163 28.8 83.8 
267 2158 28.7 83.6 
265 2154 28.7 83.6 
265 2150 28.6 83.4 
265 2147 28.6 83.4 
264 2145 28.6 83.4 
265 2141 28.5 83.3 
263 2138 28.5 83.3 
263 2134 28.4 83.1 
263 2133 28.4 83.1 
263 2130 28.4 83.1 
262 2126 28.3 82.9 
262 2124 28.3 82.9 
262 2122 28.3 82.9 
262 2118 28.2 82.7 
261 2116 28.2 82.7 
262 2113 28.1 82.5 
260 2109 28.1 82.5 
261 2106 28.0 82.4 
259 2104 28.0 82.4 
262 2101 28.0 82.4 
260 2099 28.0 82.4 
260 2096 27.9 82.2 
260 2093 27.9 82.2 
259 2091 27.8 82.0 
260 2090 27.8 82.0 
259 2087 27.8 82.0 
260 2087 27.8 82.0 
259 2085 27.8 82.0 
260 2085 27.8 82.0 
260 2084 27.8 82.0 
259 2083 27.7 81.8 
261 2082 27.7 81.8 
259 2081 27.7 81.8 
259 2080 27.7 81.8 
258 2077 27.7 81.8 
261 2077 27.7 81.8 
259 2077 27.7 81.8 
259 2077 27.7 81.8 
260 2077 27.7 81.8 
259 2077 27.7 81.8 
258 2076 27.6 81.6 
259 2076 27.6 81.6 
258 2076 27.6 81.6 
259 2075 27.6 81.6 
259 2075 27.6 81.6 
259 2075 27.6 81.6 
259 2074 27.6 81.6 
259 2076 27.6 81.6 
258 2076 27.6 81.6 
258 2076 27.6 81.6 
258 2076 27.6 81.6 
259 2076 27.6 81.6 
258 2075 27.6 81.6 
258 2075 27.6 81.6 
258 2074 27.6 81.6 
259 2075 27.6 81.6 
258 2074 27.6 81.6 
260 2073 27.6 81.6 
258 2072 27.6 81.6 
258 2071 27.6 81.6 
258 2071 27.6 81.6 
258 2072 27.6 81.6 
259 2071 27.6 81.6 
256 2071 27.6 81.6 
257 2071 27.6 81.6 
257 2071 27.6 81.6 
257 2071 27.6 81.6 
258 2071 27.6 81.6 
257 2070 27.6 81.6 
257 2070 27.6 81.6 
257 2070 27.6 81.6 
257 2071 27.6 81.6 
258 2071 27.6 81.6 
259 2070 27.6 81.6 
257 2069 27.6 81.6 
257 2069 27.6 81.6 
258 2068 27.5 81.5 
259 2068 27.5 81.5 
258 2068 27.5 81.5 
257 2067 27.5 81.5 
257 2067 27.5 81.5 
257 2066 27.5 81.5 
258 2065 27.5 81.5 
257 2065 27.5 81.5 
257 2064 27.5 81.5 
257 2064 27.5 81.5 
257 2064 27.5 81.5 
258 2065 27.5 81.5 
257 2064 27.5 81.5 
257 2063 27.5 81.5 
256 2063 27.5 81.5 
259 2064 27.5 81.5 
257 2063 27.5 81.5 
256 2064 27.5 81.5 
257 2062 27.5 81.5 
258 2063 27.5 81.5 
257 2063 27.5 81.5 
258 2064 27.5 81.5 
258 2063 27.5 81.5 
258 2063 27.5 81.5 
257 2064 27.5 81.5 
257 2063 27.5 81.5 
257 2063 27.5 81.5 
257 2064 27.5 81.5 
256 2062 27.5 81.5 
259 2061 27.4 81.3 
258 2060 27.4 81.3 
257 2059 27.4 81.3 
257 2058 27.4 81.3 
258 2058 27.4 81.3 
256 2057 27.4 81.3 
257 2057 27.4 81.3 
256 2056 27.4 81.3 
256 2056 27.4 81.3 
256 2056 27.4 81.3 
257 2056 27.4 81.3 
258 2056 27.4 81.3 
257 2055 27.4 81.3 
258 2056 27.4 81.3 
256 2054 27.4 81.3 
257 2054 27.4 81.3 
257 2055 27.4 81.3 
258 2055 27.4 81.3 
256 2057 27.4 81.3 
256 2057 27.4 81.3 
257 2057 27.4 81.3 
255 2056 27.4 81.3 
256 2057 27.4 81.3 
256 2056 27.4 81.3 
257 2056 27.4 81.3 
256 2056 27.4 81.3 
256 2056 27.4 81.3 
256 2055 27.4 81.3 
256 2056 27.4 81.3 
257 2055 27.4 81.3 
256 2055 27.4 81.3 
257 2055 27.4 81.3 
257 2055 27.4 81.3 
256 2056 27.4 81.3 
257 2056 27.4 81.3 
256 2055 27.4 81.3 
256 2055 27.4 81.3 
256 2055 27.4 81.3 
257 2056 27.4 81.3 
257 2056 27.4 81.3 
256 2055 27.4 81.3 
256 2056 27.4 81.3 
257 2055 27.4 81.3 
257 2056 27.4 81.3 
257 2055 27.4 81.3 
256 2057 27.4 81.3 
256 2056 27.4 81.3 
257 2055 27.4 81.3 
256 2057 27.4 81.3 
256 2056 27.4 81.3 
256 2055 27.4 81.3 
256 2055 27.4 81.3 
257 2055 27.4 81.3 
257 2055 27.4 81.3 
257 2055 27.4 81.3 
255 2055 27.4 81.3 
257 2056 27.4 81.3 
257 2055 27.4 81.3 
256 2055 27.4 81.3 
257 2055 27.4 81.3 
256 2055 27.4 81.3 
256 2055 27.4 81.3 
256 2055 27.4 81.3 
256 2054 27.4 81.3 
255 2054 27.4 81.3 
256 2053 27.3 81.1 
256 2053 27.3 81.1 
256 2053 27.3 81.1 
256 2053 27.3 81.1 
257 2052 27.3 81.1 
256 2053 27.3 81.1 
256 2054 27.4 81.3 
256 2054 27.4 81.3 
255 2053 27.3 81.1 
255 2052 27.3 81.1 
256 2052 27.3 81.1 
256 2051 27.3 81.1 
256 2050 27.3 81.1 
255 2049 27.3 81.1 
255 2048 27.3 81.1 
256 2048 27.3 81.1 
255 2047 27.3 81.1 
255 2046 27.2 80.9 
256 2047 27.3 81.1 
257 2049 27.3 81.1 
256 2049 27.3 81.1 
256 2049 27.3 81.1 
256 2049 27.3 81.1 
255 2049 27.3 81.1 
255 2049 27.3 81.1 
256 2049 27.3 81.1 
256 2049 27.3 81.1 
257 2048 27.3 81.1 
255 2048 27.3 81.1 
257 2048 27.3 81.1 
256 2048 27.3 81.1 
256 2048 27.3 81.1 
255 2047 27.3 81.1 
256 2047 27.3 81.1 
255 2046 27.2 80.9 
256 2046 27.2 80.9 
255 2046 27.2 80.9 
256 2046 27.2 80.9 
255 2047 27.3 81.1 
256 2048 27.3 81.1 
255 2048 27.3 81.1 
257 2048 27.3 81.1 
256 2048 27.3 81.1 
256 2048 27.3 81.1 
255 2048 27.3 81.1 
255 2047 27.3 81.1 
256 2047 27.3 81.1 
256 2047 27.3 81.1 
257 2048 27.3 81.1 
256 2047 27.3 81.1 
256 2048 27.3 81.1 
256 2048 27.3 81.1 
256 2048 27.3 81.1 
254 2048 27.3 81.1 
256 2048 27.3 81.1