#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // Data wire for DS18B20 is plugged into pin 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address to 0x27 for a 16 chars and 2 line display
const int buzzerPin = 7;
const int led1Pin = 8;
const int led2Pin = 9;
const int relayPin = 10; // Relay control pin
const float temperatureThreshold = 30.0; // Temperature threshold in Celsius
void setup() {
sensors.begin();
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
pinMode(buzzerPin, OUTPUT);
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(relayPin, OUTPUT); // Set relay pin as output
}
void loop() {
sensors.requestTemperatures();
float tempC = sensors.getTempCByIndex(0);
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(tempC);
lcd.print(" C");
if (tempC > temperatureThreshold) {
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer
blinkLEDs(); // Blink LEDs
digitalWrite(relayPin, HIGH); // Turn on the relay
} else {
digitalWrite(buzzerPin, LOW); // Turn off the buzzer
digitalWrite(led1Pin, LOW); // Turn off LED1
digitalWrite(led2Pin, LOW); // Turn off LED2
digitalWrite(relayPin, LOW); // Turn off the relay
}
delay(1000); // Update temperature reading every second
}
void blinkLEDs() {
for (int i = 0; i < 5; i++) { // Blink the LEDs 5 times
digitalWrite(led1Pin, HIGH);
digitalWrite(led2Pin, HIGH);
delay(500);
digitalWrite(led1Pin, LOW);
digitalWrite(led2Pin, LOW);
delay(500);
}
}