Skip to content
Home » Embedded Systems » Sensors » LM35 Temperature Sensor: Working, Circuit, and Arduino Code

LM35 Temperature Sensor: Working, Circuit, and Arduino Code

LM35 temperature sensor with pinout diagram and thermometer visual representation showing temperature monitoring application
Sensors for Embedded Systems
Part 5 of 18 — View Full Path →

KEY TAKEAWAYS

  • The LM35 is a precision analog temperature sensor with a linear 10mV/°C output
  • No external calibration is needed — it outputs 0V at 0°C and 1V at 100°C
  • Connect the analog output to an ADC pin and convert the reading: temp = (ADC_value * 5.0 / 1024) * 100
  • The LM35 is suitable for ambient temperature monitoring in the range of -55°C to +150°C
LM35 is a temperature sensor that outputs an analog signal which is proportional to the instantaneous temperature. The output voltage can easily be interpreted to obtain a temperature reading in Celsius. The advantage of lm35 over thermistor is it does not require any external calibration. The coating also protects it from self-heating. Low cost (approximately Rs. 70) and greater accuracy make it popular among hobbyists, DIY circuit makers, and students.Many low-end products take advantage of low cost, greater accuracy and used LM35 in their products. Its approximately 15+ years to its first release but the sensor is still surviving and is used in any products.

LM35 Temperature sensor Features

  • Calibrated Directly in Celsius (Centigrade)
  • Linear + 10-mV/°C Scale Factor
  • 0.5°C Ensured Accuracy (at 25°C)
  • Rated for Full −55°C to 150°C Range
  • Suitable for Remote Applications
  • Operates from 4 V to 30 V
  • Less than 60-µA Current Drain
  • Low Self-Heating, 0.08°C in Still Air
  • Non-Linearity Only ±¼°C Typical
  • Low-Impedance Output, 0.1 Ω for 1-mA Load

LM35 Pin-Out:

The LM35 consists of only three pins. The pin-out is as follows:lm35-pinout

LM35 Working Principle (LM35 output):

Linear + 10-mV/°C Scale Factor

In order to understand the working principle of LM35 temperature sensor we have to understand the linear scale factor. In the features of LM35 it is given to be +10 mills volt per degree centigrade. It means that with an increase of 1 degree Celcius in the temperature, the output at the Vout pin will increase by 10 millivolts. For example, if the sensor is outputting 300 millivolts at Vout pin, the temperature in centigrade will be 30-degree centigrade. The same goes for the negative temperature reading. If the sensor is outputting -100 mills volt the temperature will be -10 degrees Celsius.
Temperature (in °C)Vout (in mv)
-10-100
110
10100
20200
30300
90900
1501500
 LM35_Vout_chart

LM35 Temperature Sensor Circuit Configuration

LM35_temperature_sensor_circuitLM35 can be used in two circuit configurations. Both yield different results.In the first configuration, you can only measure the positive temperature from 2 degrees Celsius to 150 degrees Celsius. For this configuration, we simply power lm35 and connect the output directly to analog to digital converters.In the second configuration, we can utilize all the sensor resources and can measure the full range temperature from -55 degree centigrade to 150-degree centigrade. This configuration is a little complex but yields better results. We have to connect an external resistor, in this case, to switch the level of negative voltage upwards. The external resistor value can be calculated from the formula given below the configuration circuit.The second configuration circuit can be made in various ways.To see about the second configuration circuits visit the LM35 datasheet by Texas Instruments. Texas Instruments data sheet enlists the circuit with clear component values.

Steps to calculate temperature using LM35 temperature sensor

  • Build circuit.
  • Power LM35 vcc to +5-20 volts and gnd to ground.
  • Connect Vout to analog to digital converter input.
  • Sample the ADC reading, vout output voltage.
  • Convert the voltage to temperature.

Formula to convert voltage to temperature

The formula to convert the voltage to centigrade temperature for LM35 is

Centigrade Temperature = Voltage Read by ADC / 10 mV(mills Volt) 

I divided by 10 mV because Linear scale factor is for LM35 is 10mV. Following the above steps and tutorial, you can easily interface LM35 temperature sensor with any microcontroller that has a built-in analog to digital converter pins. Almost all the microcontrollers today have built-in ADC.For a demonstration and an example, I will use Arduino and show you how to interface LM35 with an Arduino

LM35 with Arduino:

For this tutorial we need an arduino board(Uno, Maga, Lenardo etc) and Lm35 temperature sensor. I am using Arduino Uno. What we will do is:
  1. Make the Circuit
  2. Read the Temperature Sensor Output
  3. Convert the ADC Value to equivalent temparature
  4. Display the data in serial monitor
Let’s get started:

1) Make the Circuit

LM35_temperature_sensor_arduino_connectionsConnect the LM35 with Arduino in the way it is shown in the circuit diagram above. The connections are:
LM35Arduino
Pin 1 – Vcc5v
Pin2 – VoutA0
Pin3 – GndGnd

2) Read the Temperature Sensor Output

