Home / Projects / Arduino Projects / How to Use LM35 Temperature Sensor with Arduino and ESP32: Complete Guide with Example Projects
pcbway
How to use LM32 with Arduino or ESP32

How to Use LM35 Temperature Sensor with Arduino and ESP32: Complete Guide with Example Projects

Introduction to LM35 Temperature Sensor

The LM35 is a precision temperature sensor that provides an analog voltage output proportional to the measured temperature. It's popular among electronics enthusiasts for its simplicity, accuracy, and ease of use with microcontrollers like Arduino and ESP32.

In this tutorial, you’ll learn how LM35 works, how to interface it with Arduino and ESP32, and how to build two practical projects — a basic temperature reader and an IoT-based web server display.


What Is an LM35 Sensor?

lm35

The LM35 is an analog temperature sensor that outputs voltage linearly related to the Celsius temperature. It doesn’t require calibration and provides a direct temperature-to-voltage conversion, making it extremely beginner-friendly.

Manufacturer: Texas Instruments
Output Type: Analog (10mV/°C)
Operating Range: -55°C to +150°C
Accuracy: ±0.5°C (at room temperature)


Key Features and Specifications of LM35

Feature Description
Operating Voltage 4V to 30V
Output Voltage 10 mV per °C
Temperature Range -55°C to +150°C
Accuracy ±0.5°C (at 25°C)
Output Type Analog
Power Consumption Low

How the LM35 Sensor Works: Principle of Operation

The LM35 works on the principle that the output voltage changes linearly with temperature.
For every 1°C rise, the output increases by 10 mV.

So if the LM35 outputs 250 mV, the temperature is 25°C.
Formula:

T(^{0}C) = \frac{V_{out} (in\; mV)}{10}

This linear relationship makes the LM35 simple to use — no complex calibration or signal conditioning is required.

That means:

  • 0°C → 0V
  • 25°C → 250mV
  • 100°C → 1.0V

Since the ESP32 ADC reads voltage in a range (0–3.3V), we can compute the temperature as:

T(^{0}C)=(\frac{ADC_{value}}{4095})\cdot3.3\cdot100


Understanding the LM35 Pin Configuration and Circuit Diagram

LM35 pinout

LM35 Pinout Explained

Pin Function Description
1 VCC Connects to 5V (Arduino) or 3.3V (ESP32)
2 VOUT Analog output voltage
3 GND Ground connection

LM35 Wiring and Power Requirements

  • For Arduino, power it with 5V.
  • For ESP32, use 3.3V.
  • Always use a common ground between LM35 and the microcontroller.
  • Optionally, add a 0.1 µF capacitor between VOUT and GND to stabilize readings.

Using LM35 with Arduino: Step-by-Step Guide

Components Required for Arduino + LM35 Project

  • Arduino Uno (or Nano)
  • LM35 temperature sensor
  • Jumper wires
  • Breadboard
  • (Optional) 16x2 LCD display

Circuit Diagram for LM35 with Arduino

Arduino and LM35 wiring diagram

Connections:

  • LM35 VCC → 5V
  • LM35 GND → GND
  • LM35 VOUT → A0 (analog pin)

Arduino Code to Read Temperature from LM35

const int sensorPin = A0;
float temperature;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(sensorPin);
  float voltage = (sensorValue / 1023.0) * 5.0;
  temperature = voltage * 100; // 10mV per degree Celsius
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");
  delay(1000);
}

Displaying Temperature on Serial Monitor or LCD

  • Open Serial Monitor (Ctrl + Shift + M).
  • You’ll see continuous readings like:
    Temperature: 27.35 °C
    Temperature: 27.42 °C
  • To display it on an LCD, use the LiquidCrystal library and connect pins RS, E, D4–D7 accordingly.

Using LM35 with ESP32: IoT-Based Temperature Monitoring

Components Required for ESP32 + LM35 Project

  • ESP32 board
  • LM35 temperature sensor
  • Breadboard and jumper wires
  • (Optional) Wi-Fi network for IoT display

Circuit Diagram for LM35 with ESP32

Connections:

  • LM35 VCC → 3.3V
  • LM35 GND → GND
  • LM35 VOUT → GPIO34 (analog input)

ESP32 Code to Read Temperature from LM35

const int sensorPin = 34;
float temperature;

void setup() {
  Serial.begin(115200);
}

void loop() {
  int sensorValue = analogRead(sensorPin);
  float voltage = (sensorValue / 4095.0) * 3.3;
  temperature = voltage * 100;
  Serial.print("Temperature: ");
  Serial.print(temperature);
  Serial.println(" °C");
  delay(2000);
}

Displaying Temperature on a Web Server (IoT Project)

