## Introduction: ARDUINO TEMPERATURE SENSOR LM35

Now make your own temperature sensor by Arduino and LM35 Sensor
You required following parts
1-ARDUINO BOARD ANY VERSION
2-LM35 TEMPERATURE SENSOR
3-USB CABLE
4-COMPUTER WITH ARDUINO SOFTWERE

MAKE THE CONNECTION AS SHOWN IN IMAGE AND UPLOAD THE FOLLOWING CODE ON ARDUINO BOARD.

int val;
int tempPin = 1;

void setup()
{
Serial.begin(9600);
}
void loop()
{
float mv = ( val/1024.0)*5000;
float cel = mv/10;
float farh = (cel*9)/5 + 32;

Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);

/* uncomment this to get temperature in farenhite
Serial.print("TEMPRATURE = ");
Serial.print(farh);
Serial.print("*F");
Serial.println();

*/
}

NOW SEE THE SERIAL MONITOR IN THE ARDUINO SOFTWERE ,
ITS DONE.

VISIT https://www.facebook.com/SparkingElectronics FOR MORE PROJECTS
;)
:)

We can get value magic number 0.48828125 from following expression:

(SUPPLY_VOLTAGE x 1000 / 1024) / 10 where SUPPLY_VOLTAGE is 5.0V (the voltage used to power LM35)

1024 is 2^10, value where the analog value can be represented by ATmega (cmiiw) or the maximum value it can be represented is 1023. The actual voltage obtained by VOLTAGE_GET / 1024.

1000 is used to change the unit from V to mV

10 is constant. Each 10 mV is directly proportional to 1 Celcius.

By doing simple math: (5.0 * 1000 / 1024) / 10 = 0.48828125

conorb1 (author)2015-06-27

Sorry for asking this but what is the magic number you refer to about? What is the importance of it

peter.mbiria (author)2016-09-09

I think he meant the calibration value. instead of doing all the computation , just get the value from the sensor and multiply it with that value

Hi Please can you tell me if I was to run this program through a Attiny85 on 4.5 volts what formula would I need to use to get the correct results?

you can substitute the SUPPLY_VOLTAGE part which result in

(SUPPLY_VOLTAGE x 1000 / 1024) / 10 = (4.5 x 1000 / 1024) / 10 =

0.439453125

sghosh21 (author)2014-11-09

the supply voltage doesn't really matter , i think the analog to digital converter matters though, coz see we can even power the LM35 with a 20 v power supply, if we do that and still read the analog value from arduino, your equation will not hold,

Indeed the supply voltage can ranging from +35V to -0.2V. Well, I got the equation from the LM35 datasheet and never done things outside the datasheet.

himan0110 (author)2017-07-17

I was trying to put date and time next to the temp so that I can do some analytics on the data. Can someone please help me with the code ? Thanks

HarDizzeR (author)2017-06-09

My LM35 gets about 333*C...

the output values are not making ant sense when i kept the sensor in different climatic conditions.they are printing the same values

blackburdtx (author)2016-10-22

Very easy, I recieved temperature in F on the serial output. Now I want to output the script to a multi digit LED Dispaly.

HarryA32 (author)2016-08-22

instructions are useful but can i connect this project with ni labview?

ams31 (author)2016-05-08

I have seen lot of people commenting they are getting improper reading let me give you some basic description of LM35 Temperature Sensor

Well LM35 is a linear temperature sensor whose output voltage is proportional to degree centigrade. LM35's output is 10mv/Degree C which means for every degree rise in temperature the output of LM35 will rise by 10mv. So if the output of LM35 is 220mv/0.22V the temperature will be 22°C. So if room temperature is 32°C then the output of LM35 will be 320mv i.e. 0.32V.

So if you are not getting proper reading then check the output voltage of the sensor is it proportional to the room temperature as explained above? If so check the code that you have typed.

Sweet! Works like a charm - will modify as I see fit :)

GuiAfonso made it! (author)2016-04-18

eustacius (author)2015-03-03

There's something wrong, with my LM35, when i connect it directly to my mega, it works correctly it shows the correct temperature but then when i connect with with ethernet shield w5200, the sensor reading become weird its like random or something. but when i use other sensors like LDR and gas sensor, it just works fine. anyone experience this before? can help me? ps: ethernet shield w5200 with teleduino library

BrwaS (author)2016-03-26

Hi , I have the same issue , can you help me please , how i can solve this problem ?

AhmetG (author)2015-03-08

Do yuo test both sensors with the same analog pin (I mean analog 0 or 1).

As far as I know, w5200 has sdcard slot on it and it uses analog 0 and 1 pins for sd card Access.

Probably it will be ok when you try on other pins such as A3

eustacius (author)2015-03-09

yes, using the same pin its analog 15 (mega 2560), i'll take not on the pin that the w5200 uses. i didnt know what i did but now its working. thanks.

