#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2    // Temperature sensor pin
#define BUZZER_PIN 3      // Buzzer pin
#define LED_PIN 4         // LED pin
#define BUTTON_PIN 6      // Push button pin

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup() {
  Serial.begin(9600);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(BUTTON_PIN, INPUT_PULLUP);

  sensors.begin();
}

void loop() {
  float temperature = getTemperature();
  int buttonState = digitalRead(BUTTON_PIN);

  // Temperature monitoring
  if (temperature > 37.5) { 
    activateAlarm();
  } else {
    deactivateAlarm();
  }


  // Button press to manually activate the system
  if (buttonState == LOW) {
    activateAlarm();
  }

  delay(1000);  
}

float getTemperature() {
  sensors.requestTemperatures();
  return sensors.getTempCByIndex(0);
}

void activateAlarm() {
  digitalWrite(BUZZER_PIN, HIGH);
  digitalWrite(LED_PIN, HIGH);
}

void deactivateAlarm() {
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
}
Loading
ds18b20