LM35 Temperature Sensor Display on LCD – Arduino Tutorial

5,563 views

Introduction

Interfacing an LM35 temperature sensor with a 16×2 Arduino LCD module using an Arduino UNO microcontroller involves connecting the LM35 temperature sensor to an analog input pin on the Arduino UNO and reading the analog voltage output of the LM35 which is proportional to the temperature. This voltage is then converted to a temperature value in centigrade and Fahrenheit. Finally, the temperature value is displayed on the 16×2 LCD module. The communication between the microcontroller and the LCD module is done through an interface such as I2C or a parallel interface. This setup is used to measure and display the ambient temperature in real time.

The LM35 is a linear temperature sensor that provides a voltage output proportional to the temperature in Celsius. It has a sensitivity of 10mV/°C, meaning that for every 1°C increase in temperature, the output voltage will increase by 10mV. The sensor can measure temperatures ranging from -55°C to 150°C, with an accuracy of ±1°C.

Hardware Components

You will require the following hardware for LM35 Temperature Sensor Display on LCD with Arduino.

S.noComponentValueQty
1.Arduino UNO1
2.USB Cable Type A to B1
3.LEDI2C1
4.Temperature SensorLM351
5.Power Adapter for Arduino9V1
6.Breadboard1
7.Jumper Wires1

Temperature LM35 Sensor on LCD with Arduino

  1. Connect the LM35 temperature sensor to the Arduino board:
  • Connect the VCC pin of the LM35 to the 5V pin on the Arduino board.
  • Connect the GND pin of the LM35 to the GND pin on the Arduino board.
  • Connect the Output pin of the LM35 to the A0 pin on the Arduino board.
  1. Connect the 16×2 LCD display to the Arduino board:
  • Connect the VCC pin of the LCD to the 5V pin on the Arduino board.
  • Connect the GND pin of the LCD to the GND pin on the Arduino board.
  • Connect the RS (register select) pin of the LCD to digital pin 12 on the Arduino board.
  • Connect the RW (read/write) pin of the LCD to the GND pin on the Arduino board.
  • Connect the E (enable) pin of the LCD to digital pin 11 on the Arduino board.
  • Connect the D4 pin of the LCD to digital pin 5 on the Arduino board.
  • Connect the D5 pin of the LCD to digital pin 4 on the Arduino board.
  • Connect the D6 pin of the LCD to digital pin 3 on the Arduino board.
  • Connect the D7 pin of the LCD to digital pin 2 on the Arduino board.
  1. Include the LiquidCrystal library in the code.
#include <LiquidCrystal.h>
  1. Define the LCD pins and create an instance of the LiquidCrystal class.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // (RS, E, D4, D5, D6, D7)
  1. Initialize the LCD in the setup() function.
void setup() {
  lcd.begin(16, 2); // initialize the LCD with 16 columns and 2 rows
  Serial.begin(9600);
}
  1. Read the temperature from the LM35 in the loop() function.
void loop() {
  int adcVal = analogRead(A0); // read the ADC value from the LM35
  float milliVolt = adcVal * (5000.0 / 1024.0); // convert the ADC value to voltage in millivolt
  float tempC = milliVolt / 10; // convert the voltage to temperature in Celsius

  // convert the temperature to Fahrenheit
  float tempF = (tempC * 9 / 5) + 32;

  // print the temperature to the Serial Monitor
  Serial.print("Temperature (°C): ");
  Serial.println(tempC);
  Serial.print("Temperature (°F): ");
  Serial.println(tempF);
  1. Display the temperature on the LCD.
  // display the temperature on the first line of the LCD
  lcd.setCursor(0, 0); // set the cursor position to the first line, first column
  lcd.print("Temperature: ");
  lcd.print(tempC);
  lcd.print("°C");

  // display the temperature on the LCD in Fahrenheit
lcd.setCursor(0, 1);
lcd.print("Temp(F): ");
lcd.print(tempF);
lcd.print("°F");

delay(500); // wait for half a second
}

Schematic

Make connections according to the circuit diagram given below.

Wiring / Connections

ArduinoLM35 SENSORLCD
5VVCCVCC
GNDGNDGND
A4SDA
A5SCL

Installing Arduino IDE

First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.

Installing Libraries

Before you start uploading a code, download and unzip the following libraries at /Progam Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “How to Add Libraries in Arduino IDE“.

Code

Now copy the following code and upload it to Arduino IDE Software.

#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(0x3F, 16, 2);  // LCD I2C address 0x27, 16 column and 2 rows

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

  lcd.init();      // initialize the lcd
  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 tempC = milliVolt / 10;
  float tempF = tempC * 9 / 5 + 32; // convert Celsius to Fahrenheit

  lcd.clear();
  lcd.setCursor(0, 0); // start to print at the first row
  lcd.print(tempC);    // print the temperature in Celsius
  lcd.print("°C");
  lcd.setCursor(0, 1); // start to print at the second row
  lcd.print(tempF);    // print the temperature in Fahrenheit
  lcd.print("°F");

  // print the temperature to Serial Monitor
  Serial.print(tempC);
  Serial.print("°C ~ ");
  Serial.print(tempF);
  Serial.println("°F");

  delay(500);
}

Working Explanation

The setup() function initializes the serial communication at 9600 baud rate, and the LCD display. The lcd.init() function initializes the LCD, and the lcd.backlight() function opens the backlight of the LCD display.

The loop() function reads the ADC value from the LM35 temperature sensor, converts the ADC value to voltage in millivolt, converts the voltage to the temperature in Celsius, and converts the temperature in Celsius to Fahrenheit. The temperature in Celsius and Fahrenheit are displayed on the LCD display and printed to the Serial Monitor. The lcd.clear() function is used to clear the display, lcd.setCursor(0, 0) sets the cursor position to the first row, and lcd.print() function is used to print the temperature in Celsius or Fahrenheit. The Serial.print() function is used to print the temperature to the Serial Monitor. The delay(500) function waits for 500 milliseconds before repeating the loop.

Applications

  • Temperature measurement in industrial processes.
  • Monitoring temperature in agriculture, greenhouses, and livestock farms.
  • Temperature control in ovens and kilns.
  • Temperature measurement in automobiles and other vehicles.
  • Environmental monitoring and control.
  • Monitoring temperature in refrigeration systems.
  • Temperature measurement in medical equipment and devices.

Conclusion.

We hope you have found thisTemperature LM35 Sensor Circuit very useful. If you feel any difficulty in making it feel free to ask anything in the comment section.