Subscribe to Arduino Academy and start learning today for FREE!

Arduino LM35 Temperature Sensor

One of the least expensive and simplest ways to measure temperature is with a LM35. This is another component found in our SainSmart kit. This transistor looking device has 3 pins, 5v, Signal out, and Gnd. The signal is an analog voltage that connects directly to a Arduino analog input. In this example we will use A0.

Now the LM35 outputs 0-1v for it’s range of -55C to 150C. Since the Arduino defaults to a 5v reference for analog to digital conversion, we are losing 80% of the sensors range, so we are switching to the internal reference which is 1.1v. This is a better match for this sensor. We are also doing a Celsius to Fahrenheit conversion in the code.

Become the Maker you were born to be. Try Arduino Academy for FREE!

With the pins down, and the flat face of the sensor facing you, the pins, from left to right are:

V- S – G

Where V connects to +5, S connects to A0, and G connects to ground. The data sheet can be found at http://www.ti.com/lit/ds/symlink/lm35.pdf

The code looks like this:

float tempC;
float tempF;
int reading;
int tempPin = 0;

void setup() {
// put your setup code here, to run once:
analogReference(INTERNAL); //changing from a 5v reference to a 1.1v reference
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
reading = analogRead(tempPin);
tempC = reading / 9.31;
//Serial.print(tempC);
tempF=tempC * 9/5 + 32;
Serial.println(tempF);
delay(5000);
}

Become the Maker you were born to be. Try Arduino Academy for FREE!

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Archives

0
Would love your thoughts, please comment.x
()
x