#include <OneWire.h> // include the OneWire library for temperature reading
#include <LiquidCrystal_I2C_Hangul.h> // include the LiquidCrystal_I2C_Hangul library for LCD display
// define the pins for the relay and temperature sensor
const int RELAY_PIN = 7;
const int TEMP_SENSOR_PIN = 10;
// initialize the OneWire temperature sensor
OneWire tempSensor(TEMP_SENSOR_PIN);
byte addr[8];
// initialize the I2C LCD display
LiquidCrystal_I2C_Hangul lcd(0x3F, 16, 2);
void setup() {
// initialize the relay pin as an output
pinMode(RELAY_PIN, OUTPUT);
// initialize the LCD display
lcd.init();
lcd.backlight();
// find the address of the temperature sensor
if (!tempSensor.search(addr)) {
Serial.println("Temperature sensor not found.");
while (true); // loop forever
}
}
void loop() {
// reset the temperature sensor
tempSensor.reset();
// send a command to start temperature conversion
tempSensor.write(0x55);
tempSensor.write(addr, 8);
// wait for temperature conversion to finish
delay(750);
// reset the temperature sensor
tempSensor.reset();
// send a command to read the temperature
tempSensor.write(0xBE);
tempSensor.write(addr, 8);
// read the temperature data
byte data[12];
for (int i = 0; i < 12; i++) {
data[i] = tempSensor.read();
}
// convert the temperature data to Celsius
int tempInt = (data[1] << 8) | data[0];
float tempC = (float)tempInt / 16.0;
// display the temperature on the LCD screen
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(tempC, 1);
lcd.write(0xDF); // degree symbol
lcd.print("C");
// turn the relay on or off depending on the temperature
if (tempC >= 62.0) {
digitalWrite(RELAY_PIN, LOW);
} else if (tempC <= 58.0) {
digitalWrite(RELAY_PIN, HIGH);
}
// wait for a moment before taking another temperature reading
delay(5000);
}