To read the sensor output, we will simply call the analogRead() function in Arduino. To this function, we need to pass the ADC channel value, or A0 in our case. A0 is the pin to which the sensor output pin is connected. We will store the result in a variable named ADCValue.
float ADCValue;
ADCValue = analogRead(A0);

3) Convert the ADC Value to equivalent temparature

Now that we have the ADC value in a variable, we have to do two things:
  1. Convert the ADC Value to equivalent voltage
  2. Convert the voltage to temperature reading
For the first step, we have to divide the ADCValue with the maximum possible value of the ADC. The Arduino ADC is a 10-bit ADC. So, the maximum value can be (2^10-1) = 1023. We subtract 1 because the count starts from zero. We get the value of ADC as 1023 if the voltage is 5v.The calculation follows simple unitary method:If the value is 1023, the voltage = 5If the value is 1, the voltage = (5/1023)If the value is ADCValue, the voltage is = (5/1023)*ADCValueIn Arduino, we write this as follows:
float tempVoltage = 0;

tempVoltage = (5/1023)*ADCValue;
Example: if the temperature is 30 degrees, the sensor output will be 300 mV. This will give an ADCValue = 61Converting this value to voltage = (5/1023)*61 = 0.298VSince our sensor output is in mV, we will multiply the entire value with 1000 to convert from voltage to milliVolts. So, our new statement becomes:
tempVoltage = ((5/1023)*ADCValue)*1000; //sensor output in milli volts

Now that we have the voltage of the sensor, we need to convert it to equivalent temperature. Remember, we saw earlier that the scaling factor of LM35 is 10mV/degree Celcius? That is, For every degree celcius of the temperature, the sensor output is 10 mV.So, if we have the mV reading of the sensor and divide it by 10, the new value will be our temperature. Let’s do that:
float temperature = 0;

temperature = tempVoltage/10; //temperature in Celcius

4) Display the data in serial monitor

We will now display this calculated temperature in the serial monitor:
Serial.print("Temperature = ");
Serial.println(temperature);
 

LM35 with Arduino – Full Code:

Combining all the above knowledge together, we have a small code that can give us the temperature
//Arduino code to read temperature from LM35 Temperature Sensor
// by Nerdyelectronics.com

void setup()
{
    Serial.begin(9600); //initialize serial communication with 9600 baud rate
}

void loop()
{
    float ADCValue;
    float tempVoltage = 0;
    float temperature = 0;

    ADCValue = analogRead(A0);
    tempVoltage = ((5/1023)*ADCValue)*1000; //sensor output in milli volts
    temperature = tempVoltage/10; //temperature in Celcius

    Serial.print("Temperature = ");
    Serial.println(temperature);

    delay(5000); //We will check the temperature every 5 seconds
}
That’s all about LM35 and how to use it for monitoring the temperature. As an upgrade, you can think about sending the temperature value to the cloud. This post explains in details how to send sensor data to the cloud. In the example in the post, I have used LM35 to read the temperature and then send it to cloud.

Common Mistakes When Using the LM35

  • Integer division in ADC conversion: Writing (5/1023)*ADCValue in C produces zero because 5/1023 is integer division. Use (5.0/1023.0)*ADCValue or ADCValue * 5.0 / 1023.0 to force floating-point math.
  • Using the wrong reference voltage: If your Arduino is powered via USB, the 5V rail may actually be 4.6–4.8V. For better accuracy, use the internal 1.1V reference (analogReference(INTERNAL)) and adjust the calculation: temperature = ADCValue * 1.1 / 1023.0 * 100.0. The 1.1V reference is stable regardless of USB voltage.
  • No decoupling capacitor: The LM35 output is analog and susceptible to noise. Add a 100nF ceramic capacitor between VCC and GND, placed as close to the sensor as possible. Without it, readings can jump ±2–3°C randomly.
  • Long wire runs without shielding: If the LM35 is more than 30 cm from the Arduino, the analog signal picks up noise from nearby digital signals and motors. Either use shielded cable or add a 100Ω resistor in series with the output and a 1µF capacitor to ground at the ADC input (low-pass filter).
  • Reading too fast: The LM35 output stabilises about 2–4 ms after a power change. If you are switching the sensor on/off to save power, add a short delay before reading. Also, calling analogRead() in a tight loop with no delay floods the serial monitor and makes the output unreadable — a delay(1000) is usually sufficient for temperature monitoring.
  • Expecting sub-zero readings on Arduino: The LM35 can measure down to -55°C, but only with a negative supply voltage on pin 3 (or a pull-down resistor circuit). With the standard 3-pin connection to Arduino, it can only read 0°C and above. The datasheet shows the required circuit for negative temperature measurement.

📖 Related: Power Supply and Voltage Regulators for Embedded Systems • ADC in Microcontrollers: How It Works, Reading Patterns, and Common Pitfalls

Going further: The LM35 outputs an analog voltage that the MCU reads through its ADC — for the full picture on resolution, reference voltage, sampling, and the common pitfalls, see our ADC in Microcontrollers guide.

Leave a Reply

Your email address will not be published. Required fields are marked *