#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int sensorPin = A0;
float voltage, temperatureC;
// Initialize LCD at I2C address 0x27, 16 columns, 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init(); // Initialize LCD
lcd.backlight(); // Turn on backlight
lcd.setCursor(0, 0);
lcd.print("Hello I2C LCD");
Serial.begin(9600);
delay(2000); // Wait before showing temperature
lcd.clear();
}
void loop() {
int adcValue = analogRead(sensorPin);
voltage = adcValue * (5.0 / 1023.0); // Assuming 5V reference
temperatureC = voltage * 100; // LM35: 10mV per °C
// Print to Serial Monitor
Serial.print("ADC: ");
Serial.print(adcValue);
Serial.print(" | Temp: ");
Serial.print(temperatureC, 1);
Serial.println(" C");
// Display on LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperatureC, 1);
lcd.print((char)223); // Degree symbol
lcd.print("C "); // Padding to clear old chars
delay(1000);
}