Introduction: Display Temperature on LCD

I will bring two projects together in this instructable.

I will demonstrate how to measure the temperature using a LM35 temperature sensor and an Arduino then display the temperature on a serial LCD 16X2 in Celsius and Fahrenheit.

You can find the initial projects here:


Step 1: The Electronics

For this project you will need:

  • 1 Arduino UNO
  • 1 LM35 temperature sensor
  • 1 Serial LCD 16X2
  • 1 Breadboard
  • Some jumper wires.

Step 2: Connect the LCD, LM35 and the Arduino UNO

The LCD I will be using is a serial LCD with a I2C.

Connect the LCD

VCC connects on the +ve red rail on the breadboard

GND connects to the -ve blue rail on the breadboard

The SDA connects to the SDA on the Arduino

The SCL connects to the SCL on the Arduino

For more detail on how to connect it visit my earlier instructable:

Connect the LM35

The VCC connects on the +ve red rail on the breadboard

The GND connects to the -ve blue rail on the breadboard

The Middle pin connects on the PIN A0 (analog 0) on the Arduino

* remember to connect the VCC and GND correctly otherwise the LM35 will heat up to 300 degrees and more.

I have detailed instructions on LM35 and how to connect it on

Now we are ready for the sketch ............

Step 3: The Sketch

The sketch is not as simple as copy and paste both sketches together, I had to modify it to accommodate both devices and to tell the Arduino to get the data from the sensor and display it on the LCD. But the Variables and libraries remain the same.

There is a zipped copy of the sketch in this instructable you can adjust it as you see fit.

I started by defining the libraries we need for the LCD. For more details on how to load the libraries in your Arduino library folder follow the instructions in this instructable:

//load libraries
#include <Wire.h>

#include <LCD.h>

#include <LiquidCrystal_I2C.h>

The I defined the variables needed by the LCD and the LM35

I added the variable tempf to help display the temperature in Fahrenheit

//Define variables for the LCD

#define I2C_ADDR 0x27 //Define I2C Address where the PCF8574A is


#define En_pin 2

#define Rw_pin 1

#define Rs_pin 0

#define D4_pin 4

#define D5_pin 5

#define D6_pin 6

#define D7_pin 7

//define variables for the LM35 temperature sensor

float temp; //Define the temp float variable

float tempf; //Define the Fahrenheit float variable

int sensor = 0; // sensor middle pin on analog pin 0

Then I initialized the LCD using this line:

//Initialize the LCD
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

In the Void setup, I tell the Arduinio that I am using a 16X2 LCD, turn on the backlights and print some lines that will not change.

void setup() {

lcd.begin (16,2); //Define the LCD as 16 column by 2 rows

//Switch on the backlight



lcd.setCursor(0,0); //goto first column (column 0) and first line (Line 0)

lcd.print("Temp C = "); //Print at cursor Location

lcd.setCursor(0,1); //goto first column (column 0) and second line (line 1)

lcd.print("Temp F = "); //Print at cursor location


In the Void loop I will read the temperature from the sensor, change it to Celsius and display it on the first row, then change it again to Fahrenheit and display it on the second row. The repeat the process every 5 seconds

void loop(){

temp = analogRead(sensor); //assigning the analog output to temp

temp = temp * 0.48828125; //converting volts to degrees celsius ----- 0.48828125 = [(5V*1000)/1024]10 tempf = (temp * 1.8)+32; //Convering from celsius to fahreneit

lcd.setCursor(8,0); //move the cursor to position 8 on row 1

lcd.print(temp); //print the temperature in Celsius

lcd.setCursor(8,1); //move the cursor to position 8 on row 2

lcd.print(tempf); //print the temperature in Fahrenheit

delay(5000); //wait 5 seconds


I hope you like it, if you have any questions don't hesitate to ask.