ESP8266 Temperature Sensor Module LM35 / LM75

Measures temperature using ESP8266 with LM35 analog sensor or LM75 I2C sensor, suitable for room‑temperature monitoring, industrial control, and IoT temperature‑measurement systems.

ESP8266 Temperature Sensor Module LM35 / LM75

The ESP8266 Temperature Sensor project demonstrates how to measure temperature using either an LM35 analog sensor or an LM75 I2C‑based temperature module with an ESP8266‑based board such as NodeMCU or Wemos‑D1. The ESP8266 reads the temperature value and can display it locally, send it over Wi‑Fi, or log it to a cloud service, making it ideal for room‑temperature monitoring, industrial control, and IoT temperature‑measurement systems.

Overview of LM35 and LM75

The LM35 is a precision analog temperature sensor that outputs 10 mV per degree Celsius, providing a simple way to read temperature with an analog‑to‑digital converter (ADC). The ESP8266 reads the LM35’s output on its A0 pin and converts the voltage into degrees Celsius using calibration formulas.

The LM75 (or compatible I2C temperature sensor) is a digital sensor that communicates over I2C, providing temperature readings as integer or floating‑point data. The ESP8266 reads the temperature from the LM75 using the Wire library and can retrieve values with higher resolution and less noise compared to analog sensors.

Components Needed

  • ESP8266 development board (e.g. NodeMCU‑v2 or Wemos‑D1)
  • LM35 temperature sensor (optional, for analog measurement)
  • LM75‑style I2C temperature sensor module (optional, for digital measurement)
  • LED or small OLED (optional, for local display)
  • Jumper Wires
  • Breadboard

Circuit Diagram

Circuit Setup

1. LM35 (Analog Sensor) Connections

Typical LM35 wiring to ESP8266 (NodeMCU‑style):

  • VCC → 3.3 V or 5 V on ESP8266 (LM35 accepts 4–30 V; many LM35‑style modules on 3.3 V boards are safe).
  • GND → GND on ESP8266.
  • OUT (analog output) → A0 on ESP8266.

The LM35 output is 10 mV/°C; with a 3.3 V reference and 10‑bit ADC, the ESP8266 maps the raw 0–1023 value to voltage in millivolts, then divides by 10 to get degrees Celsius.

2. LM75 (I2C Sensor) Connections

LM75‑style I2C module wiring to ESP8266:

  • VCC → 3.3 V on ESP8266.
  • GND → GND on ESP8266.
  • SCL → GPIO 5 (D1 on NodeMCU).
  • SDA → GPIO 4 (D2 on NodeMCU).

Ensure a stable 3.3 V power and clean I2C wiring; avoid long wires to reduce noise. Some LM75 modules include pull‑up resistors on the I2C lines; if not, you may need to add 4.7 kΩ pull‑ups to VCC.

Instructions

1. Software Setup

Configure the Arduino IDE for ESP8266 (e.g. board: NodeMCU‑v2). Initialize serial communication (9600 or 115200 baud) for debugging. For LM35, define the analog pin (A0) and use the ADC to read voltage; for LM75, include the `Wire` library and set up I2C communication with the sensor’s address.

2. LM35 Temperature Reading

Read the analog value from A0, convert it to millivolts, then divide by 10 to get temperature in °C (since 10 mV corresponds to 1 °C). The ESP8266 can then print the temperature on the Serial Monitor or send it over Wi‑Fi.

3. LM75 Temperature Reading

Initialize the I2C bus with `Wire.begin()`, then send a read command to the LM75’s address and read the temperature register. The raw data can be converted to Celsius using the sensor’s datasheet formula (typically 0.125 °C or 0.5 °C per LSB), and the result can be displayed or transmitted.

4. Wi‑Fi and Data Transmission

Use Wi‑Fi (`WiFi.begin`) and either HTTP or MQTT to send the temperature readings to a cloud service (ThingSpeak, Blynk, or a custom server) for remote monitoring. Each time the ESP8266 reads a new temperature, it can post that value to a channel or topic.

