LM35 Temperature Sensor with Arduino: A Complete Guide & Project

📖 6 min read

The ability to accurately measure temperature is fundamental in countless electronics projects, from simple weather stations to complex industrial control systems. Among the myriad of temperature sensors available, the LM35 temperature sensor with Arduino stands out as a popular, reliable, and incredibly easy-to-use choice for hobbyists and professionals alike. Its precision, linear output, and direct temperature reading in Celsius make it an ideal companion for the versatile Arduino platform. This comprehensive guide will walk you through everything you need to know to successfully integrate the LM35 into your Arduino projects, providing practical examples and essential insights.

LM35 Temperature Sensor with Arduino: A Complete Guide & Project

What is the LM35 Temperature Sensor?

The LM35 is a precision integrated-circuit temperature sensor whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. Unlike thermistors, which require complex linearization circuits or calculations, the LM35 provides a voltage output that directly corresponds to temperature, simplifying its use significantly. It boasts an output scale factor of 10 mV/°C, meaning for every degree Celsius increase in temperature, its output voltage rises by 10 millivolts.

Key features of the LM35 include:

  • Directly Calibrated in Celsius: No need for external calibration or conversion formulas to get Celsius readings.
  • Linear Output: Its output voltage changes linearly with temperature, making it easy to read.
  • Wide Temperature Range: Typically -55°C to +150°C, depending on the specific package (e.g., TO-92, SO-8).
  • Low Self-Heating: The sensor draws very little current, minimizing its own heating effect on the readings.
  • Low Output Impedance: Makes it easy to interface with microcontrollers like Arduino's analog input pins.
  • Operating Voltage: Can operate from 4V to 30V, making it compatible with Arduino's 5V supply.

The most common package for the LM35 is the TO-92, which looks like a small transistor with three pins. These pins are typically labeled (from left to right when viewed from the front, flat side) as:

  • Pin 1 (Vcc): Power supply voltage (+4V to +30V).
  • Pin 2 (Vout): Analog output voltage, proportional to temperature.
  • Pin 3 (GND): Ground.

Understanding these fundamental characteristics is the first step in any successful LM35 sensor Arduino project.

How to Connect LM35 to Arduino: Wiring Diagram

Connecting the LM35 to an Arduino board is straightforward. You'll need an Arduino board (e.g., Uno, Nano, Mega), an LM35 temperature sensor, and three jumper wires. Below is a step-by-step guide and a description of the LM35 Arduino wiring diagram:

  1. Power the LM35: Connect Pin 1 (Vcc) of the LM35 to the 5V pin on your Arduino board.
  2. Ground the LM35: Connect Pin 3 (GND) of the LM35 to any GND pin on your Arduino board.
  3. Connect the Output: Connect Pin 2 (Vout) of the LM35 to an analog input pin on your Arduino, such as A0.

It's crucial to ensure correct polarity for the Vcc and GND pins to prevent damage to the sensor. The analog output pin of the LM35 will provide a voltage signal that the Arduino's Analog-to-Digital Converter (ADC) will read and convert into a digital value.

Summary of Connections:

  • LM35 Pin 1 (Vcc) → Arduino 5V
  • LM35 Pin 2 (Vout) → Arduino A0 (or any other analog input pin)
  • LM35 Pin 3 (GND) → Arduino GND

This simple setup forms the foundation for reading temperature data with high accuracy.

Reading Temperature with LM35 and Arduino: The Code Explained

Once the LM35 is wired correctly, the next step is to write the Arduino code to read its output and convert it into a meaningful temperature value. This section will serve as your primary Arduino LM35 tutorial for programming.

LM35 Temperature Sensor with Arduino: A Complete Guide & Project - 2

The Arduino's ADC reads analog voltages and converts them into a digital value ranging from 0 to 1023. Since the Arduino operates at 5V, each increment in the ADC reading represents 5V / 1024 = approximately 4.88mV. Knowing that the LM35 outputs 10mV per degree Celsius, we can derive a simple conversion formula.

Here's a basic LM35 Arduino code to read and display temperature on the Serial Monitor:


// Define the analog pin where the LM35 is connected
const int LM35_PIN = A0;

void setup() {
  // Initialize serial communication at 9600 bits per second
  Serial.begin(9600);
}

void loop() {
  // Read the analog value from the LM35 sensor
  int analogValue = analogRead(LM35_PIN);

  // Convert the analog value to voltage
  // Arduino's ADC is 10-bit, so 0-1023 maps to 0-5V (or whatever AREF is set to)
  // Voltage = (analogValue / 1024.0)  5000; // Voltage in millivolts
  // For better accuracy, use the actual AREF voltage if known, or measure Vcc
  // Here, we assume 5V reference.
  float voltage = (analogValue  (5.0 / 1024.0)); // Voltage in Volts

  // Convert the voltage to temperature in Celsius
  // LM35 output is 10mV per degree Celsius, so Temp = Voltage (mV) / 10
  // If voltage is in Volts, then Temp = Voltage (V)  100
  float temperatureC = voltage  100.0;

  // Print the temperature to the Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");

  // Wait for a short period before taking the next reading
  delay(1000); // 1-second delay
}

Code Explanation:

  • const int LM35_PIN = A0;: Defines the analog pin the LM35 is connected to.
  • Serial.begin(9600);: Initializes serial communication, allowing you to view the output on your computer's Serial Monitor.
  • int analogValue = analogRead(LM35_PIN);: Reads the analog voltage from the LM35. This returns a value between 0 and 1023.
  • float voltage = (analogValue (5.0 / 1024.0));: Converts the 0-1023 analog reading into a voltage value. Since Arduino's default analog reference is 5V and the ADC resolution is 1024 (0-1023), each unit represents 5.0 / 1024.0 volts.
  • float temperatureC = voltage 100.0;: Converts the voltage into Celsius temperature. As the LM35 outputs 10mV/°C, multiplying the voltage in Volts by 100 (which is equivalent to dividing voltage in mV by 10) gives the temperature in Celsius.
  • Serial.print(...): Prints the calculated temperature to the Serial Monitor.
  • delay(1000);: Pauses the program for one second before taking another reading.

Enhancing Your LM35 Arduino Project: Displaying Temperature on an LCD

While the Serial Monitor is great for debugging, displaying temperature directly on a physical screen makes your project more interactive and standalone. An LCD (Liquid Crystal Display) is a perfect choice for this.

Related Articles

Post a Comment

Previous Post Next Post