//
//
#define aref_voltage 5.0 // we tie 5V to ARef
#define ADC_RESOLUTION 1024.0
#define PIN_LM35 A0
int tempReading; // the analog reading from the sensor
void setup() {
// We'll send debugging information via the Serial monitor
Serial.begin(9600);
// the voltage applied to the AREF pin (0 to 5V only) is used as the reference
analogReference(EXTERNAL);
}
void loop() {
tempReading = analogRead(PIN_LM35);
Serial.print("Temp reading = ");
Serial.print(tempReading); // the raw analog reading
// converting that reading to voltage, which is based off the reference voltage
float voltage = tempReading * aref_voltage;
voltage /= ADC_RESOLUTION;
// print out the voltage
Serial.print(" - ");
Serial.print(voltage); Serial.println(" volts");
// LM34 now print out the temperature
//float temperatureF = voltage * 100 ; //converting from 10 mv (0.01 V) per degree
//Serial.print(temperatureF); Serial.println(" degrees F");
// Use below for LM35:
float temperatureC = voltage * 100 ;
Serial.print(temperatureC); Serial.println(" degrees C");
// LM34: now convert to Celsius
//float temperatureC = (temperatureF - 32.0) * (5.0 / 9.0);
//Serial.print(temperatureC); Serial.println(" degrees C");
// Use below for LM35:
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");
delay(1000);
}