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()
{
val = analogRead(tempPin);
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
;)
:)


Comments

author
spradana1 (author)2014-04-01

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

author
conorb1 (author)spradana12015-06-27

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

author
peter.mbiria (author)conorb12016-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

author
minimadmalc (author)spradana12014-10-27

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?

author
spradana1 (author)minimadmalc2014-10-28

you can substitute the SUPPLY_VOLTAGE part which result in

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

0.439453125

author
sghosh21 (author)spradana12014-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,

author
spradana1 (author)sghosh212014-11-15

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.

author
himan0110 (author)2017-07-17

I made it.

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

author
HarDizzeR (author)2017-06-09

My LM35 gets about 333*C...

author
TadiT1 (author)2017-05-23

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

author
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.

author
HarryA32 (author)2016-08-22

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

author
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.

author
AdamD101 made it! (author)2016-04-21

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

20160421_234501.jpg
author
GuiAfonso made it! (author)2016-04-18

I Made it!

2016-04-19 00.02.35.jpg
author
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

author
BrwaS (author)eustacius2016-03-26

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

author
AhmetG (author)eustacius2015-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

author
eustacius (author)AhmetG2015-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.

author
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

Capture.PNGIMG_20150815_152104024.jpgIMG_20150815_152125662_HDR.jpgIMG_20150815_152142906.jpgIMG_20150815_152200675_HDR.jpgIMG_20150815_152211122_HDR.jpgIMG_20150815_152251856.jpgIMG_20150815_152429178_HDR.jpg
author
StevenV24 (author)CarlosG52016-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.

author
TAPAN MOJIDRA (author)CarlosG52015-10-16

thank you

author
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

author

double check your connection

author
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!

author
KostasK8 (author)2016-01-14

thanks for the info

author
vamcdharreddy (author)2016-01-11

sir how can download pdf for this project

author
vamcdharreddy (author)2016-01-11

sir how can download pdf for this project

author
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?

author
TAPAN MOJIDRA (author)SidA22015-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..

author
DeanP2 (author)SidA22015-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.

author
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 ????

author

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

author

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

author
tooradj (author)2015-04-06

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

author
TAPAN MOJIDRA (author)tooradj2015-12-24

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

author
Vitor Reppen (author)tooradj2015-06-11

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

author
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

sda.jpg
author
TAPAN MOJIDRA (author)NgoT2015-12-24

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

author
DenyR (author)2015-07-28

please help me! :(

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?

PLEASE :(

author
TAPAN MOJIDRA (author)DenyR2015-12-24

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

author
TAPAN MOJIDRA (author)DenyR2015-10-16

Double check your wiring and position of your sensor

author
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.

Capture.JPG
author

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

author

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...

author

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

author
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 .

author

yes you can connect xbee to your arduino.