// Task 5: Communication using I2C LCD + Temperature Sensor
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// LCD setup: address 0x27, 16 columns x 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Thermistor parameters
const int tempPin = A0;
const float BETA = 3950; // Should match the thermistor's Beta coefficient
void setup() {
lcd.init(); // Initialize LCD
lcd.backlight(); // Turn on backlight
lcd.setCursor(0, 0);
lcd.print("Hello I2C LCD");
Serial.begin(9600); // For debugging
}
void loop() {
int analogValue = analogRead(tempPin);
// Convert ADC reading to temperature (Celsius)
float celsius = 1 / (log(1 / (1023.0 / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
// Display on LCD
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print(celsius, 1);
lcd.print((char)223); // Degree symbol
lcd.print("C "); // Clear old digits with spaces
// Print to Serial Monitor
Serial.print("Analog: ");
Serial.print(analogValue);
Serial.print(" | Temp: ");
Serial.print(celsius);
Serial.println(" °C");
delay(1000);
}