#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
// Data wire is connected to Arduino digital pin 2
#define ONE_WIRE_BUS 7
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
// Initialize the LCD with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
Serial.begin(9600);
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
sensors.begin(); // Start communication with the DS18B20 sensor
}
void loop() {
sensors.requestTemperatures(); // Request temperature readings from the sensor
float temperatureC = sensors.getTempCByIndex(0.1); // Read temperature in Celsius
// float temperatureC = (temperatureF - 32.0) * 5.0 / 9.0; // Convert Fahrenheit to Celsius
lcd.clear(); // Clear the LCD display
lcd.setCursor(0, 0); // Set cursor to the first column and first row
lcd.print("Temp: ");
lcd.print(temperatureC);
lcd.print(" C");
delay(1000); // Update every second
}