Arduino LM35 Temperature Sensor Interfacing

In this tutorial, you’ll learn how to interface Arduino with LM35 Temperature Sensor and use it to measure the surrounding temperature in degrees Celsius and Fahrenheit. We’ll create a couple of Arduino LM35 code example projects to practice what we’ll learn in this tutorial.

And we’ll also interface Arduino with LM35 and I2C LCD in this tutorial as well. Moreover, we’ll interface Multiple LM35 Temperature Sensors With Arduino and display the temperature readings independently in another project within this tutorial. Without further ado, let’s jump right into it!

Table of Contents

  1. Arduino LM35 Temperature Sensor
  2. Arduino LM35 Interfacing
  3. Arduino LM35 Code Example – Temperature Sensor
  4. Arduino LM35 LCD Example
  5. Arduino Multiple LM35 Temperature Sensors Example
  6. Wrap Up

Arduino LM35 Temperature Sensor

LM35-Temperature-Sensor

The LM35 is a temperature sensor widely used in electronic projects and midrange devices. It has limited usage in industrial applications due to maximum temperature range limitations. It’s rated to a full range of −55°C to 150°C.

You can power it up and instantly read the voltage level on the output terminal. The VOUT of the sensor directly maps to the sensor’s temperature as we’ll see hereafter.

LM35 Sensor Technical Specifications

  • Linear + 10-mV/°C Scale Factor
  • 0.5°C Ensured Accuracy (at 25°C)
  • Rated for Full −55°C to 150°C Range
  • Operates From 4 V to 30 V
  • Less Than 60-μA Current Drain
  • Non-Linearity Only ±¼°C Typical

LM35 Pinout

LM35 Temperature Sensor Pinout - ESP32 Arduino Tutorial

LM35 V-T Characteristics

As stated in the LM35 temperature sensor datasheet, the accuracy specifications of the LM35 are given with respect to a simple linear transfer function:

VOUT = (10 mv / °C) × T

where VOUT is the LM35 output voltage & T is the temperature in °C. And this is what we’ll be using in code in order to convert the ADC voltage readings to temperature values (in °C or °F).

You can play with the interactive tool below to see how the sensor’s analog output voltage changes when the temperature value is changed. And it’ll also show you the ADC digital value as captured (measured) by the Arduino code.



25 °C


0.25 v


128
❕ Note

At the maximum temperature (+150°C), the sensor’s output analog voltage will be almost 1.5v which is quite far from the Arduino’s ADC reference voltage (+5v). This means that most of the ADC’s range will stay unused and the voltage measurement resolution will be 5v/1024 = 5mv, which means we’ve got a temperature measurement resolution of 0.5°C.

The 0.5°C resolution is “luckily” equal to the sensor’s accuracy so we don’t need to enhance the measurement resolution by changing the ADC’s VREF voltage to a lower value because the voltage resolution increase will not improve the overall measurement resolution due to the sensor’s characteristic accuracy itself.

Arduino ADC (Analog Input)

The Arduino UNO has 6 analog input pins labeled from A0 to A5 as shown in the figure below. Those pins can be used with analog peripherals in the Arduino microcontroller such as ADC (A/D Converter) and the Analog Comparator.

Arduino-UNO-Pinout-Analog-Input-Pins-ADC

The Arduino ADC resolution is 10 bits, the digital output range is therefore from 0 up to 1023. And the analog input range is from 0v up to 5v (which is the default analog reference voltage VREF = +5v).

You can use the interactive tool below to set an analog input voltage and see the ADC digital output value that corresponds to the analog input voltage. The output equation for the ADC is as follows: ADC Output = ( Analog input voltage / VREF ) x (2n – 1). Where VREF = 5v and n is the ADC resolution which is 10bits.


0V
0

It’s Highly Recommended to check out the tutorial below to learn more about Arduino ADC. It’s a prerequisite for this Arduino LM35 temperature sensor interfacing tutorial to help you understand the topic in more detail.

💡 Also Read
Arduino ADC analogRead Tutorial

This tutorial is the ultimate guide for Arduino ADC & reading analog input voltages using the analogRead() function. You’ll learn, in-depth, everything about Arduino ADC, how it works, and how to make the best use of it with a lot of tips and tricks all the way through.


Arduino LM35 Interfacing

The LM35 sensor is a very popular temperature sensor that can easily be used with Arduino using the ADC analog input pin. It’s got a linear voltage output response with a slope of 10mv per °C. The typical LM35 temperature sensor’s operating range is (0°C To 150°C) but it can also measure negative temperatures down to -55°C below zero.

LM35 Temperature Sensor Configurations

You can connect your LM35 temperature sensor according to any of the following configurations (circuits) depending on your application and what you’re trying to achieve with it. It can normally measure positive temperatures (0°C To 150°C) with no extra components or circuitry.

And it can also measure negative temperatures down to -55°C and up to +150°C using the dual-supply configurations and an additional resistor. You’ll need, for example, a +5v power source, a -5v source, and a resistor R1 = 5v/50µA = 100kΩ.

If you need to measure negative temperatures with the LM35 sensor and don’t want to use dual-supply (positive & negative), you can still use the 3rd configuration shown below. It’ll require additional 2 diodes and 1 resistor (18kΩ). And you’ll also need 2 analog input pins to measure the differential voltage output of this configuration.

Arduino-LM35-Temperature-Sensor-Configurations

Arduino LM35 Wiring (Circuit Diagram)

Here is the wiring diagram for Arduino with the LM35 temperature sensor. Note that I’m using the basic LM35 configuration (positive temperature sensing).

