# Arduino - LM35 Temperature Sensor

## Hardware Required

Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

### Pinout

LM35 temperature sensor has three pins:

• GND pin needs to be connected to GND (0V)
• VCC pin needs to be connected to VCC (5V)
• OUT pin signal pin gives the output voltage that is linearly proportional to the temperature, should be connected to a analog pin on Arduino.
• ### How It Works

The LM35 outputs the voltage linearly proportional to the Centigrade temperature. The output scale factor of the LM35 is 10 mV/°C. It means that the temperature is calculated by dividing the voltage (mV) in output pin by 10.

## Wiring Diagram Image is developed using Fritzing. Click to enlarge image

## How To Program For LM35 Temperature Sensor

• Get the ADC value from the temperature sensor by using analogRead() function.
• Convert the ADC value to voltage in millivolt
• Convert the voltage to the temperature in Celsius
float tempC = milliVolt / 10;
• (Optional) Convert the Celsius to Fahrenheit
float tempF = tempC * 9 / 5 + 32;

## Arduino Code

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-lm35-temperature-sensor */ #define ADC_VREF_mV 5000.0 // in millivolt #define ADC_RESOLUTION 1024.0 #define PIN_LM35 A0 void setup() { Serial.begin(9600); } void loop() { // get the ADC value from the temperature sensor int adcVal = analogRead(PIN_LM35); // convert the ADC value to voltage in millivolt float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION); // convert the voltage to the temperature in Celsius float tempC = milliVolt / 10; // convert the Celsius to Fahrenheit float tempF = tempC * 9 / 5 + 32; // print the temperature in the Serial Monitor: Serial.print("Temperature: "); Serial.print(tempC); // print the temperature in Celsius Serial.print("°C"); Serial.print(" ~ "); // separator between Celsius and Fahrenheit Serial.print(tempF); // print the temperature in Fahrenheit Serial.println("°F"); delay(1000); }

#### Quick Steps

• Copy the above code and open with Arduino IDE
• Click Upload button on Arduino IDE to upload code to Arduino
• Grasp the sensor by your hand
• See the result on Serial Monitor.
• COM6
Temperature: 26.31°C ~ 79.36°F Temperature: 26.44°C ~ 79.59°F Temperature: 26.50°C ~ 79.70°F Temperature: 26.56°C ~ 79.81°F Temperature: 27.06°C ~ 80.71°F Temperature: 27.75°C ~ 81.95°F Temperature: 28.37°C ~ 83.07°F Temperature: 29.00°C ~ 84.20°F Temperature: 29.56°C ~ 85.21°F Temperature: 30.00°C ~ 86.00°F Temperature: 30.31°C ~ 86.56°F Temperature: 30.62°C ~ 87.12°F Temperature: 30.87°C ~ 87.57°F
Autoscroll Show timestamp
Clear output
9600 baud
Newline

## Improving the Temperature Precision

In the above code, we use ADC reference voltage by default (5V~5000mV). We can increase the temperature resolution by changing reference voltage to INTERNAL (1.1V~1100mV). This reference voltage can be changed using the analogReference() function.

The below table show the diffrent between using 5000mV and 1100mV reference voltage

Vref(mV) 5000 mV (by default) 1100 mV (INTERNAL)
Reading Resolution 5000/1024 = 4.88 mV 1100/1024 = 1.07 mV
Temperature Resolution 0.488 °C 0.107 °C
Temperature Range 0 to 500 °C 0 to 110 °C

### Arduino Code

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-lm35-temperature-sensor */ #define ADC_VREF_mV 1100.0 // in millivolt #define ADC_RESOLUTION 1024.0 #define PIN_LM35 A0 void setup() { Serial.begin(9600); // switch to Internal 1.1V Reference analogReference(INTERNAL); } void loop() { // get the ADC value from the temperature sensor int adcVal = analogRead(PIN_LM35); // convert the ADC value to voltage in millivolt float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION); // ADC_VREF_mV = 1100 mV // convert the voltage to the temperature in Celsius float tempC = milliVolt / 10; // convert the Celsius to Fahrenheit float tempF = tempC * 9 / 5 + 32; // print the temperature in the Serial Monitor: Serial.print("Temperature: "); Serial.print(tempC); // print the temperature in Celsius Serial.print("°C"); Serial.print(" ~ "); // separator between Celsius and Fahrenheit Serial.print(tempF); // print the temperature in Fahrenheit Serial.println("°F"); delay(1000); }

## Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

※ OUR MESSAGES