Temperature sensing using Arduino and LM35
LM35 is a precision IC analog temperature sensor with its output voltage proportional to the
temperature (in Celsius).The sensor circuitry is sealed and therefore it is not subjected to
oxidation and other processes. With LM35, temperature can be measured more accurately than
with a thermistor. It also possess low self heating and does not cause more than 0.1 degree
Celsius temperature rise in still air.
The operating temperature range is from -55°C to 150°C. The output voltage varies by 10mV in
response to every degree Celsius rise/fall in ambient temperature, that is, its scale factor is
0.01V/ degree Celsius.It is as shown below.
You will require an Arduino(UNO/MEGA 2560 preferably), A to B USB
cable,LM35,connecting wires/male jumper wires,Arduino IDE,LED
Circuit diagram:Basic Temperature Sensor
Pin A0 to O/P,GND TO GND,5V PIN to supply
The above circuit provides the ambient temperature reading after a specified time interval
on the serial monitor of the Arduino IDE,when connected to the computer via a USB cable.
The program required to do so is as follows
//declaration of variables
int val;
int tempPin = 0;
//Pin A0 on the Arduino will receive O/P of LM35(Analog output)
void setup()
{
Serial.begin(9600); //Baud rate
}
void loop()
{
val = analogRead(tempPin);
//val stores temperature reading at required time
float mv = ( val/1024.0)*5000;
//Reading value from analog input and converting it to voltage. Maximum voltage Arduino can measure equals 5V(5000Mv)
and the A/D converter’s resolution is 10 bits, which means 1024 values, thus voltage value on Analog0 input is the value
returned by analogRead multiplied by the voltage equaling one step of A/D converter.
float cel = mv/10; //10mv rise per degree Celsius
Serial.print("TEMPERATURE = ");
//print output on Serial Monitor
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(2000);
//Check O/P temperature every two seconds
}
The output should be as shown below, when the Serial monitor icon on the top right of the
sketch window is clicked
Now,lets go a step further and interface and LED along with the above circuit,such that the
LED glows when the temperature goes above a certain threshold value.The circuit diagram
is similar,the only difference being the addition of the LED to the breadboard and
connected to the Arduino as shown.
Note:Longer lead of LED to supply and shorter lead to ground
Circuit Diagram
In the diagram,the shorter lead of LED is connected to GND and longer end to pin 13.
The program is the same as above, but with slight modifications.
int val;
int tempPin = 1;
int ledPin=13; //Pin 13 controls LED
int ledState=LOW;
//InItially,set LED state to OFF
void setup()
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
//Declares Pin 13 as an output Pin
}
void loop()
{
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
digitalWrite(ledPin,ledState);
//Initiates Pin13 as an O/P Pin at LOW state
if(cel>25)
ledState=HIGH; )
//If temperature is greater than say 25 deg Celsius,LED is ON
else
ledState=LOW;
//Below 25 deg Celsius,LED is OFF
Serial.print("TEMPERATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(2000);
}
The output will be the same on the Serial Monitor,but the LED will glow only when the
given condition is met during temperature check at the two second intervals.
© Copyright 2025 Paperzz