Below is a full example code that:

  1. Reads temperature from LM35.
  2. Connects to Wi-Fi.
  3. Hosts a simple webpage showing live temperature readings.
#include <WiFi.h>
#include <WebServer.h>

// Replace with your Wi-Fi credentials
const char* ssid = "YOUR_WIFI_SSID";
const char* password = "YOUR_WIFI_PASSWORD";

const int lm35_pin = 34; // Analog pin for LM35
WebServer server(80);    // Web server on port 80

float read_temperature() {
  int adc_value = analogRead(lm35_pin);
  float voltage = (adc_value / 4095.0) * 3.3;  // Convert ADC reading to voltage
  float temperature_c = voltage * 100;         // 10mV per °C
  return temperature_c;
}


String html_page(float temp_c) {
  String html = "<!DOCTYPE html><html><head><meta name='viewport' content='width=device-width, initial-scale=1.0'>";
  html += "<title>ESP32 LM35 Temperature</title>";
  html += "<style>body{font-family:Arial;text-align:center;background:#111;color:#0ff;}h1{color:#00ffff;}</style>";
  html += "</head><body>";
  html += "<h1>ESP32 LM35 Temperature Monitor</h1>";
  html += "<h2>Current Temperature: " + String(temp_c, 2) + " °C</h2>";
  html += "<meta http-equiv='refresh' content='2'>"; // auto-refresh every 2 seconds
  html += "</body></html>";
  return html;
}


void handle_root() {
  float temp = read_temperature();
  server.send(200, "text/html", html_page(temp));
}

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  Serial.print("Connecting to Wi-Fi");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("\nConnected!");
  Serial.print("ESP32 IP address: ");
  Serial.println(WiFi.localIP());

  server.on("/", handle_root);
  server.begin();
  Serial.println("Web server started!");
}

void loop() {
  server.handleClient();
}

Accessing the Web Page

  1. Upload the sketch to your ESP32.
  2. Open the Serial Monitor at 115200 baud.
  3. Wait until you see:
    Connected!
    ESP32 IP address: 192.168.1.xxx
  4. Open that IP in your browser (e.g., http://192.168.1.45)
  5. You’ll see a temperature dashboard refreshing every 2 seconds!

Troubleshooting Common Issues

Incorrect Temperature Readings

  • Check voltage reference (5V or 3.3V).
  • Ensure correct analog pin.
  • Add a capacitor between VOUT and GND to reduce noise.

Sensor Noise and Calibration Tips

  • Use shielded cables for long distances.
  • Calibrate by comparing with a digital thermometer.

Applications of LM35 in Real-Life Projects

Home Automation Systems

  • Temperature-controlled fans or air conditioners.

Environmental Monitoring and IoT Systems

  • Smart agriculture
  • Weather monitoring stations
  • IoT dashboards (via Blynk, ThingSpeak, etc.)

Advantages and Limitations of LM35 Sensor

Benefits of Using LM35

  • Linear and accurate output
  • Low cost and easy to interface
  • No external calibration needed

Limitations and Alternatives

  • Analog-only output (needs ADC)
  • Not waterproof
  • Alternatives: DHT11, DS18B20, TMP36

FAQs: How to Use LM35 Temperature Sensor with Arduino and ESP32

1. What voltage does LM35 require?
It operates between 4V and 30V, commonly powered by 5V (Arduino) or 3.3V (ESP32).

2. Can I use LM35 with ESP8266 or Raspberry Pi?
Yes, but ensure you use analog-to-digital conversion, as some boards (like ESP8266) have limited ADC support.

3. Why are my readings unstable?
Add a capacitor (0.1 µF) across output and ground to filter noise.

4. How accurate is the LM35 sensor?
±0.5°C at room temperature and ±1°C across a wide range.

5. Can LM35 measure below 0°C?
Yes, but output voltage may go negative, requiring offset circuitry.

6. Which IoT platforms support LM35 + ESP32 projects?
Popular ones include Blynk, ThingSpeak, and Google Firebase.


Conclusion

The LM35 temperature sensor is a simple, reliable, and precise device for temperature measurement and monitoring. Whether you’re using Arduino for basic sensor readings or ESP32 for IoT web dashboards, the LM35 offers versatility and accuracy.

Experimenting with LM35 is an excellent way to start learning about analog sensors, ADC conversion, and IoT data visualization.

For more information, visit the Texas Instruments LM35 Datasheet.

Check Also

ESP32 Earthquake Monitor

ESP32 Earthquake Monitor with USGS API, GPS, LCD, and Web Dashboard

Updated: October 18, 2025Was that an earthquake, or did I just stand up too fast? …

Index