#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16x2 display
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int tempPin = A0;
void setup() {
// Initialize the LCD
lcd.begin(16, 2);
lcd.backlight();
// Initialize the serial communication
Serial.begin(9600);
}
void loop() {
// Read the analog value from the sensor
int sensorValue = analogRead(tempPin);
// Convert the analog reading to a voltage (LM35 gives 10mV per degree Celsius)
float voltage = sensorValue * (5.0 / 1023.0);
// Convert the voltage to temperature (°C)
float temperature = voltage * 100;
// Print temperature on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
// Print temperature to Serial Monitor for reference
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
delay(1000);
}