# Measure Temperature Using Lm35 and Arduino

12,958

7

2

## Introduction: Measure Temperature Using Lm35 and Arduino

The lm35 is an analog linear temperature sensor. This means that the output voltage is proportional to the temperature. The output voltage rises by 10mv for every 1 degree Celsius rise in temperature. The Arduino can read input from 0-5v. The Arduino stores this as a 10bit number(0-1023). The method that i am going to use now can be used to measure temperature from 2 degree Celsius to the maximum temperature that your lm35 can measure. I will make another article on how we can measure temperatures below that soon.

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 1: Making the Connections

The lm35 that i used has the ground pin and the Vs pin interchanged compared to the Texas Instruments one, the data sheet for which is commonly available. If you have interchanged the pins while connecting the sensor it will get hot so you'll know if its incorrect.

connect the Vs pin to the 5v pin on the Arduino and ground to one of the 2 ground pins on the power rail. Connect the Vout pin to one of the analog pin, A0 in my case.

Another thing i noticed is that the temperature that you get is not reliable if you connect many jumper cables together to make the wire long.

## Step 2: The Program

Here is the sketch:

int temppin=0;

float temp;

void setup()

{

Serial.begin(9600);

}

void loop()

{

temp=analogRead(temppin); // Reading data from the sensor.This voltage is stored as a 10bit number

temp=(5.0*temp*1000.0)/(1024*10);

/* 5*temp/1024 is to convert the 10 bit number to a voltage reading.

This is multiplied by 1000 to convert it to millivolt.

We then divide it by 10 beacuse each degree rise results in a 10 millivolt increase.

*/

Serial.println(temp);

delay(500);// This is because we dont want a continuous stream of data

}

## Step 3: Check the Temperature

Open the serial monitor and check the temperature. The temperature reading will change every 0.5 seconds.

## 2 Discussions

When using the LM35, it's a good idea to use the internal voltage reference instead of the 5v.
This will make the maximum value of the ADC converter to 1.1v, thus increasing the resolution of the converted value.

On the setup function, add the following line
analogReference(INTERNAL); // 1.1 ref. [LM35 outputs 1v when 100ºC]

Then, on the loop function change from
temp=(5.0*temp*1000.0)/(1024*10);
To
temp=(1.1*temp*1000.0)/(1024*10);

Ideally, you could read the true Aref voltage (with a multi-meter) and use this value instead of 1.1