Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Temperature Sensor on Analog input
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Temperature Sensor on Analog input

by Silver on Sun May 04, 2008 2:45 am

Looking through my parts bin, I found an LM35 precision temperature sensor that was included in a parts package from my earlier days.

I did some research and found the specification sheet for the LM35 and decided to hook it up to the Arduino. The LM35 outputs a linear voltage of 10 millivolts per degree Celsius. The simple program here sends a message back over the serial port to show the temperature in both Celsius and Fahrenheit. It could also be used to control a fan or sound an alarm. The LM35 costs about $1.75 from either BGmicro.com or Jameco.com.

Sorry for the long comments section in the program. I like to put a lot of notes in my programs so I remember why I did something a particular way when I go back and read the program again weeks later. Especially the conversion factor for the Analog to Digital Conversion input and the LM35.


Code: Select all | TOGGLE FULL SIZE
/* Analog Read of LM35 temperature sensor
 * --------------------------------------
 *
 * The Analog to Digital Converter (ADC) converts analog values into a digital approximation
 * based on the formula ADC Value = sample * 1024 / reference voltage (+5v).  So with a +5 volt
 * reference, the digital approximation will = input voltage * 205.  (Ex.  2.5v * 205 = 512.5)
 *
 * The LM35 is a precision linear temperature sensor that supplies 10mv per degree Celsius.
 * This means at 15 degrees Celsius, it would produce a reading of .150v or 150 millivolts.
 * Putting this value into our ADC conversion ( .15v * 205 = 30.75) we can get a close
 * approximation of the Celsius temperature by dividing the digital input count by 2.
 *
 * If the LM35 were supplied by a different reference voltage (9v or 12v) we would have
 * to use a different conversion method.  For this circuit, dividing by 2 works well.
 *
 * The LM25 has three legs and looks like a transistor.  The two outside legs are
 * +5v and Ground, and the middle leg develops the sample voltage.
 * LM35 Sources:  BGmicro.com and Jameco.com   Search term:  LM35   Approx  $1.75
 *
 *         /|---> Gnd       18K ohm
 *        | |-----------+---/\/\/\/-----> Gnd
 *         \|---> +5v   |
 *                      +----------- Analog Input pin 5
 *
 */

int inPin = 5;                              // select the input pin for analog temp value
int inVal;                                  // integer value for input read from sensor
int delayVal = 1000;                        // delay value to read once a second

void setup() {
Serial.begin(9600);                         // set up Serial library at 9600 bps
}

void loop() {
  inVal = analogRead(inPin);                // read the value from the sensor
  inVal /= 2;                               // convert 1024 steps into value referenced to +5 volts
  Serial.print(inVal);                      // print input value
  Serial.print(" Celsius,  ");              // print Celsius label
  Serial.print((inVal * 9)/ 5 + 32);        // convert Celsius to Fahrenheit
  Serial.println(" Fahrenheit");            // print Fahrenheit label
  delay(delayVal);                          // delay the program for the requested time
}



Hope this is useful,

Silver
Silver
 
Posts: 12
Joined: Mon Apr 21, 2008 1:39 am

by adafruit on Tue May 06, 2008 8:15 pm

very useful!

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm
Location: nyc

Re: Temperature Sensor on Analog input

by Shiseiji on Mon Apr 27, 2009 9:42 am

Thanks! I just got two pets and want to monitor the temp in my (poorly insulated rental) place (and then be able to turn on the cooling if necessary, that will be part 2). I just finished setting up my first Linux box and have had the Arduino for some time. I am no where close to any kind of an engineer, but am a reasonbly skilled technician and "will" scream for help if I can't get this going. Thanks again.

Ron
Shiseiji
 
Posts: 1
Joined: Mon Apr 27, 2009 9:36 am

Please be positive and constructive with your questions and comments.