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.

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 : Power supply input (4V to 30V DC)

OUT : Analog output voltage (10mV per °C)

GND : Ground / reference pin

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

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

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
const int sensorPin = A0;

Note : Without this line, nothing will appear in the Serial Monitor. Make sure your Serial Monitor is also set to 9600 baud.

Tip : Touch the sensor gently with your finger. The temperature should rise by a few degrees within a few seconds. Then release it and the reading should slowly come back down. If this happens, your LM35 is working correctly.

Resources

feel free to ask any questions in the comments.
Subscribe
Notify of
guest
0 Comments
Scroll to Top