-
Library and Pin Setup:
#include <LiquidCrystal.h>
: Includes the LCD library.- Pin Definitions: Sets up connections for the LCD and temperature sensor.
-
LCD Initialization:
lcd.begin(16, 2);
: Initializes a 16x2 LCD display.
-
Temperature Reading and Display:
int adcvalue = analogRead(lm35pin);
: Reads the temperature sensor value.float tempvol = adcvalue * 4.88;
: Converts the sensor reading to voltage.float temp = tempvol / 10;
: Converts voltage to temperature in Celsius.lcd.setCursor(0, 0);
: Moves the cursor to the first row of the LCD.lcd.print("Temp: ");
: Displays the "Temp: " label.lcd.print(temp);
: Shows the temperature value.lcd.print(" C");
: Adds the Celsius unit.delay(5000);
: Updates the display every 5 seconds.
Write a program to interface LM 35 temperature sensor and display the readings on LCD .
Last Updated : 30 Jul 2025
Jul 2024
Solution:
#include <LiquidCrystal.h> // LCD library
// LCD pin connections
const int rs = 11;
const int en = 10;
const int d4 = 9;
const int d5 = 8;
const int d6 = 7;
const int d7 = 6;
// Initialize LCD
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// LM35 sensor pin
const int lm35pin = A5;
void setup() {
lcd.begin(16, 2); // Set up LCD
}
void loop() {
int adcvalue = analogRead(lm35pin); // Read sensor value
float tempvol = adcvalue * 4.88; // Convert to voltage
float temp = tempvol / 10; // Convert to Celsius
lcd.setCursor(0, 0); // Set cursor
lcd.print("Temp: "); // Display text
lcd.print(temp); // Display temperature
lcd.print(" C"); // Display unit
delay(5000); // Wait 5 seconds
}
Output Description:
The LCD displays the current temperature in Celsius. The output format is:
Temp: XX.X C
"Temp: ": Label for the temperature reading.
"XX.X": Temperature value in Celsius.
" C": Indicates Celsius.
The display updates every 5 seconds.
Code Explanation:
Meanwhile you can watch this video
Watch Video