int sensorPin = A0; // select the input pin for the LM35 sensor
int digitalValue; // variable to store the value coming from the sensor
float analogVoltage;
float temp;
void setup() {
Serial.begin(9600);
}
void loop() {
// Get the analog value from lm35 sensor and convert that value into digital value using ADC converter
digitalValue = analogRead(sensorPin);
Serial.print("digital value = ");
Serial.print(digitalValue); //print digital value on serial monitor
//convert digital value to analog voltage
//Analog voltage = digital value * (Vref/2^n – 1)
//Here Vref is 5V that we connected to lm35 sensor.If we connect 3.3V to sensor then Vref is 3.3V
//Here we use 10 bit ADC so n=10 bits so the values ranges from 0 to 1023
analogVoltage = (digitalValue * 5.00)/1023.00;
Serial.print(" analog voltage = ");
Serial.println(analogVoltage);
//To convert analog voltage to temperature in Celcius, we multiply by 100
//because the LM35 output is 0.010V per degree. ie 1 degree =0.010V or 1V=100 degree
temp=analogVoltage * 100;
Serial.print("temperature = ");
Serial.print(temp);
Serial.println(" °C");
delay(10000);
}