Saturday, April 11, 2015

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.

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

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

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

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...