Interfacing LM35 Temperature Sensor with Arduino

Introduction

Temperature is one of the most commonly measured physical quantities in electronics projects, from simple home automation systems to industrial monitoring equipment.

Among the many sensors available for this purpose, the LM35 stands out as one of the most popular choices. With a typical accuracy of ±0.5°C, low power consumption, and a wide operating range (typically -55°C to 150°C depending on the package), it strikes an excellent balance between simplicity, cost, and performance.

LM35 Temperature Sensor

In this tutorial, you’ll learn how to wire the LM35 to an Arduino, and through three practical examples, you’ll gain a solid understanding of this sensor so you can confidently include it in bigger projects.

How the LM35 sensor works

The LM35 works on the principle that the voltage across a transistor’s base-emitter junction changes in a predictable way with temperature — it decreases by a small, consistent amount (roughly 2mV) for every 1°C rise in temperature. This is a natural electrical property of semiconductor junctions.

Inside the LM35 sensor

Inside the LM35, this voltage change is picked up and passed through a built-in amplifier circuit that scales and calibrates it precisely, so that the final output becomes exactly 10mV per °C. This internal calibration is what removes the need for the user to do any complex math or compensation — the sensor essentially does the conversion from “raw semiconductor behavior” to “clean, linear temperature signal” before the output ever leaves the chip.

 

You can find more information in the datasheet below.

When connected to an Arduino, the LM35’s analog output is read and converted into a temperature value through three distinct stages :

Stage 1: Analog Voltage → Digital ADC Value

The Arduino reads the LM35’s analog output using its built-in ADC and converts it into a digital value between 0 and 1023.

ADC_value = analogRead(A0)

Stage 2: Digital ADC Value → Voltage

This raw digital value is then converted back into an actual voltage, based on the Arduino’s reference voltage.

Voltage (mV) = (ADC_value / 1023) × 5000

Stage 3: Voltage → Temperature

Finally, the voltage is converted into a temperature reading using the LM35’s fixed 10mV/°C scale factor.

Temperature (°C) = Voltage (mV) / 10

LM35 linearity and conversion

ADC value

-

Voltage

-

Temperature

-

The LM35 output voltage increases linearly at 10 millivolts per degree Celsius across its full operating range.
25°C

LM35 Sensor Pinout

The LM35 is most commonly found in a TO-92 package — the same small plastic, half-moon-shaped case used for many transistors. It has three pins:

LM35 PINTOUT
VCC is the power supply input (4V to 30V DC)
OUT is the analog output voltage (10mV per °C)
GND is the ground / reference pin

Wiring the LM35 Sensor to the Arduino

The wiring is very straightforward :
⦿ Place the LM35 on your breadboard with the flat side facing you.
⦿ Connect the left pin (VCC) to the Arduino’s 5V pin using a red jumper wire.
⦿ Connect the middle pin (OUTPUT) to the Arduino’s A0 (Analog pin 0) using a yellow or orange wire.
⦿ Connect the right pin (GND) to the Arduino’s GND pin using a black or bleu wire.
⦿ Connect your Arduino to the computer via USB.

Warning : If you connect VCC and GND backwards, the LM35 will get hot instantly. If you feel heat coming from the sensor after connecting, disconnect immediately!

Example 1 : Reading temperature with LM35

This example shows how to read the LM35’s analog output and convert it into a temperature reading in degrees Celsius (°C) and degrees Fahrenheit (°F), displayed on the Serial Monitor. Keep the same wiring shown above.

const int sensorPin = A0;  // LM35 output connected to analog pin A0

void setup() {
  Serial.begin(9600);      // Start serial communication at 9600 baud
}

void loop() {
  int sensorValue = analogRead(sensorPin);           // Read raw ADC value (0-1023)
  float voltage = sensorValue * (5.0 / 1023.0);      // Convert ADC value to voltage
  float temperatureC = voltage * 100.0;              // Convert voltage to Celsius (10mV/°C)
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;  // Convert Celsius to Fahrenheit

  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.print(" °C / ");
  Serial.print(temperatureF);
  Serial.println(" °F");

  delay(1000);  // Wait 1 second before next reading
}

Once uploaded, open the Serial Monitor (set to 9600 baud) to see the live readings :

The values update every second, reflecting real-time changes in the sensor’s surrounding temperature. Try holding the LM35 between your fingers or blowing warm air on it to see the readings rise.

Code explanation

