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:
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
ADC value
-
Voltage
-
Temperature
-
Wiring the LM35 Sensor to the Arduino
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
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% usedThis 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% usedconst 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.