30. Interface LM35 temperature sensor

To connect and use the LM35 temperature sensor with a microcontroller, enabling accurate temperature measurement across the sensor’s full rated range.

Understanding the LM35 Sensor

LM35-Sensor-pinout
  • Temperature Range: -55°C to +150°C
  • Output Scale: 10 millivolts (mV) per 1°C
  • Default Output Voltage:
    • When GND = 0V, the OUT pin voltage ranges from -0.55V to +1.5V (corresponding to the sensor’s min/max temperatures)
  • Output Formula:
    • Output Voltage (V) = (Temperature in °C) × 10mV

Output Voltage Shifting: Why and How

Why Shift the Output?

  • Most microcontroller ADCs (Analog-to-Digital Converters) only measure voltages in the 0–3.3V or 0–5V range.
  • The LM35 can output negative voltages if the GND pin is at 0V and measures negative temperatures—these cannot be detected directly by most ADCs.

How to Shift the Output?

  • Technique: Raise the voltage on the LM35’s GND pin above 0V (using a voltage divider).
  • Effect: Shifts the LM35 OUT voltages into the positive range, ensuring all outputs fit within the ADC’s measurable limits.

Using a Voltage Divider 

  • Construct a voltage divider with two resistors (R1 and R2) between the microcontroller’s supply voltage and ground.
  • Voltage at the divider (Vshift):

Vshift = Vcc × (R2 / (R1+R2))

  • Connect Vshift to the GND pin of the LM35.
  • Choose R1 and R2 to set Vshift so that the entire LM35 output range (relative to shifted ground) fits within the ADC range.

Choosing R1 and R2

  • Resistor values determine the shifted ground; choose them so your LM35 output always falls within the ADC’s range.
  • Example:
    • R1 = 10 kΩR2 = 3.3 kΩ (with Vcc = 5V)
    • Vshift = 5 x ( 3300 / ( 10000 + 3300) = 1.24 V 

 

  • Corresponding Output Range:
    • At -55 degrees Celsius: Vmin = Vshift + (-0.55V) = 0.69V
    • At 150 degrees Celsius: Vmax = Vshift + (1.5V) = 2.74V
    • Both values fall within typical ADC ranges (0–3.3V or 0–5V).

Circuit Connections Overview

  • LM35 Vout:
    • Connect to one ADC channel
  • Voltage Divider Output (Vshift):
    • Connects to the LM35 GND pin
    • Also, connect to another ADC channel to monitor the reference shift
LM35-temprature-sensor-connection

Measurement Process

  1. Read ADC1: Measures LM35 output voltage (Vout)
  2. Read ADC2: Measures the shifted ground voltage (Vshift)
  3. Calculate Sensor Voltage:

Vsensor = (VLM35 OUT) − Vshift

Temperature Calculation

  • Convert Voltage to Temperature:
    1. Find the voltage difference (from above), in millivolts (mV)
    2. Use the scale factor:

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

  • e.g., 250mV difference = 25°C

Notes

  • Select resistor values so that the shifted range matches your ADC’s capability.
  • Optionally, use an op-amp buffer for the voltage divider to avoid a voltage drop if the sensor draws current.
  • For best results, use precision resistors and ensure stable supply voltages.

Negative temperature detection

  • Measuring negative temperature would require liquid nitrogen, but it is -196 °C. So, it will damage our sensor.
  • Unfortunately, we will skip measuring negative temperature for the demonstration.

So, by considering the above points, we can implement the task. Below are the solutions to the given task using different microcontrollers

  1. STM32
  2. Arduino UNO

Note: The current task requires a highly accurate ADC. However, the ESP32’s built-in ADC is non-linear and shows poor accuracy near the voltage edges (close to 0 V and Vref). Due to this limitation,  we are not implementing this task using ESP32.

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!