Thermometer Project: Update

{lang: 'en-GB'}

Rich Davies has send in his Temperature measurement Sketch which uses an LM35 temperature sensor, as apposed to a thermistor. It can give readings in both Celsius and Fahrenheit, too.  His Sketch code, which includes an ASCII diagram for connecting the LM35 to the Arduino,  can be found below:


/* 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
}