LM35 Interfacing with Arduino, Temperature Measurement and Display

LM35 Interfacing with Arduino
LM35 Interfacing with Arduino

Accurately measuring temperature in your projects is essential, and the LM35 temperature sensor offers a simple and cost-effective solution. When used with an Arduino board, this can provide accurate measurements of temperature for a wide range of applications including home automation systems and weather stations. This guide will help you understand how to use LM35 temperature sensor with Arduino, read off temperature values, and implement some example projects.

 How to Interface the LM35 Temperature Sensor with Arduino

Interfacing the LM35 temperature sensor with an Arduino is straightforward due to the sensor’s linear output and ease of use. The LM35 outputs a voltage that is directly proportional to the Celsius temperature, which the Arduino can read and process to display temperature readings accurately.

 What is the LM35 Temperature Sensor?

A very popular and commonly used temperature sensor in various electronics projects is the LM35. It is popular for being simple, cheap and accurate. The LM35 provides a linear voltage output proportional to the Celsius temperature that permits it to be easily interfaced with microcontrollers such as Arduino.

 LM35 Features

The LM35 temperature sensor has several notable features that make it ideal for temperature measurement in electronics projects. These are summarized as follows:

  • Linear output: The LM35 outputs 10 mV per degree Celsius.
  • Wide temperature range: -55°C to 150°C.
  • High accuracy: ±0.25°C at room temperature and ±0.75°C over the full range.
  • Low self-heating: Less than 0.1°C in still air.
  • Operates from 4V to 30V: Compatible with various power supplies.

 LM35 Pinout

Understanding the pinout of the LM35 is crucial for correct wiring.

LM35 Pinout

The LM35 has three pins:

1. Vcc (Power Supply): Connects to the 5V pin of the Arduino.

2. Output: Provides a voltage proportional to the temperature.

3. GND (Ground): Connects to the ground of the Arduino.

 LM35 Interfacing with Arduino

Connecting the LM35 to an Arduino is a simple process that requires minimal components. This section will guide you through the necessary hardware, the connections you need to make, and how to program your Arduino to read the temperature data from the sensor.

 Hardware Required

To connect the LM35 to an Arduino, you’ll need the following components:

  • Arduino board (e.g., Uno, Nano, Mega)
  • LM35 temperature sensor
  • Breadboard
  • Jumper wires
  • LCD display (optional for displaying temperature)
  • 7-segment display (optional)
  • I2C LCD display (optional)

 Arduino LM35 Setup

Follow these steps to connect the LM35 to the Arduino:

  1. Connect Vcc: Connect the Vcc pin of the LM35 to the 5V pin on the Arduino.
  2. Connect GND: Connect the GND pin of the LM35 to the ground (GND) pin on the Arduino.
  3. Connect Output: Connect the output pin of the LM35 to one of the analog input pins (e.g., A0) on the Arduino.

The following circuit is a LM35 arduino circuit diagram. In this setup, the LM35 sensor is connected to the Arduino with three pins: Vcc to the 5V pin on the Arduino, GND to the ground pin, and the output pin to the  analog input pin A0. This configuration allows the Arduino to read the analog voltage from the LM35, which is proportional to the temperature in Celsius, and convert it into a readable temperature value using simple code.

Arduino Interfacing with LM35
Arduino Interfacing with LM35

 Programming the Arduino

To read temperatures from the LM35 you will need to write this basic Arduino program. Try the following Arduino code for lm35 temperature sensor:

const int sensorPin = A0; // Pin where the LM35 is connected
float temperature; // Variable to store the temperature value

void setup() {
  Serial.begin(9600); // Initialize serial communication
}

void loop() {
  int sensorValue = analogRead(sensorPin); // Read the analog value
  float voltage = sensorValue * (5.0 / 1023.0); // Convert the value to voltage
  temperature = voltage * 100; // Convert the voltage to temperature
  Serial.print("Temperature: ");
  Serial.print(temperature); 
  Serial.println(" °C");
  delay(1000); // Wait a second before reading again
}

Arduino LM35 temperature sensor code

This Arduino LM35 code reads the temperature from the sensor and prints it to the Serial Monitor.

 Reading Temperature Values

Once your Arduino is correctly set up to read the LM35 sensor, the next step is to interpret these readings accurately. This section will cover the essential steps to set up your code, calculate the voltage from the sensor, and convert this voltage into a meaningful temperature value in Celsius.

 Setting Up the Code

Ensure your Arduino IDE is correctly set up and use above LM35 Arduino code which should be uploaded directly into your Arduino board. Open the Serial Monitor to see the temperature readings.

LM35 voltage Temperature Equation

The LM35 produces an output voltage that corresponds to the temperature. To convert analog reading to voltage, we can use this formula:

LM35 Voltage Equation

From there, converting the voltage into Celsius degrees is straightforward:

LM35 Temperature Equation

The reason this calculation works is because one degree Celsius corresponds to 10 mV in case of LM35.

 Advanced Examples

For those looking to expand their projects, the LM35 can be paired with additional displays and sensors to create more sophisticated systems. This section includes advanced examples using an LCD display, a 7 segment display, and an I2C LCD display.

 Arduino LM35 Temperature Sensor with LCD Display

The following circuit is a schematic diagram for the Arduino and LM35 with a 16×2 LCD screen. In this setup, the LM35 is connected as before with Vcc, GND, and output to A0. Additionally, the 16×2 LCD is connected to the Arduino using digital pins 12, 11, 5, 4, 3, and 2. For more information about the 16×2 LCD please refer to our previous article: 16×2 LCD Interfacing with Arduino including the code.

