#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>
#define ONE_WIRE_BUS 2 // Pin for DS18B20 data
#define TEMPERATURE_THRESHOLD 50 // Set temperature threshold in Celsius
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // RS, EN, D4, D5, D6, D7
int buzzerPin = 4;
int ledPin = 13;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("Temperature:");
lcd.setCursor(0, 1);
lcd.print("Threshold: ");
lcd.print(TEMPERATURE_THRESHOLD);
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
sensors.begin();
}
void loop() {
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
lcd.setCursor(12, 0);
lcd.print(temperature);
if (temperature > TEMPERATURE_THRESHOLD) {
triggerAlarm();
}
delay(1000); // Update temperature every second
}
void triggerAlarm() {
tone(buzzerPin, 1000); // Turn on buzzer
digitalWrite(ledPin, HIGH); // Turn on LED
delay(1000); // Alarm duration
noTone(buzzerPin); // Turn off buzzer
digitalWrite(ledPin, LOW); // Turn off LED
}
/*
Connect the VCC pin of the DS18B20 temperature sensor to the 5V pin on the Arduino.
Connect the GND pin of the DS18B20 temperature sensor to the GND pin on the Arduino.
Connect the data pin (DQ) of the DS18B20 temperature sensor to digital pin 2 on the Arduino.
Place a 4.7kΩ pull-up resistor between the data pin (DQ) and the 5V pin.
Connect the VSS pin (Ground) of the LCD display to the GND pin on the Arduino.
Connect the VDD pin (Power) of the LCD display to the 5V pin on the Arduino.
Connect the RS (Register Select), RW (Read/Write), and EN (Enable) pins of the LCD display
to digital pins 7, GND, and 8 on the Arduino, respectively.
Connect the data pins (D4-D7) of the LCD display to digital pins 9-12 on the Arduino.
Connect the positive terminal of the buzzer to digital pin 4 on the Arduino.
Connect the negative terminal of the buzzer to GND on the Arduino.
Connect the anode (longer leg) of the LED to digital pin 13 on the Arduino
through a 220Ω resistor.
Connect the cathode (shorter leg) of the LED to GND on the Arduino.
*/