LM35 Temperature Sensor
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.
13 Comments
softeng 5 years ago
PeterR249 5 years ago
However, for a hello world app, it is worth noting that a brief version printing Celsius is just:
void setup(){ Serial.begin(9600);}
void loop(){
Serial.println(analogRead(1)*500.0/1024.0);
delay(1000);
}
DušanB4 8 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.
R9758 6 years 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);
}
Manishiya 7 years ago
can we use this for body temperature measurement?
SexyBeastAsian 9 years ago
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!
ams31 8 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
innovativetom 9 years ago
I would just do some testing. To find the voltage = temp you want.
KhaR1 8 years ago
Can someone give me the difference between a temperature sensor like the one used here, and a thermister.
Thanks
VilnisD 8 years ago
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
SamuelEmmettBray 8 years ago
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 :-)
SHIVANIS3 9 years ago
it measures board or human body temp?
innovativetom 9 years ago
Its an ambient temp, more for like a room.