C++ Example Code (ESP8266 LM35 Temperature Sensor)

ESP8266 LM35 Temperature Sensor (Analog Reading)
#include <ESP8266WiFi.h>

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

// LM35 pin (analog input A0)
const int lm35Pin = A0;

// Reference voltage (3.3 V for ESP8266)
const float refVoltage = 3.3;

// Variables for temperature
float voltage;
float temperatureC;

void setup() {
  Serial.begin(9600);
  
  // Optional: connect to Wi‑Fi
  // WiFi.begin(ssid, password);
  // while (WiFi.status() != WL_CONNECTED) delay(1000);
  
  Serial.println("=== ESP8266 LM35 TEMPERATURE SENSOR READY ===");
}

void loop() {
  // Read analog value (0–1023)
  int rawValue = analogRead(lm35Pin);
  
  // Convert to voltage in mV
  voltage = (rawValue / 1024.0) * (refVoltage * 1000);
  
  // LM35: 10 mV = 1 °C
  temperatureC = voltage / 10.0;
  
  // Optional: convert to Fahrenheit
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32;
  
  // Print to Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.print(" °C, ");
  Serial.print(temperatureF);
  Serial.println(" °F");
  
  // Optional: send to cloud service here (HTTP or MQTT)
  
  delay(2000);
}

C++ Example Code (ESP8266 LM75 I2C Temperature Sensor)

ESP8266 LM75 I2C Temperature Sensor (Digital Reading)
#include <ESP8266WiFi.h>
#include <Wire.h>

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

// LM75 I2C address (typical 0x48)
#define LM75_ADDR 0x48

// Variables for temperature
float temperatureC;

void setup() {
  Serial.begin(9600);
  
  // Optional: connect to Wi‑Fi
  // WiFi.begin(ssid, password);
  // while (WiFi.status() != WL_CONNECTED) delay(1000);
  
  Wire.begin(4, 5); // D2, D1 on NodeMCU (SDA, SCL)
  
  Serial.println("=== ESP8266 LM75 I2C TEMPERATURE SENSOR READY ===");
}

void loop() {
  Wire.beginTransmission(LM75_ADDR);
  Wire.write(0x00); // Temperature register
  Wire.endTransmission();
  
  Wire.requestFrom(LM75_ADDR, 2);
  if (Wire.available() >= 2) {
    // Read two bytes for temperature
    int16_t tempRaw = (Wire.read() << 8) | Wire.read();
    
    // LM75 uses 0.5 °C per LSB
    temperatureC = (tempRaw >> 7) * 0.5;
  }
  
  // Print to Serial Monitor
  Serial.print("Temperature: ");
  Serial.print(temperatureC);
  Serial.println(" °C");
  
  // Optional: send to cloud service here (HTTP or MQTT)
  
  delay(2000);
}

Applications

Room‑Temperature Monitoring: Use the LM35 or LM75 with ESP8266 to monitor room temperature in homes, offices, or server rooms, and send data to a web dashboard.

Industrial Control: Integrate the sensor into industrial equipment or process control systems to monitor and regulate temperature, preventing overheating or cooling issues.

IoT Temperature Measurement: Connect the ESP8266 to Wi‑Fi and send temperature readings to cloud services like ThingSpeak or Blynk, enabling real‑time monitoring and historical analysis.

Notes

Analog vs Digital Sensors

LM35 provides an analog output requiring ADC conversion, while LM75 uses I2C for digital communication. Digital sensors typically offer better accuracy and less noise, while analog sensors are simpler to interface.

Serial and Debugging

Use the Serial Monitor to verify that temperature values change with the environment. For LM35, confirm the voltage conversion is correct; for LM75, check the I2C communication and address configuration.

Remote Monitoring Extension

Extend the project by sending temperature data to a cloud dashboard or home‑automation system, or use the ESP8266 to trigger alerts or control devices based on temperature thresholds.