Problem with the LM35 temperature sensor

Trying to put together a very simple thermometer with the Proton and a LM35 temperature sensor. (http://www.dx.com/p/diy-lm35-linear-temperature-sensor-module-black-166653#.VxO4HZN96EI)

I have the LM35 temperature sensor connected to 3,3V, GND, A5.

The readings I get in my living room are around 2200, when my Netatmo weather station tells me it is 22,8 C in the same room.

Using this code to convert the reading to Celsius, doesn’t really make sense as I get results around 130C after using this formula for converting.

tempReadLevel = analogRead(tempPin);
temp = (((tempReadLevel * 3.3)/4095) - 0.5) * 100;

Have anyone succeeded in using the LM35 with the Proton and actually getting a correct reading out of it?

In the data sheet that I looked at, the supply voltage for the LM35 is 4V to 20V. Assuming you have Photon powered by USB, you could use VIN which is around 4.8V. The 3V3 supply is too low.

However you must be careful because the analog inputs only allow up to 3.3V. At 10 mV/°C you should hopefully never exceed 3.3V, but be careful you don’t do it by shorting a wire somewhere.

Thanks for your answer Rickkas7.

I have tried both 5V and 3,3V.

With the LM35 connected to the VIN, I get readings around 4000, and a temperature celsius around 420. (I have changed the code to:

temp = (((tempReadLevel * 5)/4095) - 0.5) * 100;

to reflect the 5V input.

So still doesn’t compute I’m afraid… :frowning:

You’d still need to use 3.3 in the voltage part of the equation, since this is the reference voltage for the ADCs

voltage = 3.3 * analogRead(D5) / 4095.0;
temp = (voltage - 0.5) * 100; // I've not looked this up in the datasheet, I just took your word for it ;-)

Something seems wrong, but I’m not sure what. Assuming the 10 mV/°C I’d expect that 22°C you should have 220 mV, or a value of 273 from analogRead. Odd!

Yup, the minimum wiring only spans 2°C (0.02V) to 150°C (1.5V).
Full range would require to push the “center” voltage a bit higher up to put 150°C near the top reading (3.3V) and the bottom reading (aprox. 0V) into the negative °C range (e.g. by use of two Si diodes as shown in System examples Fig. 18)

The temp calculation would need adapting then.

But there are several threads dealing with this sensor already
https://community.particle.io/search?q=lm35

There are several threads, still none that can actually show some code that works, and will return the correct temperature in Celsius from this sensor in my case… People seem to have a nice range of problems with the sensor though… :confounded:

Have you tried the cap as suggested in one of these threads?
Since your raw readings seem way out, I’d suspect an electrical issue that needs attention before looking at the code.

With the minimum wiring (2°C-150°C) you’d need the raw reading to be at about 300 at room temperature.

BTW: The TMP36/LM36 might be better suited
http://www.ladyada.net/learn/sensors/temp36.html