What is Temperature sensor:
Temperature sensor is the Device which is used to measure temperature. It gives an analog value which is proportional to temperature. Higher the value, more the temperature.
temp_val = analogRead(A0);
float temp_in_celcius = ( temp_val/1023.0)*5000; //multiplied with 5000 because we get values ranging from 0 to 5v
float temp_in_fahrenheit = (temp_in_celcius*9)/5 + 32;
Serial.print(“TEMPERATURE in Celcius is “);
Serial.print(“TEMPRATURE in fahrenheit is “);
Here, before void setup, we initialized temp_val to store temperature value. In void setup, we did serial.begin to start program. After completing void setup, we come to void loop. We have written temp_val to store analog temperature value; temp_in_celcius to store celcius value of temperature;temp_in_fahrenheit to store fahrenheit temperature value.We are printing temperature in celcius and fahrenheit for every 500 milli seconds.
Connecting LM35 sensor:
There are 3 pins for LM35 sensor, I.e., one for Vcc, one for ground and one for temperature. When we hold LM35 and face towards flat surface, the one to the left should be connected to Vcc, the one in the center is output, which actually gives the voltage value of the temperature, and the last one is connected to the ground. The connections are shown in then figure below, And the values come in the serial port are as shown in the figure below.