#include <Wire.h>
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin definitions
#define ONE_WIRE_BUS 2
// Initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass the oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup() {
// Start the LCD
lcd.begin(16, 2);
lcd.print("Temperature:");
// Start the DS18B20 sensor
sensors.begin();
}
void loop() {
// Request temperature from the DS18B20 sensor
sensors.requestTemperatures();
// Get the temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
// Display temperature on LCD
lcd.setCursor(0, 1); // Move cursor to the second line
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print(" C");
// Wait 1 second before taking another reading
delay(1000);
}