Introduction: LM35 Temperature Sensor

“Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is programmed using the Arduino programming language”. Using the Arduino I will show you how to get the analog input from the LM35 temperature sensor and display the information in the serial window as raw data, celsius and fahrenheit.

For the purpose of the post I will assume that you already know how to download and install the Arduino software and load a sketch onto it.

Step 1: What You Need

What you will need:

Arduino UNO, Leonardo or equivalent

Breadboard

Jumper Wires

USB Cord

LM35 temperature sensor Data Sheet

Step 2: Wiring:

Wire up the breadboard as depicted in this picture.

Step 3: Code

The code can be downloaded here.

or Copy and paste this into the arduino sketch.

/*<br>Simple Temperature uses the lm35 in the basic centigrade temperature configuration
*/
float temp;
int tempPin = 2; // analog input pin
int sampleTime = 1000; // 1 second dafault 
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  //gets and prints the raw data from the lm35
  temp = analogRead(tempPin);
  Serial.print("RAW DATA: ");
  Serial.print (temp);
  Serial.println(" ");
  //converts raw data into degrees celsius and prints it out
  // 500mV/1024=.48828125
  temp = temp * 0.48828125;
  Serial.print("CELSIUS: ");
  Serial.print(temp);
  Serial.println("*C ");
  //converts celsius into fahrenheit 
  temp = temp *9 / 5;
  temp = temp + 32;
  Serial.print("FAHRENHEIT: ");
  Serial.print(temp);
  Serial.println("*F");
  delay(sampleTime);

}

Load the code into to your board and open the serial monitor you should see both fahrenheit and celsius.

Comments

author
DušanB4 (author)2015-11-20

Hallo , i dont know why but I just tried to copy this program but I faced problem :

could someone help ? Using arduino mini pro and Voltage for me is 5V
checked wiring, plus , GND , and output are set correctly

I kept serial.println only for celsius ... there are 21 degrees in room

thanks for any idea.

p.PNG
author
R9758 (author)DušanB42017-05-28

That code is wrong I had the same problem it should be like this

I got the range form the manufacturer

http://www.ti.com/lit/ds/symlink/lm35.pdf

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

}

void loop() {

// put your main code here, to run repeatedly:

int x = analogRead(A0);

double y = map(x,0,1024,-55.0,150.0); //converit it to range

Serial.println(y);

delay(1000);

}

author
Manishiya (author)2016-09-27

can we use this for body temperature measurement?

author
SexyBeastAsian (author)2015-04-12

Hi, so depending on the temperature, the voltage output changes am I correct? Is it possible to know the correlationship between voltage and temperature? I'm trying to add a fan to run above certain voltage(temperature.) Thanks!

author
ams31 (author)SexyBeastAsian2016-05-08

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.

For detailed information check out basic's of LM35 Temperature Sensor

author

I would just do some testing. To find the voltage = temp you want.

author
KhaR1 (author)2016-01-17

Can someone give me the difference between a temperature sensor like the one used here, and a thermister.

Thanks

author
VilnisD (author)KhaR12016-03-03

I gues that termister is simple THERM-ally sensitive res-ISTOR, but LM35 has some amplifying element inside. Read this artile: http://www.electronics-tutorials.ws/io/io_3.html

author
SamuelEmmettBray (author)2015-09-23

I am confused about the 500mV number constant?

According to the datasheet even in the basic setup (which is used in this article) there is a range of 1480mV w/ 2degC being 0mV & 150degC being 1480mV w/ each degree C linear at 10mV.

TY :-)

author
SHIVANIS3 (author)2015-04-26

it measures board or human body temp?

author
innovativetom (author)SHIVANIS32015-04-26

Its an ambient temp, more for like a room.

author
tobias.sobkowiak made it! (author)2015-02-01

Nice instructable,

but i have a problems to get the correct celsius. The value isn´t constant. Do you have a hint what could be the problem?

Screenshot 2015-02-01 15.41.21.png
author

Hey sorry I never responded, were you able to get it working?

author

Nope. The data is freaking out....i´ve no clue what could be the problem. Degree spans between 6° aren´t very convincing i think...;-)

author

Looks like I had my Fritzing drawing wrong swap the +5v and GND.

About This Instructable

65,072views

70favorites

License:

Bio: As a young lad Tom spent most of his days at the heels of his father, working in their shop, also known as the basement ... More »
More by innovativetom:Table Top Tiki Torch! Recycle Your Beat Up Tiki Torch.How to Mount a Poster or Print to Plywood PanelRecycled Hardware & Parts Bin Organizer!
Add instructable to: