#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Pin Configurations
const int ds18b20Pin = 7; // Temperature sensor on digital pin 2
const int potPin = A0; // Potentiometer on analog pin A0
// Setup a oneWire instance
OneWire oneWire(ds18b20Pin);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
// Setup the LCD, address 0x27 (common for I2C LCDs), 16 columns and 2 rows
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// Start communication with sensors and LCD
sensors.begin();
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the LCD backlight
}
void loop() {
// Request temperature from sensor
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0); // Get temperature in Celsius
// Read the potentiometer voltage
int potValue = analogRead(potPin);
float voltage = (potValue / 1023.0) * 5.0; // Convert analog value to voltage (assuming 5V Arduino)
// Display on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Volt: ");
lcd.print(voltage);
lcd.print(" V");
delay(1000); // Wait 1 second before updating
}