LM35 Temperature Sensor

About: 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. His dad was an extraordinary cabinet maker and while working on their 1850’s hom...

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

Share

Recommendations

  • Metalworking Contest

    Metalworking Contest
  • Tiny Home Contest

    Tiny Home Contest
  • Audio Contest 2018

    Audio Contest 2018

11 Discussions

0
None
DušanB4

2 years ago

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
1 reply
0
None
R9758DušanB4

Reply 1 year ago

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);

}

0
None
Manishiya

1 year ago

can we use this for body temperature measurement?

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!

2 replies
0
None
ams31SexyBeastAsian

Reply 2 years ago

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

0
None
KhaR1

2 years ago

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

Thanks

1 reply
0
None
SamuelEmmettBray

3 years ago on Step 3

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 :-)