Example Code for Raspberry Pi – LM35 Analog Linear Temperature Sensor

Last revision 2026/01/20

This article offers example code and instructions for using the LM35 Analog Linear Temperature Sensor with Raspberry Pi, detailing sensor specifications, setup requirements, and coding steps using Thonny IDE to achieve accurate temperature readings and interactive project effects.

Introduction

Based on LM35 semiconductor, this sensor produced by National Semiconductor Corporation can be used to detect ambient temperature. It offers a measurement range from -40 °C to 150 °C and a sensitivity of 10 mV/°C. And its output voltage is proportional to the temperature. Moreover, if used in combination with sensor-specific expansion of Arduino board, this sensor can be really easy to achieve interactive effects related to ambient temperature perception.

Commonly-used sensors for temperature measurement include thermocouples, platinum resistance, thermal resistance and temperature semiconductor chips. Thermocouples are commonly used in high temperature measurement. Platinum resistance temperature modules are used in measurement of 800 degrees Celsius, while the thermal resistance and semiconductor temperature sensor are suitable for measuring the temperature of 100-200 degrees or below. With good linearity and high sensitivity, the semiconductor temperature sensor is easy to use.

Precautions

The port layout of the new analog sensor has the following two improvements. Please refer to the blog How to change the layout of the data cable connector. When using this sensor on the IO expansion board, you may need to adjust the layout of the connector. For your convenience, we will make more improvements, so stay tuned.

Wiring Diagram

  • Connect the sensor to the analog pin 0 on the expansion board

Sample Code

  • Open Thonny Python IDE to copy the following program into it

Was this article helpful?

TOP