Interfacing Temperature Sensor (LM35) to Arduino

The LM35 temperature sensor produces an analog voltage directly proportional to temperature with an output of 1 millivolt per 0.1°C (10 mV per degree). The sketch (program) converts the analogRead values into millivolts (and divides this by 10 to get degrees. The sensor accuracy is around 0.5°C, and in many cases you can use integer math instead of floating point.

For LM35 datasheet click here

Program

/*
Interfacing LM35 temperature sensor
LM35 is a common TO-92 temperature sensor, which senses in
degree Celcius Scale
The circuit:
* Center pin is attached to analog input 0
* Pin 1 is connected to VCC (refer datasheet)
* Pin 3 is connected to GND (refer datasheet)
*/
int sensorPin = A0;
// select the input pin
int sensorValue = 0; // variable to store the value coming from the sensor
float Temp = 0.0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
sensorValue = analogRead(sensorPin);
Temp = (5.0 * sensorValue * 100.0) / 1024;
Serial.print(“Sensor Value: “);
Serial.println(sensorValue);
Serial.print(“Temperature Reading: “);                                                                      Serial.println(Temp);
Serial.println();
delay(2000);
}

Program Explanation

As disscussed earlier the LM35 output 1 millivolt per 0.1°C; the total voltage that can be represented is 5V or 5000mV. Therefore each unit read by the analogRead() will equal to 500/1024 degree Celsius. Hence the Temperature of the device being measured or ambient temperature can be easily computed as:

1

Connection Diagram

The figure shows the connection diagram of LM35 to Arduino. It is ad viced to used wires to connect LM35 to Arduino as it is not advised to keep the Arduino near the heat source.

2

Happy coding !! 🙂

Published by

Syam Nair

Technocrat, Traveler, & Researcher

Leave a comment