A very Basic Way of Interfacing a LM35 Temperature Sensor to an Arduino.
The Basic Test Code to show the Values in Serial Monitor is Given Here:
float tempC;
int tempPin = 0;
void setup()
{
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}
void loop()
{
tempC = analogRead(tempPin); //read the value from the sensor
tempC = (5.0 * tempC * 100.0) / 1024.0; //convert the analog data to temperature
Serial.print((byte)tempC); //send the data to the computer
delay(1000); //wait one second before sending new data
}
Another Way Of Reading The Temperature,, but in this case the Resulution has Been Improved:
float tempC;
int reading;
int tempPin = 0;
void setup()
{
analogReference(INTERNAL);
Serial.begin(9600); //opens serial port, sets data rate to 9600 bps
}
void loop()
{
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.print((byte)tempC);//send the data to the computer
Serial.print(" C");
Serial.println();
delay(1000); //wait one second before sending new data
}