CarlosG5 made it! (author)2015-08-15

Interesting and easy to understand, thanks for the sample code, I was able to tweak it for my own needs :D

StevenV24 (author)2016-03-09

I do not know how it happens, but measurements that vary completely randomly of an entire degree are useless.

How do I avoid this noise.

TAPAN MOJIDRA (author)2015-10-16

thank you

faizvalensi (author)2016-02-20

The value of the temperature is opposite. When it is cold the temperature value increases, while when it is hot the temperature value decreases. How to fix this? HELP ME! T_T

TAPAN MOJIDRA (author)2016-02-29

double check your connection

johnjr101 (author)2016-01-27

I'm trying to make something where the arduino changes the color of a rgb led based on the temperature, I think i have the code to use a rgb led with it but i don't know how the code would go to have it do different commands based off of the temperature. I'm assuming it has something to do with setting the minimum mV and maximum mV from the LM35's output for that command or colour. Any ideas would be helpful! Thanks!

thanks for the info

vamcdharreddy (author)2016-01-11

sir how can download pdf for this project

vamcdharreddy (author)2016-01-11

sir how can download pdf for this project

SidA2 (author)2015-01-10

Hello. I'm somewhat new to Arduino and I have a box of random sensors, one of which was the temp sensor. I tried out this program but the sensor kept on giving me high values ranging from 180*C to sometimes at the 400s. I am using an Arduino Mega and I have tried all possible configurations. There is only one that works, the other ways two heat up my sensor...

And it's nothing wrong with my Arduino because I tried it with two of the same board.

How can I get this to work?

TAPAN MOJIDRA (author)2015-12-24

Don't keep the length of sensor pin wire (A0- to lm35) long..
kepp it as short as possible
and check your connection..

DeanP2 (author)2015-01-21

I had that happen the other night with a project that was just fine minutes before. I had accidentally knocked a wire loose. I reconnected it and the sensor felt like it really WAS 440 degrees. I reversed it and it was fine. Can't explain all that, but I tried to reset my Arduino several times first, and this was the only thing that worked.

MOUNIKA DATTA (author)2015-02-06

I m getting d output as 132.34*C .....in ds pattern nly but not as 23*C n all...wat crctns can I make ????

TAPAN MOJIDRA (author)2015-12-24

Don't keep the length of sensor pin wire (A0- to lm35) long..
kepp it as short as possible

TAPAN MOJIDRA (author)2015-02-19

just check the wiring once again ...
see the picture and connect exactly as shown in image

Hi, I've got wrong temperature. I have 2 pieces of lm35DZ sensor, one of them read 451.9 and the other show numbers between zero and 24.38, correct temperature of my desktop is 26.5 degrees centigrade. I'm using pin A0 of arduino. Off course when I pull out the sensor from the bred board, my arduino UNO R3 shows some numbers. Please help me on this problem

TAPAN MOJIDRA (author)2015-12-24

Don't keep the length of sensor pin wire (A0- to lm35) long..
kepp it as short as possible

Vitor Reppen (author)2015-06-11

You should use pin A1 to work, if you read the program you should be able to figure that ... ( int tempPin = 1; )

NgoT made it! (author)2015-07-07

Excuse me bro, This is my code and simulation. It s a bit difference from you and LCD look not so nice. But wiring is ok. Similar to karengrace.victor, i also have a problem with temperature and display it, Thanks

TAPAN MOJIDRA (author)2015-12-24

Don't keep the length of sensor pin wire (A0- to lm35) long..
kepp it as short as possible

DenyR (author)2015-07-28

the output (from your code) always "499.51*C"

and i very very sure wired it correctly.

can u tell my how to fix this?

TAPAN MOJIDRA (author)2015-12-24

Don't keep the length of sensor pin wire (A0- to lm35) long..
kepp it as short as possible

TAPAN MOJIDRA (author)2015-10-16

Double check your wiring and position of your sensor

Controlzeti (author)2015-10-31

Hi. When I try use this code, the results are incomprehensible. results show on etched image. the result is same wen i remove temperature sensor.

TAPAN MOJIDRA (author)2015-12-24

Don't keep the length of sensor pin wire (A0- to lm35) long..
kepp it as short as possible..

TAPAN MOJIDRA (author)2015-11-06

in your code if you use analog pin A0 then check the code whrere it should be temperature pin = 0

if you use analog pinA1 then temp. pin=1
like wise...

TAPAN MOJIDRA (author)2015-11-03

check out the connection once again please..
It should work..

eyesonsaldanha (author)2015-11-16

CAn we send this values sensed to the other microcontroller using zigbee, if yes let me have a brief idea .

TAPAN MOJIDRA (author)2015-11-17

yes you can connect xbee to your arduino.