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.We are using LM35 sensor in this arduino tutorial.


int temp_val;
void setup()
void loop()
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.println(” C”);
Serial.print(“TEMPRATURE in fahrenheit is  “);
Serial.println(” F”);

Code explaination:

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.
  • 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.

Connection Diagram
Snapshot of Serial Monitor showing Temperature values from sensor.

Next Post:Fading LED Program in Arduino IDE

Previous Post:Turning on and off an LED from Serial Monitor

Categories: ArduinoTutorials


Arduino Tutorials:Turning on and off an LED from Serial Monitor - projectsflix · January 3, 2021 at 6:20 pm

[…] Next Post:Reading analog data from temperature sensor (LM35) […]

Arduino Tutorials:Arduino and DC motor using L293D - projectsflix · January 3, 2021 at 6:33 pm

[…] Previous Post:Reading analog data from temperature sensor (LM35) […]

Leave a Reply