Display Temperature on LCD

58,228

55

7

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:

https://www.instructables.com/id/How-to-connect-a-s...

and

https://www.instructables.com/id/How-to-display-tem...

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:

https://www.instructables.com/id/How-to-connect-a-s...

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

https://www.instructables.com/id/How-to-display-tem...

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:

https://www.instructables.com/id/How-to-connect-a-s...

//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 BACKLIGHT_PIN 3

#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.setBacklightPin(BACKLIGHT_PIN,POSITIVE);

lcd.setBacklight(HIGH);

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.

Enjoy

Be the First to Share

    Recommendations

    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Make It Bridge

      Make It Bridge
    • For the Home Contest

      For the Home Contest

    7 Comments

    0
    s01939preethi
    s01939preethi

    Question 1 year ago on Step 1

    Can I use Dht11-digital temperature sensor instead of LM35(the sensor u have used), Will it work?

    0
    Elementk2
    Elementk2

    Question 4 years ago

    would the VSS pin work like the VCC pin. I dont know what kind of LCD I am using but there is only VSS not VCC

    0
    sohakapadia66
    sohakapadia66

    5 years ago

    is there any other way to do the above apart for using arduino?

    0
    theflash9000
    theflash9000

    6 years ago

    i can make this but can u plz elaborate on the coding part

    thank u

    0
    SimoneR2
    SimoneR2

    7 years ago on Introduction

    Hi, to reduce the temperature's reading error you could also change che ADC reference and set it to INTERNAL (1,1V max) if you don't need to measure high temperature (max 110°C) . In the setup you should just add: analogReference(INTERNAL); and then change in loop when you convert volt to temperature: temp = temp*0.107421875; //([(1,1V*1000)/1024]/10).
    //load libraries

    #include <Wire.h>
    #include <LCD.h>
    #include <LiquidCrystal_I2C.h>
    //Define variables for the LCD
    #define I2C_ADDR 0x27 //Define I2C Address where the PCF8574A is
    #define BACKLIGHT_PIN 3
    #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
    //Initialise the LCD
    LiquidCrystal_I2C lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
    void setup()
    {
    //change ADC reference voltage to 1,1V to get more precision
    //max temperature to be read is 110°C
    analogReference(INTERNAL);
    //Define the LCD as 16 column by 2 rows
    lcd.begin (16,2);
    //Switch on the backlight
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    lcd.setBacklight(HIGH);
    //goto first column (column 0) and first line (Line 0)
    lcd.setCursor(0,0);
    //Print at cursor Location
    lcd.print("Temp C = ");
    //goto first column (column 0) and second line (line 1)
    lcd.setCursor(0,1);
    //Print at cursor Location
    lcd.print("Temp F = ");
    }
    void loop()
    {
    temp = analogRead(sensor); //assigning the analog output to temp
    temp = temp * 0.107421875; //converting volts to degrees celsius ----- 0.107421875 = [(1,1V*1000)/1024]/10
    tempf = (temp * 1.8)+32; //Convering from celsius to Fahrenheit
    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
    //wait 5 seconds
    delay(5000);

    }

    bye, I hope it can be useful =)

    p.s. small note on volt's measure unit: volt is derived from a proper noun (Alessandro Volta), so this unit doesn't need s for plural (Ampere, Watt, Ohm, Hertz too!)

    0
    eliesalame
    eliesalame

    Reply 7 years ago on Introduction

    Thanks, I will definitely try it. And I got to learn something new about volt :)