const int sensorPin = A0; Defines the analog pin connected to the LM35's output. Using a named constant makes the code easier to read and modify later.
Serial.begin(9600); Initializes serial communication between the Arduino and your computer at a baud rate of 9600, allowing you to view readings in the Serial Monitor.
analogRead(sensorPin); Reads the analog voltage on pin A0 and converts it into a digital value between 0 and 1023 (the Arduino's ADC has 10-bit resolution).
voltage = sensorValue * (5.0 / 1023.0); Converts the raw ADC reading back into an actual voltage. Since the Arduino's ADC maps 0–5V to 0–1023, dividing by 1023 and multiplying by 5.0 gives the voltage read by the pin.
temperatureC = voltage * 100.0; Converts the voltage into temperature. Since the LM35 outputs 10mV (0.01V) per degree Celsius, multiplying the voltage by 100 gives the temperature directly in °C.
temperatureF = (temperatureC * 9.0 / 5.0) + 32.0; Converts the Celsius value into Fahrenheit using the standard conversion formula.
Serial.print() / Serial.println() Sends the formatted temperature readings (both °C and °F) to the Serial Monitor for real-time viewing.
delay(1000); Pauses for one second between readings, keeping the output readable and preventing the Serial Monitor from flooding with data.

Example 2 : Improving the Accuracy of readings with the Arduino's Internal ADC Reference

By default, an Arduino’s Analog-to-Digital Converter (ADC) compares incoming sensor voltage against the board’s main 5V power supply. Because the Arduino uses a 10-bit ADC, it chops that 5V range into 1024 equal digital steps .

At room temperature (25°C), the LM35 sensor only outputs 0.25V (equivalent to 51 digital steps out of 1024), and even at 100°C it barely reaches 1V (equivalent to 205 digital steps out of 1024). That means the ADC only covers a small slice of its full 5V range, and a lot of resolution just goes to waste.

5V reference

5% used
0V 5V

This is where the internal 1.1V reference of the Arduino helps. Instead of spreading those 1024 steps across 5V, the Arduino spreads them across just 1.1V, so each step becomes much smaller -> about 1.07mV. Using the same example, that same 0.25V reading now corresponds to roughly 234 steps instead of 51. Same temperature, much more precision.

1.1V reference

91% used
0V 1.1V
In this example we will keep the same wiring and samply add the following line in the setup section analogReference(INTERNAL); .

Warning : When you activate the internal reference in code, the Arduino internally connects that 1.1V source to the AREF (Analog Reference) pin on the board. Do not connect any external wires or voltages to the AREF pin. Doing so will cause a short circuit inside the microcontroller and can permanently destroy your Arduino.

const int sensorPin = A0;  // LM35 output connected to analog pin A0

void setup() {
  Serial.begin(9600);      // Start serial communication at 9600 baud
  analogReference(INTERNAL);  // Use internal 1.1V reference (Uno/Nano/Mini)
  delay(1000);                // Allow reference voltage to stabilize
}

void loop() {
  int sensorValue = analogRead(sensorPin);           // Read raw ADC value (0-1023)
  float voltage = sensorValue * (1.1 / 1023.0);      // Convert ADC value to voltage
  float temperatureC = voltage * 100.0;              // Convert voltage to Celsius (10mV/°C)
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;  // Convert Celsius to Fahrenheit

  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.print(" °C / ");
  Serial.print(temperatureF);
  Serial.println(" °F");

  delay(1000);  // Wait 1 second before next reading
}

Code explanation

analogReference(INTERNAL); Switches the ADC's reference voltage from the default 5V to the chip's internal 1.1V reference.
delay(1000); in setup() Gives the internal reference voltage time to stabilize after switching, since the first few readings can be inaccurate right after changing the reference.
voltage = sensorValue * (1.1 / 1023.0); using 1.1V instead of 5V.
● The rest of the code Serial.begin , analogRead , Serial.print works the same way as in Example 1.

Example 3 : Making thermometer with LM35 and 16x2 I2C LCD Display

In this example, we read the temperature with the LM35 sensor, but instead of showing the readings on the Serial Monitor, we display them on a 16×2 I2C LCD. This means you can disconnect the PC after uploading the code and power the Arduino with a battery to create a standalone thermometer.

 

Update the connections as shown below.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address 0x27, 16 columns, 2 rows
const int sensorPin = A0;             // LM35 output connected to analog pin A0

void setup() {
  analogReference(INTERNAL);  // Use internal 1.1V reference (Uno/Nano/Mini)
  delay(1000);                 // Allow reference voltage to stabilize

  lcd.init();          // Initialize the LCD
  lcd.backlight();      // Turn on the backlight
  lcd.setCursor(0, 0);
  lcd.print("LM35 Thermometer");
  delay(1500);
  lcd.clear();
}

void loop() {
  int sensorValue = analogRead(sensorPin);           // Read raw ADC value (0-1023)
  float voltage = sensorValue * (1.1 / 1023.0);      // Convert ADC value to voltage using 1.1V reference
  float temperatureC = voltage * 100.0;              // Convert voltage to Celsius (10mV/°C)

  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temperatureC);
  lcd.print((char)223);  // Degree symbol
  lcd.print("C");

  delay(1000);
}

The LCD will briefly show “LM35 Thermometer” on startup, then continuously display the room temperature. The reading updates every second and holds steady thanks to the internal reference

Subscribe
Notify of
guest
0 Comments
Scroll to Top