#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// I2C LCD address and dimensions
LiquidCrystal_I2C lcd(0x27, 16, 2); // Address 0x27 or 0x3F
// DS18B20 Temperature Sensor pin
#define ONE_WIRE_BUS 15 // GPIO 34
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup() {
// Start Serial Monitor for debugging
Serial.begin(115200);
// Initialize the LCD and backlight
lcd.init();
lcd.backlight();
// Start up the temperature sensor library
sensors.begin();
// Display initialization message
lcd.setCursor(0, 0);
lcd.print("Temperature Init");
delay(2000); // Wait for 2 seconds
lcd.clear(); // Clear the LCD for the next display
}
void loop() {
// Request temperature from the sensor
sensors.requestTemperatures();
// Get the temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
// Display the temperature on the LCD
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print(" C");
// Optional: Debugging output to Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" C");
// Wait for 1 second before the next reading
delay(1000);
}