This configuration enables the Arduino to display the temperature readings from the LM35 sensor directly on the LCD screen, providing a real-time visual output of the temperature data.

Arduino Interfacing with LM35 and LCD 16x2
Arduino Interfacing with LM35 and LCD 16×2

Arduino LM35 temperature sensor with lcd display code

To display the temperature on an LCD, connect the LM35 with Arduino and lcd as shown above and use the following code:

#include <LiquidCrystal.h>

const int sensorPin = A0; // Pin where the LM35 is connected
float temperature; // Variable to store the temperature value

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Initialize the library with the numbers of the interface pins

void setup() {
  lcd.begin(16, 2); // Set up the LCD's number of columns and rows
  Serial.begin(9600); // Initialize serial communication
}

void loop() {
  int sensorValue = analogRead(sensorPin); // Read the analog value
  float voltage = sensorValue * (5.0 / 1023.0); // Convert the value to voltage
  temperature = voltage * 100; // Convert the voltage to temperature
  
  lcd.setCursor(0, 0); // Set the cursor to column 0, line 1
  lcd.print("Temp: ");
  lcd.print(temperature); 
  lcd.print(" C");
  
  Serial.print("Temperature: ");
  Serial.print(temperature); 
  Serial.println(" °C");
  delay(1000); // Wait a second before reading again
}

This Arduino LM35 temperature sensor with lcd display code example shows the temperature on an LCD display.

 Arduino LM35 Temperature Sensor with 7 Segment Display

To use a 7 segment display, connect it to your Arduino and use appropriate libraries and code to display the temperature. This involves more complex wiring and coding but can be achieved similarly to the LCD example.

Arduino LM35 Temperature Sensor with I2C LCD Display

For an I2C LCD display, you will need to use the Wire library and an I2C LCD library. This simplifies wiring and coding by using only two pins for communication.

Arduino LM35 negative temperature

The LM35 can measure temperatures below 0°C. However, you need to handle the negative voltage output correctly in your code. Most Arduino boards can read negative temperatures if the appropriate calculations are made.

Example Projects

Moreover, there are various practical projects where an LM35 temperature sensor combined with an Arduino can prove useful. For instance, they include room thermostat systems; a temperature monitoring system and even weather stations.

 Temperature Monitoring System

Develop a system that continuously performs temperature measurement using lm35 and Arduino and logs temperature data – realtime display via LCD or storing it on SD card for further analysis may be used.

 Room Thermostat

Build a room thermostat that maintains a desired temperature. Use the LM35 sensor with Arduino to monitor the room temperature and control a heating or cooling device based on the readings.

 Weather Station

Integrate the LM35 sensor into a weather station project. Combine it with other sensors to measure humidity, pressure, etc., providing comprehensive weather data.

FAQ

Which sensor is the LM35?

The LM35 is a precision integrated-circuit based temperature sensing device. This means that it produces a linear output voltage with changes in Celsius temperature making it easier to use. The reason why this device is highly rated includes: its precision, modest cost and ease of interfacing with microcontrollers like Arduino.

Why is the LM35 used as a temperature sensor?

The LM35 temperature sensor is a good choice, because it has high accuracy, linear output and simple operation. It provides a voltage output that is directly proportional to the Celsius temperature, while eliminating the need for complex calibration. Additionally, this sensor has a low power consumption and can measure a temperature range over -55°C to 150°C which makes it suitable for different applications.

What voltage does the LM35 output?

The LM35 outputs 10 mV/°C, so it has a linear scale factor that makes temperature calculations easy.

How accurate is the LM35?

The LM35 has an accuracy of ±1⁄4°C at room temperature and ±3⁄4°C over the full -55°C to 150°C range, making it very suitable for most temperature measurement applications.

What’s the easiest way to interface the LM35 with Arduino?

The simplest connection is to power the LM35 from the Arduino 5V pin, connect the LM35 output pin to an analog input, and write code to read the voltage and convert to temperature.

How do I connect an LM35 to an Arduino?

To connect the LM35 temperature sensor to an Arduino, follow these steps:
1. Connect the Vcc pin of the LM35 to the 5V pin on the Arduino.
2. Connect the GND pin of the LM35 to the ground (GND) pin on the Arduino.
3. Connect the Output pin of the LM35 to an analog input pin (e.g., A0) on the Arduino. This setup allows the Arduino to read the voltage output from the LM35, which corresponds to the temperature.

How does the LM35 temperature sensor work?

The LM35 temperature sensor works by producing an output voltage that is linearly proportional to the Celsius temperature. It operates on the principle that the voltage drop across a diode changes with temperature. The LM35 is internally calibrated to output 10 mV per degree Celsius, making it easy to convert the voltage reading into a temperature value via direct scaling. For example, an output of 250 mV corresponds to a temperature of 25°C. This linearity and simplicity make the LM35 an ideal choice for temperature measurement in various electronic projects.

Thank you to being with us until the end of this tutorial and I hope you find what you need about LM35 with Arduino and LCD, if your passion about Arduino and you want to learn more.

ROBOSANS is the best place to learn about Arduino with a brief tutorial and to the point.

If you want to learn more, read these articles down below.

16×2 LCD Interfacing With Arduino

Arduino Analog Ports

DHT11 Humidity And Temperature Sensor

Sources:

arduino.cc

Scroll to Top