And I’m using the A0 analog input pin to read the analog output voltage of the LM35 temperature sensor.

Arduino LM35 Wiring (Connection) Diagram

Arduino LM35 Code

Here is a test code example that reads the LM35 temperature sensor’s output on the A0 analog input pin and prints the temperature value to the serial monitor over UART. You can use it to check that your wiring and connections are all okay.


Arduino LM35 Code Example – Temperature Sensor

In this example project, we’ll use Arduino analog input with an LM35 temperature sensor to read the temperature value and print it over UART to the serial monitor in both units (degrees Celsius °C and Fahrenheit °F).

Code Example

Here is the complete code listing for this example.

Code Explanation

First, we define the IO pin used for the LM35 temperature sensor’s analog voltage reading. And we’ll also define some variables to be used during the voltage-to-temperature conversion process.

setup()

in the setup() function, we’ll initialize the UART serial port communication @ 9600bps baud rate.

loop()

in the loop() function, we’ll call the analogRead() function to get the voltage reading of the LM35 sensor. We’ll then convert it to voltage (in mv) and use that value to get the temperature in (°C and °F) units.

Then, we’ll just format the message string and send it over UART to be printed on the serial monitor at the PC side.

Proteus (ISIS) Simulation

Proteus (ISIS) is an extremely powerful simulation environment for Arduino. It can definitely run our test projects for this tutorial. But you won’t feel its power until you need some virtual test equipment like an oscilloscope, function generator, power supply, and advanced SPICE simulation for auxiliary electronic circuitry that you may build around an Arduino microcontroller.

Here is the Arduino project simulation result from the Proteus environment.

Arduino-LM35-Simulation

Check out the tutorial below to help you get started with simulating your Arduino projects in the Proteus simulation environment.

💡 Also Read
Arduino Proteus Library Simulation Guide

This article will provide you with more in-depth information about using proteus ISIS for Arduino projects simulation.

Testing Results

Here is a demo video for testing this project on my Arduino UNO board.


Arduino LM35 LCD Example

In this example project, we’ll use Arduino with an LM35 temperature sensor and I2C LCD 16×2 display to print out the temperature measurement. This example project will use the I2C LCD 16×2 with Arduino which you can learn more about by checking the tutorial linked below.

💡 Also Read
Arduino I2C LCD 16x2 Interfacing Tutorial & Library Examples

This is the ultimate guide for Arduino I2C LCD 16×2 interfacing and library functions explanation. It’ll guide you through everything you’d need to interface Arduino with an I2C LCD display.

Code Example

Here is the complete code listing for this example project.

Code Explanation

First of all, we should include the Wire.h library for I2C communication and the LiquidCrystal_I2C.h library for the I2C LCD control.

Then, we’ll define the analog input pin to be used for the LM35 sensor reading, we’ll create an instance of the I2C_LCD class, and define some variables to be used in the voltage-to-temperature measurement & conversion process.

setup()

in the setup() function, we’ll initialize the I2C LCD display and turn ON its backlight.

loop()

in the loop() function, we’ll call the analogRead() function to get the voltage reading of the LM35 sensor. We’ll then convert it to voltage (in mv) and use that value to get the temperature in the (°C) unit.

Then, we’ll construct the string message that shows the resulting measured temperature and print it on the I2C LCD display.

Testing Results

Here is a demo video for testing this project on my Arduino UNO board.


Arduino Multiple LM35 Temperature Sensors Example

In this example project, we’ll use multiple LM35 temperature sensors with Arduino and I2C LCD display. We’ll take the temperature measurement from both sensors and display them separately on the I2C LCD display.

Code Example

Here is the complete code listing for this example.

Code Explanation

First of all, we should include the Wire.h library for I2C communication and the LiquidCrystal_I2C.h library for the I2C LCD control.

Then, we’ll define the 2 analog input pins to be used for the two LM35 sensors reading, we’ll create an instance of the I2C_LCD class, and define some variables to be used in the voltage-to-temperature measurement & conversion process.

setup()

in the setup() function, we’ll initialize the I2C LCD display and turn ON its backlight.

loop()

in the loop() function, we’ll call the analogRead() function to get the voltage reading of the first LM35 sensor. We’ll then convert it to voltage (in mv) and use that value to get the temperature in the (°C) unit.

We’ll do exactly the same logic to get the reading of the second LM35 temperature sensor.

Then, we’ll construct the string message that shows the resulting measured temperatures from LM35 sensors 1 & 2. Then, we’ll print both temperature readings on the I2C LCD display.

Testing Results

Here is a demo video for testing this project on my Arduino UNO board.


Parts List

Here is the full components list for all parts that you’d need in order to perform the practical LABs mentioned here in this article and for the whole Arduino Programming series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.

Download Attachments

You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting my work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports our community.


Wrap Up

To conclude this tutorial, we can say that you can easily interface Arduino with an LM35 temperature sensor to read the surrounding temperature and use that information for various Arduino projects. You can build on top of the examples provided here in this tutorial to create so many applications, you’re only limited by your imagination. Let me know if you have further questions or need help implementing your project.

If you’re just getting started with Arduino, you need to check out the Arduino Getting Started [Ultimate Guide] here.

And follow this Arduino Series of Tutorials to learn more about Arduino Programming.

💡 Also Read
Getting Started With Arduino Programming For Beginners

This is the ultimate guide for getting started with Arduino for beginners. It’ll help you learn the Arduino fundamentals for Hardware & Software and understand the basics required to accelerate your learning journey with Arduino Programming.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?