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

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 valueint inVal;                                  // integer value for input read from sensorint delayVal = 1000;                        // delay value to read once a secondvoid 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

very useful!

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