ESP8266 - LM35 Temperature Sensor LCD
This tutorial instructs you how to use ESP8266 to acquire the temperature from an LM35 sensor and display it on a 16x2 LCD I2C.

Hardware Preparation
Or you can buy the following kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .
Additionally, some of these links are for products from our own brand, DIYables .
Overview of LM35 Temperature Sensor and LCD I2C
If you are not familiar with the LM35 Temperature Sensor and LCD I2C (including pinout, functionality, programming, etc.), you can find out more in the following tutorials:
- ESP8266 - LCD I2C tutorial
- ESP8266 - LM35 Temperature Sensor tutorial
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
ESP8266 Code - LM35 Temperature Sensor - LCD I2C
/*
* This ESP8266 NodeMCU code was developed by newbiely.com
*
* This ESP8266 NodeMCU code is made available for public use without any restriction
*
* For comprehensive instructions and wiring diagrams, please visit:
* https://newbiely.com/tutorials/esp8266/esp8266-lm35-temperature-sensor-lcd
*/
#include <LiquidCrystal_I2C.h> // LCD I2C library
#define ADC_VREF_mV 5000.0 // in millivolt
#define ADC_RESOLUTION 1024.0
#define PIN_LM35 A0 // pin connected to LM35 temperature sensor
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD I2C address 0x27 (from DIYables LCD), 16 column and 2 rows
void setup() {
Serial.begin(9600);
lcd.init(); // Initialize the LCD I2C display
lcd.backlight(); // open the backlight
}
void loop() {
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in Celsius
float temperature_C = milliVolt / 10;
float temperature_F = temperature_C * 9 / 5 + 32; // convert Celsius to Fahrenheit
lcd.clear();
lcd.setCursor(0, 0); // start to print at the first row
lcd.print(temperature_C); // print the temperature in Celsius
lcd.print("°C");
lcd.setCursor(0, 1); // start to print at the second row
lcd.print(temperature_F); // print the temperature in Fahrenheit
lcd.print("°F");
// print the temperature to Serial Monitor
Serial.print(temperature_C);
Serial.print("°C ~ ");
Serial.print(temperature_F);
Serial.println("°F");
delay(500);
}
Detailed Instructions
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- Click to the Libraries icon on the left bar of the Arduino ID
- Search for “LiquidCrystal I2C” and locate the LiquidCrystal_I2C library by Frank de Brabander.
- Click the Install button to install the LiquidCrystal_I2C library.

- Copy the code and open it in the Arduino IDE.
- Click the Upload button to send it to the ESP8266.
- Place the sensor in hot and cold water or hold it in your hand.
- Check the LCD and Serial Monitor for the outcome.
※ NOTE THAT:
The address of the LCD may differ depending on the manufacturer. In our code, we used 0x27, which is the address specified by DIYables.